// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x40, %rsp
movq %rsi, %rbx
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
movslq 0xc0(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x10(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x1322d
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1b886(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0x13232
movslq 0xc0(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x18(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x1322d
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1b852(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0x13232
movslq 0xc0(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x20(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x1322d
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x1b81e(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0x13232
movslq 0xb4(%rbx), %r12
movslq 0xc0(%rbx), %rax
movl %eax, 0xb4(%rbx)
movq 0x18(%rbx), %rcx
movq 0x20(%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
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)
pushq $0x8
popq %r14
movslq 0xb4(%rbx), %rax
cmpq %rax, %r12
jle 0x131ea
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %r15
testq %r15, %r15
je 0x131d5
movq %r15, %rdi
callq 0x17248
movq %r15, %rdi
movq %r14, %rsi
callq 0x61e0
addq $-0x8, 0x20(%rbx)
decq %r12
jmp 0x131b4
leaq 0xd56b(%rip), %rsi      # 0x2075c
leaq -0x48(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
addq $0x78, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x1925e
leaq -0x48(%rbp), %rdi
callq 0x60d0
leaq -0x58(%rbp), %rdi
callq 0x17070
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x6220
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %rbx
leaq 0xd4e5(%rip), %rsi      # 0x20729
leaq -0x48(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x1a81e(%rip), %rsi     # 0x2da88
leaq 0x4aa9(%rip), %rdx      # 0x17d1a
movq %rbx, %rdi
callq 0x63c0
movq %rax, %r14
leaq -0x48(%rbp), %rdi
callq 0x60d0
jmp 0x132ae
jmp 0x132ab
movq %rax, %r14
leaq -0x48(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x1329f
jmp 0x132ae
movq %rax, %r14
movq %rbx, %rdi
callq 0x6150
jmp 0x132ae
jmp 0x132ab
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0x17070
movq %r14, %rdi
callq 0x63f0
nop