Factor FlattenCFG out from SimplifyCFG

Patch by: Mei Ye