// File: zerolfx[P]P-Machine/ldd.cpp
// Function: Ldd::execute(StackMachine*)
void Ldd::execute(StackMachine *stack) 
{
	if(stack->fSP < 2)
		throw ExecutionError("instruction ldd: requires 3 stackelements to be present.");
	
	StackAddress p1;
	if(typeid(p1) != typeid(*(stack->fStore[stack->fSP - 2])))
		throw ExecutionError("instruction add: SP-2 does not point to element of type address.");
		
	++stack->fSP;
	
	stack->fStore.push_back(new StackInteger(stack->fStore[stack->fSP -3]->getValue() + fQ));
	
	// adding cost of this instruction
	stack->fTime.count("ldd");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0xb4(%rax)
jge 0x25467
movb $0x1, -0x45(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0xc8(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x74f0
movq -0xc0(%rbp), %rdx
leaq 0x14e43(%rip), %rsi     # 0x3a225
leaq -0x30(%rbp), %rdi
callq 0x8940
jmp 0x253ed
movq -0xc8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x283d0
jmp 0x253ff
movq -0xc8(%rbp), %rdi
movb $0x0, -0x45(%rbp)
leaq 0x2466f(%rip), %rsi     # 0x49a80
leaq 0x2fe8(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x25719
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x25445
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 0x25456
jmp 0x25462
movq -0xc8(%rbp), %rdi
callq 0x71c0
jmp 0x25710
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x26800
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %eax
subl $0x2, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
jne 0x254a6
callq 0x7300
jmp 0x254a6
movq -0xd0(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x2549d(%rip), %rdi     # 0x4a958
callq 0x9370
testb $0x1, %al
jne 0x254c9
jmp 0x25592
movb $0x1, -0x7a(%rbp)
movl $0x20, %edi
callq 0x7110
movq %rax, -0xe0(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x74f0
movq -0xd8(%rbp), %rdx
leaq 0x14d62(%rip), %rsi     # 0x3a25e
leaq -0x78(%rbp), %rdi
callq 0x8940
jmp 0x25507
movq -0xe0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x283d0
jmp 0x25519
movq -0xe0(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0x24555(%rip), %rsi     # 0x49a80
leaq 0x2ece(%rip), %rdx      # 0x28400
callq 0x74a0
jmp 0x25719
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x25707
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x25570
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 0x25581
jmp 0x2558d
movq -0xe0(%rbp), %rdi
callq 0x71c0
jmp 0x25707
movq -0x10(%rbp), %rax
movl 0xb4(%rax), %ecx
incl %ecx
movl %ecx, 0xb4(%rax)
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0xf0(%rbp)
movl $0x10, %edi
callq 0x7270
movq %rax, -0xe8(%rbp)
jmp 0x255c6
movq -0x10(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movl 0xb4(%rax), %eax
addl $-0x3, %eax
movslq %eax, %rsi
callq 0x8e70
movq (%rax), %rdi
movq (%rdi), %rax
movq 0x68(%rax), %rax
callq *%rax
movl %eax, -0xf4(%rbp)
jmp 0x255f6
movq -0xe8(%rbp), %rdi
movl -0xf4(%rbp), %esi
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %eax
addl %eax, %esi
callq 0x27340
jmp 0x25616
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %rsi
callq 0xd2a0
jmp 0x25639
movq -0x10(%rbp), %rax
addq $0x78, %rax
movq %rax, -0x108(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x74f0
movq -0x100(%rbp), %rdx
leaq 0x14c36(%rip), %rsi     # 0x3a29f
leaq -0xa8(%rbp), %rdi
callq 0x8940
jmp 0x25677
movq -0x108(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2c4d0
jmp 0x2568c
leaq -0xa8(%rbp), %rdi
callq 0x7170
leaq -0xa9(%rbp), %rdi
callq 0x72e0
leaq -0x58(%rbp), %rdi
callq 0x26840
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xe8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x10, %esi
callq 0x7280
jmp 0x25707
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x256fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x7170
leaq -0xa9(%rbp), %rdi
callq 0x72e0
leaq -0x58(%rbp), %rdi
callq 0x26840
movq -0x40(%rbp), %rdi
callq 0x74e0
nopl (%rax)