MAINT trim away >10 kLOC of generated C code

Trimmed away some dead code and used lower-level APIs were it didn't hurt readability. This is intended to get smaller code, not extra speed, and the generated C code is <del>hundreds of</del> more than 10.000 lines shorter.
This change moves the `x != 0` checks to Python