// File: zerolfx[P]P-Machine/mul.cpp
// Function: Mul::execute(StackMachine*)
void Mul::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 mul: SP does not point to element of type integer.");
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
				throw ExecutionError("instruction mul: 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 mul: SP does not point to element of type real.");
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 1])))
				throw ExecutionError("instruction mul: SP - 1 does not point to element of type real.");
			break;
		}
		default:
			cerr << "operation not supported for this type" << endl;
	}
	
	// actual addition
	stack->fStore[stack->fSP - 1]->mul(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("mul");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0xb4(%rax)
jge 0x1c067
movb $0x1, -0x45(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x148(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x74f0
movq -0x140(%rbp), %rdx
leaq 0x1b1d7(%rip), %rsi     # 0x371b9
leaq -0x30(%rbp), %rdi
callq 0x8940
jmp 0x1bfed
movq -0x148(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x283d0
jmp 0x1bfff
movq -0x148(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0x2da6f(%rip), %rsi     # 0x49a80
leaq 0xc3e8(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x1c71f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c045
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7170
leaq -0x31(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x45(%rbp)
jne 0x1c056
jmp 0x1c062
movq -0x148(%rbp), %rdi
callq 0x71c0
jmp 0x1c716
movq -0x138(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x14c(%rbp)
testl %eax, %eax
je 0x1c2f8
jmp 0x1c081
movl -0x14c(%rbp), %eax
subl $0x1, %eax
jne 0x1c57d
jmp 0x1c092
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x27340
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x158(%rbp)
cmpq $0x0, %rax
jne 0x1c0cc
callq 0x7300
jmp 0x1c0cc
movq -0x158(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x2ea0f(%rip), %rdi     # 0x4aaf0
callq 0x9370
testb $0x1, %al
jne 0x1c0ef
jmp 0x1c1b8
movb $0x1, -0x7a(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x168(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x74f0
movq -0x160(%rbp), %rdx
leaq 0x1cf7f(%rip), %rsi     # 0x390a1
leaq -0x78(%rbp), %rdi
callq 0x8940
jmp 0x1c12d
movq -0x168(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x283d0
jmp 0x1c13f
movq -0x168(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x2d92f(%rip), %rsi     # 0x49a80
leaq 0xc2a8(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x1c71f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c2ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c196
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x7170
leaq -0x79(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x7a(%rbp)
jne 0x1c1a7
jmp 0x1c1b3
movq -0x168(%rbp), %rdi
callq 0x71c0
jmp 0x1c2ea
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x170(%rbp)
cmpq $0x0, %rax
jne 0x1c1ec
callq 0x7300
jmp 0x1c1ec
movq -0x170(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x2e8ef(%rip), %rdi     # 0x4aaf0
callq 0x9370
testb $0x1, %al
jne 0x1c20f
jmp 0x1c2dc
movb $0x1, -0xa2(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x180(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x74f0
movq -0x178(%rbp), %rdx
leaq 0x1ce98(%rip), %rsi     # 0x390e0
leaq -0xa0(%rbp), %rdi
callq 0x8940
jmp 0x1c256
movq -0x180(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x283d0
jmp 0x1c26b
movq -0x180(%rbp), %rdi
movb $0x0, -0xa2(%rbp)
leaq 0x2d800(%rip), %rsi     # 0x49a80
leaq 0xc179(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x1c71f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c2b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7170
leaq -0xa1(%rbp), %rdi
callq 0x72e0
testb $0x1, -0xa2(%rbp)
jne 0x1c2ce
jmp 0x1c2da
movq -0x180(%rbp), %rdi
callq 0x71c0
jmp 0x1c2ea
leaq -0x58(%rbp), %rdi
callq 0x27380
jmp 0x1c59f
leaq -0x58(%rbp), %rdi
callq 0x27380
jmp 0x1c716
leaq -0xb8(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x27840
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x188(%rbp)
cmpq $0x0, %rax
jne 0x1c336
callq 0x7300
jmp 0x1c336
movq -0x188(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x2e875(%rip), %rdi     # 0x4abc0
callq 0x9370
testb $0x1, %al
jne 0x1c359
jmp 0x1c43a
movb $0x1, -0xda(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x198(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x74f0
movq -0x190(%rbp), %rdx
leaq 0x1cd91(%rip), %rsi     # 0x39123
leaq -0xd8(%rbp), %rdi
callq 0x8940
jmp 0x1c3a0
movq -0x198(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x283d0
jmp 0x1c3b5
movq -0x198(%rbp), %rdi
movb $0x0, -0xda(%rbp)
leaq 0x2d6b6(%rip), %rsi     # 0x49a80
leaq 0xc02f(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x1c71f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c56c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c412
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x7170
leaq -0xd9(%rbp), %rdi
callq 0x72e0
testb $0x1, -0xda(%rbp)
jne 0x1c429
jmp 0x1c435
movq -0x198(%rbp), %rdi
callq 0x71c0
jmp 0x1c56c
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
cmpq $0x0, %rax
jne 0x1c46e
callq 0x7300
jmp 0x1c46e
movq -0x1a0(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x2e73d(%rip), %rdi     # 0x4abc0
callq 0x9370
testb $0x1, %al
jne 0x1c491
jmp 0x1c55e
movb $0x1, -0x102(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0x1b0(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x74f0
movq -0x1a8(%rbp), %rdx
leaq 0x1cc95(%rip), %rsi     # 0x3915f
leaq -0x100(%rbp), %rdi
callq 0x8940
jmp 0x1c4d8
movq -0x1b0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x283d0
jmp 0x1c4ed
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x102(%rbp)
leaq 0x2d57e(%rip), %rsi     # 0x49a80
leaq 0xbef7(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x1c71f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c539
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x7170
leaq -0x101(%rbp), %rdi
callq 0x72e0
testb $0x1, -0x102(%rbp)
jne 0x1c550
jmp 0x1c55c
movq -0x1b0(%rbp), %rdi
callq 0x71c0
jmp 0x1c56c
leaq -0xb8(%rbp), %rdi
callq 0x27880
jmp 0x1c59f
leaq -0xb8(%rbp), %rdi
callq 0x27880
jmp 0x1c716
movq 0x2ea6c(%rip), %rdi     # 0x4aff0
leaq 0x1ad65(%rip), %rsi     # 0x372f0
callq 0x7250
movq %rax, %rdi
movq 0x2ea0e(%rip), %rsi     # 0x4afa8
callq 0x72b0
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x1c0(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq -0x1c0(%rbp), %rdi
movq (%rax), %rsi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
je 0x1c633
movq -0x1b8(%rbp), %rdi
callq 0x26ca0
movq -0x1b8(%rbp), %rdi
movl $0x8, %esi
callq 0x7280
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0xb4(%rax), %rsi
callq 0x8e70
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
callq 0x8e90
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %ecx
decl %ecx
movl %ecx, 0xb4(%rax)
movq -0x10(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x1d0(%rbp)
leaq -0x129(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x74f0
movq -0x1c8(%rbp), %rdx
leaq 0x1caff(%rip), %rsi     # 0x3919f
leaq -0x128(%rbp), %rdi
callq 0x8940
jmp 0x1c6ae
movq -0x1d0(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x2c4d0
jmp 0x1c6c3
leaq -0x128(%rbp), %rdi
callq 0x7170
leaq -0x129(%rbp), %rdi
callq 0x72e0
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x1c70a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x7170
leaq -0x129(%rbp), %rdi
callq 0x72e0
movq -0x40(%rbp), %rdi
callq 0x74e0
nop