// A copy of the `cprog1' test, this time using
// the magic set transformation
.pragma "magic-transform" "*"

//0: x = 0; y = 10, z = 100;
//1: while( x < y) { x++; }
//2: while( y < z) { y++; }
//3: assert(y = 101);

.decl loop(line: number, x:number, y:number, z:number)
.decl Res()
.output Res()

loop(0, 0, 10, 100).

loop(1, x, y, z)   :- loop(0, x, y, z).
loop(1, x+1, y, z) :- loop(1, x, y, _), loop(0, _, _, z), x < y.

loop(2, x, y, z) :- loop(1, x, y, z), x >= y.
loop(2, x, y+1, z) :- loop(2, _, y, z), loop(1, x, _, _),  y < z.

loop(3, x, y, z) :- loop(2, x, y, z), y >= z.
Res() :- loop(3, _, y, _), y = 100.
