Transform loops into a normal form