// File: /workspace/github_cpp_makefile_star2_O3/zerolfx[P]P-Machine/sub.cpp
// Function: Sub::execute(StackMachine*)
void Sub::execute(StackMachine *stack) 
{
	// check if the stack contains at least two entries
	if(stack->fSP < 1)
		throw ExecutionError("instruction sub: 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 sub: SP does not point to element of type integer.");
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
				throw ExecutionError("instruction sub: 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 sub: SP does not point to element of type real.");
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
				throw ExecutionError("instruction sub: SP - 1 does not point to element of type real.");
			break;
		}
		default:
			cerr << "operation not supported for this type" << endl;
	}
	
	// actual subtraction
	stack->fStore[stack->fSP - 1]->sub(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("sub");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
cmpl $0x0, 0xb4(%rsi)
jle 0x182cf
movq %rsi, %rbx
movl 0x8(%rdi), %eax
testl %eax, %eax
je 0x1813d
cmpl $0x1, %eax
jne 0x181d9
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1a9d4
movslq 0xb4(%rbx), %r15
movq 0x18(%rbx), %r12
movq (%r12,%r15,8), %rax
testq %rax, %rax
je 0x18328
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1ba28(%rip), %rcx     # 0x33af8
movq 0x8(%rcx), %r14
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x180f7
cmpb $0x2a, (%r14)
je 0x18332
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x18332
movq -0x8(%r12,%r15,8), %rax
testq %rax, %rax
je 0x18328
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x1812f
cmpb $0x2a, (%r14)
je 0x183e4
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x183e4
leaq -0x50(%rbp), %rdi
callq 0x1a9f8
jmp 0x1821b
leaq -0x50(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1abfc
movslq 0xb4(%rbx), %r15
movq 0x18(%rbx), %r12
movq (%r12,%r15,8), %rax
testq %rax, %rax
je 0x1832d
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1ba59(%rip), %rcx     # 0x33bc8
movq 0x8(%rcx), %r14
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x18196
cmpb $0x2a, (%r14)
je 0x1838b
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x1838b
movq -0x8(%r12,%r15,8), %rax
testq %rax, %rax
je 0x1832d
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x181ce
cmpb $0x2a, (%r14)
je 0x1843a
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x1843a
leaq -0x50(%rbp), %rdi
callq 0x1ac2a
jmp 0x1821b
movq 0x1be10(%rip), %r14     # 0x33ff0
leaq 0xb109(%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 -0x8(%rcx,%rax,8), %rdi
movq (%rcx,%rax,8), %rsi
movq (%rdi), %rax
callq *0x8(%rax)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r14
testq %r14, %r14
je 0x18251
movq %r14, %rdi
callq 0x1a300
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 0xddbc(%rip), %rsi      # 0x26049
leaq 0xddb8(%rip), %rdx      # 0x2604c
leaq -0x40(%rbp), %rdi
callq 0x746c
addq $0x78, %rbx
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x1cbc8
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x182c2
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), %r15
movq %r15, -0x10(%r15)
leaq 0xdc27(%rip), %rsi      # 0x25f12
leaq 0xdc58(%rip), %rdx      # 0x25f4a
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1a774(%rip), %rsi     # 0x32a88
leaq 0x2e4f(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x1848e
callq 0x6250
callq 0x6250
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xdbfd(%rip), %rsi      # 0x25f4b
leaq 0xdc34(%rip), %rdx      # 0x25f89
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1a711(%rip), %rsi     # 0x32a88
leaq 0x2dec(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x1848e
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xdc26(%rip), %rsi      # 0x25fcd
leaq 0xdc5a(%rip), %rdx      # 0x26008
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1a6b8(%rip), %rsi     # 0x32a88
leaq 0x2d93(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x1848e
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xdb8a(%rip), %rsi      # 0x25f8a
leaq 0xdbc5(%rip), %rdx      # 0x25fcc
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1a65f(%rip), %rsi     # 0x32a88
leaq 0x2d3a(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x1848e
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xdbb3(%rip), %rsi      # 0x26009
leaq 0xdbeb(%rip), %rdx      # 0x26048
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1a609(%rip), %rsi     # 0x32a88
leaq 0x2ce4(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x18496
jmp 0x184b5
jmp 0x184c2
jmp 0x184e1
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x184ae
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x184b8
jmp 0x1851d
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x1851d
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x184da
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x184e4
jmp 0x1852b
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x1852b
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x18506
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x18510
jmp 0x18553
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x18553
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1ac2a
jmp 0x18553
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1a9f8
jmp 0x18553
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x18553
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x18553
movq %rax, %rbx
movq %rbx, %rdi
callq 0x6410
nop