// Integer division.

.method idiv
.args   3                       // ( int x, int y )
.define x = 1
.define y = 2                    
.locals 2                       // int q, int sign;
.define q = 3
.define sign = 4	

	iload y
	IFEQ end_if1		// ( y == 0 )		
	
	iload x
	iflt if2		// ( x < 0 )
	goto ty
if2:
	bipush 0
	iload x
	isub
	istore x		// x = -x
	bipush 1
	iload sign
	iadd        		// sign++
	istore sign
	
ty:
        iload y
	iflt if3		// ( y < 0 )
	goto pre_w 
if3:
	bipush 0
	iload y
	isub
	istore y		// y = -y
	bipush 1
	iload sign
	iadd        		// sign++
	istore sign

pre_w:
	bipush 0
	istore q		// q = 0

while:                          // while ( x >= y ) {     
        iload x
	iload y
	isub
	iflt end_while 		// ( x >= y ) 
	iload x
        iload y
	isub
	istore x		// x = x - y
        bipush 1
	iload q
	iadd
	istore q		// q++
        goto while              // }
end_while:

	bipush 1
	iload sign
	isub
	IFEQ if4		// ( sign == 0 )
	goto end_if2

if4:
	bipush 0
	iload q
	isub
	istore q		// ( q = -q )
	goto end_if2

end_if2:
	iload q
	ireturn			// return q

end_if1:
        bipush 0
        ireturn                 // return 0;

.method main
.args   1
.define OBJREF = 44
  
        bipush OBJREF
        bipush -12
        bipush 2
        invokevirtual idiv      
        ireturn                 // return imul(2,3);
