convert code to C

the code was written in very unidiomatic C++ - basically 99% C with usage of less than a handfull C++ features. turning it entirely into C gives better portability (for example embedded or new systems without C++ compilers), and much better compilation speed.