It looks like a C function (with a lot of code-like commentary). Are you sure you want to convert it to perl - instead of just compiling it using a C compiler?
I'm asking because this is the kind of question that makes me very cautious about making assumptions.