There are mainly two ways to do this:
- Use an explicit stack to store local variables and return addresses.
- Do a CPS against your function and then do a trampolining transformation.
In both ways, constructing a control flow graph from your function would be very useful to aid thinking...