// File: /workspace/github_cpp_makefile_star2_O1/zerolfx[P]P-Machine/retf.cpp
// Function: Retf::execute(StackMachine*)
void Retf::execute(StackMachine *stack)
{	
	StackAddress p;
	if((typeid(p) != typeid(*(stack->fStore[stack->fMP + 2]))
		|| (typeid(p) != typeid(*(stack->fStore[stack->fMP + 3])))
		|| (typeid(p) != typeid(*(stack->fStore[stack->fMP + 4])))))
	{
		throw ExecutionError("instruction retf: stackframe has been compromised.");
	}
	
	int oldSP = stack->fSP;
	
	// function result in the local stack
	stack->fSP = stack->fMP;
	
	// return branch
	stack->fPC = stack->fStore[stack->fMP + 4]->getValue();
	
	// restore EP
	stack->fEP = stack->fStore[stack->fMP + 3]->getValue();
	
	// restore MP
	stack->fMP = stack->fStore[stack->fMP + 2]->getValue();
	
	for(int i = oldSP; i > stack->fSP; --i)
	{
		delete stack->fStore[i];
		stack->fStore.pop_back();
	}
	
	// adding cost of this instruction
	stack->fTime.count("retf");

	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x1a3d0
movl 0xc0(%rbx), %eax
movl %eax, -0x2c(%rbp)
movslq %eax, %r15
movq 0x18(%rbx), %r13
movq 0x10(%r13,%r15,8), %rax
testq %rax, %rax
je 0x1594d
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1e1f1(%rip), %rcx     # 0x33960
movq 0x8(%rcx), %r14
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x15796
cmpb $0x2a, (%r14)
je 0x158f8
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x158f8
movq 0x18(%r13,%r15,8), %rax
testq %rax, %rax
je 0x1594d
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x157ce
cmpb $0x2a, (%r14)
je 0x158f8
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x158f8
movq 0x20(%r13,%r15,8), %r15
testq %r15, %r15
je 0x1594d
movq (%r15), %r12
movq -0x8(%r12), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x15807
cmpb $0x2a, (%r14)
je 0x158f8
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x158f8
movslq 0xb4(%rbx), %r13
movl -0x2c(%rbp), %eax
movl %eax, 0xb4(%rbx)
movq %r15, %rdi
callq *0x68(%r12)
movl %eax, 0xb0(%rbx)
movslq 0xc0(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x18(%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, 0xbc(%rbx)
movslq 0xc0(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x10(%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, 0xc0(%rbx)
cmpl 0xb4(%rbx), %r13d
jle 0x1589c
movq 0x18(%rbx), %rax
movq (%rax,%r13,8), %r14
testq %r14, %r14
je 0x15888
movq %r14, %rdi
callq 0x1a5cc
movl $0x8, %esi
movq %r14, %rdi
callq 0x6210
addq $-0x8, 0x20(%rbx)
decq %r13
movslq 0xb4(%rbx), %rax
cmpq %rax, %r13
jg 0x15866
leaq -0x40(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xfeb1(%rip), %rsi      # 0x2575c
leaq 0xfeae(%rip), %rdx      # 0x25760
leaq -0x50(%rbp), %rdi
callq 0x746c
addq $0x78, %rbx
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x1ce78
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x158e0
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x6210
leaq -0x60(%rbp), %rdi
callq 0x1a3f4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xfe14(%rip), %rsi      # 0x25729
leaq 0xfe3f(%rip), %rdx      # 0x2575b
leaq -0x50(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1d14a(%rip), %rsi     # 0x32a88
leaq 0x5af1(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
callq 0x6250
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x159a2
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x159a2
jmp 0x1599f
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x1598e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x1598e
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x159a2
movq %r14, %rdi
callq 0x6170
jmp 0x159a2
jmp 0x1599f
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x1a3f4
movq %rbx, %rdi
callq 0x6410
nop