// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x38, %rsp
cmpl $0x0, 0xb4(%rsi)
jle 0x8fce
movq %rsi, %rbx
movl 0x8(%rdi), %eax
testl %eax, %eax
je 0x8e7f
cmpl $0x1, %eax
jne 0x8efd
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x175ac
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x9066
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x25cc8(%rip), %rdi     # 0x2eaf8
callq 0x76ba
testb %al, %al
jne 0x9070
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x9066
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x25c94(%rip), %rdi     # 0x2eaf8
callq 0x76ba
testb %al, %al
jne 0x9108
leaq -0x50(%rbp), %rdi
callq 0x175d0
jmp 0x8f18
leaq -0x50(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x177d4
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x906b
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x25d17(%rip), %rdi     # 0x2ebc8
callq 0x76ba
testb %al, %al
jne 0x90bc
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x906b
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x25ce3(%rip), %rdi     # 0x2ebc8
callq 0x76ba
testb %al, %al
jne 0x9151
leaq -0x50(%rbp), %rdi
callq 0x17802
jmp 0x8f18
movq 0x260ec(%rip), %rdi     # 0x2eff0
leaq 0x153e5(%rip), %rsi     # 0x1e2f0
callq 0x61b0
movq %rax, %rdi
callq 0x60e0
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
jne 0x901a
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 0x8f6e
movq %r14, %rdi
callq 0x17248
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x61e0
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
andq $0x0, (%rcx,%rax,8)
addq $-0x8, 0x20(%rbx)
decl %eax
movl %eax, 0xb4(%rbx)
leaq 0x157ea(%rip), %rsi     # 0x1e787
leaq -0x40(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x72a6
addq $0x78, %rbx
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x1925e
leaq -0x40(%rbp), %rdi
callq 0x60d0
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x151d9(%rip), %rsi     # 0x1e1b9
leaq -0x40(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x24a82(%rip), %rsi     # 0x2da88
leaq 0xed0d(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x9198
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x1572a(%rip), %rsi     # 0x1e756
leaq -0x40(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x24a36(%rip), %rsi     # 0x2da88
leaq 0xecc1(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x9198
callq 0x6220
callq 0x6220
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x155d6(%rip), %rsi     # 0x1e658
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x249e0(%rip), %rsi     # 0x2da88
leaq 0xec6b(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x9198
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x1560c(%rip), %rsi     # 0x1e6da
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x24994(%rip), %rsi     # 0x2da88
leaq 0xec1f(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x9198
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x1557d(%rip), %rsi     # 0x1e697
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x24948(%rip), %rsi     # 0x2da88
leaq 0xebd3(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x9198
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x155b3(%rip), %rsi     # 0x1e716
leaq -0x40(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x248ff(%rip), %rsi     # 0x2da88
leaq 0xeb8a(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x91a0
jmp 0x91b3
jmp 0x91c0
jmp 0x91d3
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x91b6
jmp 0x9207
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x9207
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x91d6
jmp 0x9215
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x9215
jmp 0x91e4
jmp 0x91f7
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x91fa
jmp 0x9231
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x9231
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x17802
jmp 0x9231
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x175d0
jmp 0x9231
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x60d0
jmp 0x9231
movq %rax, %rbx
movq %rbx, %rdi
callq 0x63f0
nop