The issue is due to a difference between MATLAB and C syntax in you C-Script. In Matlab "1/2" in an S-Function will return 0.5, but C will return 0 since it treats 1 and 2 as integers and not floating point values. Integer division will return an integer. So your C-Script logic check was faulty and the output would always be zero. Good practice is to add "." after any number if you want it to be a float (e.g. p=1./2.;) or simply enter in the value as a float (p=0.5;).

See the following example:

https://onlinegdb.com/dupqaU-l_
Attached is a revised version of your model with the C-Script problem fixed.