// File: /workspace/github_cpp_makefile_star2_O3/zerolfx[P]P-Machine/sto.cpp
// Function: Sto::execute(StackMachine*)
void Sto::execute(StackMachine *stack)
{
	StackAddress p;
	
	if(stack->fSP < 1)
		throw ExecutionError("instruction sto: at least 2 stackelements are required for this operation");
		
	if(typeid(p) != typeid(*(stack->fStore[stack->fSP - 1])))
		throw ExecutionError("instruction sto: type pointed to by SP - 1 is not of type address.");
				
	switch(fType)
	{
		case integer:
		{
			StackInteger p1;

			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
			{
				throw ExecutionError("instruction sto: type pointed to by SP is not of type integer.");
			}
				
			break;
		}	
		case real:
		{
			StackReal p1;

			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
			{
				throw ExecutionError("instruction sto: type pointed to by SP is not of type real.");
			}

			break;
		}
		case boolean:
		{
			StackBoolean p1;
			
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
			{
				throw ExecutionError("instruction sto: type pointed to by SP is not of type boolean.");
			}

			break;
		}
		case character:
		{
			StackCharacter p1;
			
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
			{
				throw ExecutionError("instruction sto: type pointed to by SP is not of type character.");
			}


			break;
		}
		case address:
		{
			StackAddress p1;

			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
			{
				throw ExecutionError("instruction sto: type pointed to by SP is not of type address.");
			}
				
			break;
		}
	}
	
	if(stack->fStore[stack->fSP - 1]->heapAddress())
	{
		if(stack->fStore[stack->fSP - 1]->getValue() < stack->fNP)
		{
			throw ExecutionError("instruction sto: invalid heap address.");
		}
		else
		{
			delete stack->fHeap[-stack->fStore[stack->fSP - 1]->getValue() - 1];
			stack->fHeap[-stack->fStore[stack->fSP - 1]->getValue() - 1] = stack->fStore[stack->fSP];
		}
	}
	else
	{
		if(stack->fStore[stack->fSP - 1]->getValue() > stack->fSP - 2) 	
		{
			// -2 because the SP will be decreased by 2 as a result of this operation
			
			throw ExecutionError("instruction sto: invalid stack address.");
		}
		else
		{
			delete stack->fStore[stack->fStore[stack->fSP - 1]->getValue()];
			stack->fStore[stack->fStore[stack->fSP - 1]->getValue()] = stack->fStore[stack->fSP];
		}
	}
	
	stack->fStore.pop_back();
	delete stack->fStore[stack->fSP - 1];
	stack->fStore[stack->fSP - 1] = 0;
	stack->fStore.pop_back();

	stack->fSP -= 2;
	
	// adding cost of this instruction
	stack->fTime.count("sto");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x1a104
movslq 0xb4(%rbx), %rax
testq %rax, %rax
jle 0x1733f
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17398
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1ca54(%rip), %rcx     # 0x33960
movq 0x8(%rcx), %r14
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x16f33
cmpb $0x2a, (%r14)
je 0x172e6
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x172e6
movl 0x8(%r15), %eax
cmpq $0x4, %rax
ja 0x17130
leaq 0xebc4(%rip), %rcx      # 0x25b0c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x50(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1abfc
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17613
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1cc45(%rip), %rcx     # 0x33bc8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x16fa6
cmpb $0x2a, (%rdi)
je 0x1755a
callq 0x6310
testl %eax, %eax
jne 0x1755a
leaq -0x50(%rbp), %rdi
callq 0x1ac2a
jmp 0x17130
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1a104
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17604
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x17001
cmpb $0x2a, (%r14)
je 0x1744f
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x1744f
leaq -0x50(%rbp), %rdi
callq 0x1a128
jmp 0x17130
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1ae40
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17609
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1cc58(%rip), %rcx     # 0x33c98
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x17063
cmpb $0x2a, (%rdi)
je 0x174a8
callq 0x6310
testl %eax, %eax
jne 0x174a8
leaq -0x50(%rbp), %rdi
callq 0x1ae64
jmp 0x17130
leaq -0x50(%rbp), %rdi
movl $0x61, %esi
callq 0x1b03c
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x1760e
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1ccc3(%rip), %rcx     # 0x33d68
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x170c8
cmpb $0x2a, (%rdi)
je 0x17501
callq 0x6310
testl %eax, %eax
jne 0x17501
leaq -0x50(%rbp), %rdi
callq 0x1b060
jmp 0x17130
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1a9d4
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17618
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1c9f4(%rip), %rcx     # 0x33af8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x17127
cmpb $0x2a, (%rdi)
je 0x175b0
callq 0x6310
testl %eax, %eax
jne 0x175b0
leaq -0x50(%rbp), %rdi
callq 0x1a9f8
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x88(%rax)
movslq 0xb4(%rbx), %rcx
movq 0x18(%rbx), %rdx
movq -0x8(%rdx,%rcx,8), %rdi
movq (%rdi), %rcx
movq 0x68(%rcx), %rcx
testb %al, %al
je 0x171cf
callq *%rcx
cmpl 0xb8(%rbx), %eax
jl 0x1739d
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
leaq 0x30(%rbx), %r15
notl %eax
cltq
movq (%r15), %rcx
movq (%rcx,%rax,8), %r14
testq %r14, %r14
je 0x171a4
movq %r14, %rdi
callq 0x1a300
movl $0x8, %esi
movq %r14, %rdi
callq 0x6210
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rdi
movq (%rcx,%rax,8), %r14
movq (%rdi), %rax
callq *0x68(%rax)
notl %eax
jmp 0x17232
callq *%rcx
movslq 0xb4(%rbx), %rcx
leal -0x2(%rcx), %edx
cmpl %edx, %eax
jg 0x173f6
leaq 0x18(%rbx), %r15
movq (%r15), %rax
movq -0x8(%rax,%rcx,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
cltq
movq (%r15), %rcx
movq (%rcx,%rax,8), %r14
testq %r14, %r14
je 0x1720b
movq %r14, %rdi
callq 0x1a300
movl $0x8, %esi
movq %r14, %rdi
callq 0x6210
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rdi
movq (%rcx,%rax,8), %r14
movq (%rdi), %rax
callq *0x68(%rax)
cltq
movq (%r15), %rcx
movq %r14, (%rcx,%rax,8)
addq $-0x8, 0x20(%rbx)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %r14
testq %r14, %r14
je 0x1725d
movq %r14, %rdi
callq 0x1a300
movl $0x8, %esi
movq %r14, %rdi
callq 0x6210
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq $0x0, -0x8(%rcx,%rax,8)
addq $-0x8, 0x20(%rbx)
addl $-0x2, %eax
movl %eax, 0xb4(%rbx)
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xeaa0(%rip), %rsi      # 0x25d3b
leaq 0xea9c(%rip), %rdx      # 0x25d3e
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 0x172d0
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
leaq -0x60(%rbp), %rdi
callq 0x1a128
addq $0x40, %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 0xe86d(%rip), %rsi      # 0x25b6f
leaq 0xe8a8(%rip), %rdx      # 0x25bb1
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b75d(%rip), %rsi     # 0x32a88
leaq 0x3e38(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe7ca(%rip), %rsi      # 0x25b25
leaq 0xe80c(%rip), %rdx      # 0x25b6e
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b704(%rip), %rsi     # 0x32a88
leaq 0x3ddf(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
callq 0x6250
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe933(%rip), %rsi      # 0x25cec
leaq 0xe952(%rip), %rdx      # 0x25d12
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b6a6(%rip), %rsi     # 0x32a88
leaq 0x3d81(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe901(%rip), %rsi      # 0x25d13
leaq 0xe921(%rip), %rdx      # 0x25d3a
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b64d(%rip), %rsi     # 0x32a88
leaq 0x3d28(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe842(%rip), %rsi      # 0x25cad
leaq 0xe879(%rip), %rdx      # 0x25ceb
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b5f4(%rip), %rsi     # 0x32a88
leaq 0x3ccf(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe769(%rip), %rsi      # 0x25c2d
leaq 0xe7a0(%rip), %rdx      # 0x25c6b
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b59b(%rip), %rsi     # 0x32a88
leaq 0x3c76(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe74f(%rip), %rsi      # 0x25c6c
leaq 0xe788(%rip), %rdx      # 0x25cac
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b542(%rip), %rsi     # 0x32a88
leaq 0x3c1d(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe67b(%rip), %rsi      # 0x25bf1
leaq 0xe6af(%rip), %rdx      # 0x25c2c
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b4e9(%rip), %rsi     # 0x32a88
leaq 0x3bc4(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0x17604
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xe5e6(%rip), %rsi      # 0x25bb2
leaq 0xe61d(%rip), %rdx      # 0x25bf0
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x1b493(%rip), %rsi     # 0x32a88
leaq 0x3b6e(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x17635
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x17642
jmp 0x1770b
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x1770b
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x17667
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x17674
jmp 0x1771c
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x1771c
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x17699
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x176a6
jmp 0x1772d
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x1772d
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x176c8
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x176d2
jmp 0x1773b
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x1773b
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x176f4
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x176fe
jmp 0x17749
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x17749
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1a9f8
jmp 0x177b5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1ac2a
jmp 0x177b5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1b060
jmp 0x177b5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1ae64
jmp 0x177b5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1a128
jmp 0x177b5
jmp 0x177b2
jmp 0x177b2
jmp 0x177b2
jmp 0x177b2
jmp 0x177b2
jmp 0x1776a
jmp 0x1776a
jmp 0x17789
jmp 0x17789
jmp 0x1776a
jmp 0x17789
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r15, %rdi
je 0x17782
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0x1778c
jmp 0x177b5
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0x177b5
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x177b5
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x177b5
jmp 0x177b2
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x1a128
movq %rbx, %rdi
callq 0x6410