flatten: fix handling nested loops

* graph: make root an Option<BlockId>