TBR: applying transformation to irgen.cpp
Apply the same refactoring to irgen.cpp.