Refactor gcc.c, pulling out the reusable code