tests: Add test for semantics of for-loop that optimisation can break.