generator: fix a few bugs in generated C files