Remove unnecessary forward declarations

Shuffle functions so that all are defined before use, which obsoletes
the forward declarations.
Replace int functions returning 1 or 0 with C99 bool
Declare loop variables in loop header, this is C99
Convert oldschool single-line comments to C99 style