A clean Mex function uses the mexFunction() function to obtain the pointers to the values of the inputs at first. Then a subsection, or better sub-functions process the data. Finally the mexFunction() creates the outputs for Matlab.
Then it is relatively easy to remove the mexFunction() and use the sub-function for calculations from otehr C-code directly.
But maybe the mexFunction() creates the outputs at first and delivers pointers to allocated arrays to the subfunction. Or the mexFunction() mixes its job as a Matlab-C-gateway with calculations. Then a separation of the Mex and C parts is difficult.