Comment on v5 since Gitlab is being uncoöperative: the foreach_loop() function is currently applying logic twice to "if" inside "for", but moreover, I would leave off adding a generic wrapper for this until we have more passes that need it. I.e. I'd just write a single function that calls itself.
More generally, I'm not thrilled about the way this gives the same IR two different semantics depending on whether this iterator pass has been done yet. I suppose that an improvement would be to use two different jump-type enums, but I don't immediately see how to name them.