I can't tell if it's correct or not without seeing all the relevant code that it is being converted from. You're not sure and you're asking us to guess based on portions of your pseudocode (which hopefully is even accurate). That're far too many places where a bug could creep in.
The best option would be to work out the purpose of the piece of code and write it in C from scratch.