also, it's a series of if/else if/else if/else if
that would have been better structured as a switch, for a start, for the clarity of the top level
there is three cases if i remember correctly, where two go to two options and one goes to three
some comments explaining the reason why this order of actions would have helped a lot
i will explain it, just as i have also explained the binary formatting of your code in other work
and i won't thank you because decoding bad code is harder than writing it.