add while and if statement in generate.c