Hello,
If I'm interpreting your question correctly, you're basically saying that the line:
MASK_INDEX = *mxGetPr(ssGetSFcnParam(S, 0));
is repeated, and you want to avoid doing so.
Note that, as you suspect, the variable assigned (MASK_INDEX) is a global, and the assignment modifies it. As such, it's assignment is a side-effect of executing the functions containing it, so using a *local* variable will mean that the global state won't change, and will be incorrect.
So, unfortunately, the duplication is necessary. However, there are things you could do to reduce the typing. E.g. you could create a small function which does nothing but execute the statement, then call that function:
void LastPart(SimStruct *S) {
MASK_INDEX = *mxGetPr(ssGetSFcnParam(S, 0));
}
...
LastPart(s); // replace MASK_INDEX = *mxGetPr(ssGetSFcnParam(S, 0));