// File: /workspace/github_cpp_makefile_star2_O1/zerolfx[P]P-Machine/div.cpp
// Function: Div::execute(StackMachine*)
void Div::execute(StackMachine *stack) 
{
	// check if the stack contains at least two entries
	if(stack->fSP < 1)
		throw ExecutionError("instruction add: requires 2 stackelements to be present.");
		
	switch(fType)
	{
		case integer:
		{
			StackInteger p1;

			// check if the two uppermost stackentries are of type integer
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
				throw ExecutionError("instruction div: SP does not point to element of type integer.");
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
				throw ExecutionError("instruction div: SP - 1 does not point to element of type integer.");

			break;
		}	
		case real:
		{
			StackReal p1;
			
			// check if the two uppermost stackentries are of type real
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
				throw ExecutionError("instruction div: SP does not point to element of type real.");
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
				throw ExecutionError("instruction div: SP - 1 does not point to element of type real.");
			break;
		}
		default:
			cerr << "operation not supported for this type" << endl;
	}
	
	// first check for a possible division by zero
	if(stack->fStore[stack->fSP]->isZero())
		throw ExecutionError("instruction div: illegal action: divide by zero.");

	// actual division
	stack->fStore[stack->fSP - 1]->div(stack->fStore[stack->fSP]);
	
	// SP := SP - 1
	delete stack->fStore[stack->fSP];
	stack->fStore[stack->fSP] = 0;
	stack->fStore.pop_back();
	--stack->fSP;
	
	// adding cost of this instruction
	stack->fTime.count("div");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
cmpl $0x0, 0xb4(%rsi)
jle 0x97f7
movq %rsi, %rbx
movl 0x8(%rdi), %eax
testl %eax, %eax
je 0x9645
cmpl $0x1, %eax
jne 0x96e1
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1aca0
movslq 0xb4(%rbx), %r15
movq 0x18(%rbx), %r12
movq (%r12,%r15,8), %rax
testq %rax, %rax
je 0x98ab
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x2a520(%rip), %rcx     # 0x33af8
movq 0x8(%rcx), %r14
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x95ff
cmpb $0x2a, (%r14)
je 0x98b5
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x98b5
movq -0x8(%r12,%r15,8), %rax
testq %rax, %rax
je 0x98ab
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x9637
cmpb $0x2a, (%r14)
je 0x9969
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x9969
leaq -0x50(%rbp), %rdi
callq 0x1acc4
jmp 0x9723
leaq -0x50(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1aec8
movslq 0xb4(%rbx), %r15
movq 0x18(%rbx), %r12
movq (%r12,%r15,8), %rax
testq %rax, %rax
je 0x98b0
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x2a551(%rip), %rcx     # 0x33bc8
movq 0x8(%rcx), %r14
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x969e
cmpb $0x2a, (%r14)
je 0x990f
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x990f
movq -0x8(%r12,%r15,8), %rax
testq %rax, %rax
je 0x98b0
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x96d6
cmpb $0x2a, (%r14)
je 0x99c0
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x99c0
leaq -0x50(%rbp), %rdi
callq 0x1aef6
jmp 0x9723
movq 0x2a908(%rip), %r14     # 0x33ff0
leaq 0x19c01(%rip), %rsi     # 0x232f0
movl $0x25, %edx
movq %r14, %rdi
callq 0x6270
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x61d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x6030
movq %rax, %rdi
callq 0x6140
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
jne 0x9851
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rdi
movq (%rcx,%rax,8), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r14
testq %r14, %r14
je 0x9786
movq %r14, %rdi
callq 0x1a5cc
movl $0x8, %esi
movq %r14, %rdi
callq 0x6210
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
addq $-0x8, 0x20(%rbx)
decl %eax
movl %eax, 0xb4(%rbx)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x19fd2(%rip), %rsi     # 0x23787
leaq 0x19fce(%rip), %rdx     # 0x2378a
leaq -0x40(%rbp), %rdi
callq 0x746c
addq $0x78, %rbx
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x1ce78
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x97ea
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x199a5(%rip), %rsi     # 0x231b9
leaq 0x199d6(%rip), %rdx     # 0x231f1
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x2924b(%rip), %rsi     # 0x32a88
leaq 0x11bf2(%rip), %rdx     # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x9a15
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x19ee8(%rip), %rsi     # 0x23756
leaq 0x19f11(%rip), %rdx     # 0x23786
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x291f1(%rip), %rsi     # 0x32a88
leaq 0x11b98(%rip), %rdx     # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x9a15
callq 0x6250
callq 0x6250
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x19d86(%rip), %rsi     # 0x23658
leaq 0x19dbd(%rip), %rdx     # 0x23696
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x2918d(%rip), %rsi     # 0x32a88
leaq 0x11b34(%rip), %rdx     # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x9a15
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x19dae(%rip), %rsi     # 0x236da
leaq 0x19de2(%rip), %rdx     # 0x23715
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x29133(%rip), %rsi     # 0x32a88
leaq 0x11ada(%rip), %rdx     # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x9a15
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x19d11(%rip), %rsi     # 0x23697
leaq 0x19d4c(%rip), %rdx     # 0x236d9
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x290d9(%rip), %rsi     # 0x32a88
leaq 0x11a80(%rip), %rdx     # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x9a15
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x19d39(%rip), %rsi     # 0x23716
leaq 0x19d71(%rip), %rdx     # 0x23755
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x29082(%rip), %rsi     # 0x32a88
leaq 0x11a29(%rip), %rdx     # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x9a1d
jmp 0x9a37
jmp 0x9a4c
jmp 0x9a66
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x9a3d
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x9a3d
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x9ab1
movq %r14, %rdi
callq 0x6170
jmp 0x9ab1
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x9a6c
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x9a6c
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x9abf
movq %r14, %rdi
callq 0x6170
jmp 0x9abf
jmp 0x9a7f
jmp 0x9a99
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x9a9f
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x9a9f
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x9ae7
movq %r14, %rdi
callq 0x6170
jmp 0x9ae7
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1aef6
jmp 0x9ae7
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1acc4
jmp 0x9ae7
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x9ae7
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x9ae7
movq %rax, %rbx
movq %rbx, %rdi
callq 0x6410
nop