Refactor it, preferably yesterday - but make a "shadow deploy". For each set of input / output parameters run both functions and compare them. If they differ, use the old one and go back to figuring out where it went wrong. After some time you can be quite sure that the new clean function works as it should - then you just switch.
http://www.amazon.co.uk/Working-Effectively-Legacy-Michael-F...
More seriously though, the kind of code you described will be what I imagine the first subject of study of the software archeology field in the future.
I've been working at the system to free it from that subsystem with an eventual replacement. There are all kinds of single-letter variables and Russian words, refactoring wouldn't be economical or sane.