I haven’t tried compiling the code as there are too many bits missing but my suspicion is that the comments ending in \ are the problem. A line in C ending with a \ indicates that the next line is to be taken as a continuation of this line which means the if statements following them are being swallowed up into the comment.
The error appeared where it did due to the mismatched }s eventually causing the compiler to think the function was finished. The opening {s were being swallowed up as they were inline with the if statements.