// File: /workspace/github_cpp_makefile_star2_O1/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 0x1a3d0
movslq 0xb4(%rbx), %rax
testq %rax, %rax
jle 0x1757c
movq 0x18(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rax
testq %rax, %rax
je 0x175d6
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1c818(%rip), %rcx     # 0x33960
movq 0x8(%rcx), %r14
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x1716f
cmpb $0x2a, (%r14)
je 0x17522
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x17522
movl 0x8(%r15), %eax
cmpq $0x4, %rax
ja 0x1736c
leaq 0xe988(%rip), %rcx      # 0x25b0c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x50(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1aec8
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17858
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1ca09(%rip), %rcx     # 0x33bc8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x171e2
cmpb $0x2a, (%rdi)
je 0x1779d
callq 0x6310
testl %eax, %eax
jne 0x1779d
leaq -0x50(%rbp), %rdi
callq 0x1aef6
jmp 0x1736c
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1a3d0
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17849
movq (%rax), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r14
je 0x1723d
cmpb $0x2a, (%r14)
je 0x1768f
movq %r14, %rdi
callq 0x6310
testl %eax, %eax
jne 0x1768f
leaq -0x50(%rbp), %rdi
callq 0x1a3f4
jmp 0x1736c
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1b10c
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x1784e
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1ca1c(%rip), %rcx     # 0x33c98
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x1729f
cmpb $0x2a, (%rdi)
je 0x176e9
callq 0x6310
testl %eax, %eax
jne 0x176e9
leaq -0x50(%rbp), %rdi
callq 0x1b130
jmp 0x1736c
leaq -0x50(%rbp), %rdi
movl $0x61, %esi
callq 0x1b308
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x17853
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1ca87(%rip), %rcx     # 0x33d68
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x17304
cmpb $0x2a, (%rdi)
je 0x17743
callq 0x6310
testl %eax, %eax
jne 0x17743
leaq -0x50(%rbp), %rdi
callq 0x1b32c
jmp 0x1736c
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x1aca0
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x1785d
movq (%rax), %rax
movq -0x8(%rax), %rax
leaq 0x1c7b8(%rip), %rcx     # 0x33af8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0x17363
cmpb $0x2a, (%rdi)
je 0x177f4
callq 0x6310
testl %eax, %eax
jne 0x177f4
leaq -0x50(%rbp), %rdi
callq 0x1acc4
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 0x1740b
callq *%rcx
cmpl 0xb8(%rbx), %eax
jl 0x175db
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 0x173ed
movq %r14, %rdi
callq 0x1a5cc
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 0x1746e
callq *%rcx
movslq 0xb4(%rbx), %rcx
leal -0x2(%rcx), %edx
cmpl %edx, %eax
jg 0x17635
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 0x17454
movq %r14, %rdi
callq 0x1a5cc
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 0x174a6
movq %r14, %rdi
callq 0x1a5cc
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 0xe864(%rip), %rsi      # 0x25d3b
leaq 0xe860(%rip), %rdx      # 0x25d3e
leaq -0x40(%rbp), %rdi
callq 0x746c
addq $0x78, %rbx
leaq -0x40(%rbp), %rsi
movq %rbx, %rdi
callq 0x1ce78
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x1750c
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
leaq -0x60(%rbp), %rdi
callq 0x1a3f4
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), %r12
movq %r12, -0x10(%r12)
leaq 0xe630(%rip), %rsi      # 0x25b6f
leaq 0xe66b(%rip), %rdx      # 0x25bb1
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b520(%rip), %rsi     # 0x32a88
leaq 0x3ec7(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe58c(%rip), %rsi      # 0x25b25
leaq 0xe5ce(%rip), %rdx      # 0x25b6e
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b4c6(%rip), %rsi     # 0x32a88
leaq 0x3e6d(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
callq 0x6250
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe6f4(%rip), %rsi      # 0x25cec
leaq 0xe713(%rip), %rdx      # 0x25d12
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b467(%rip), %rsi     # 0x32a88
leaq 0x3e0e(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe6c1(%rip), %rsi      # 0x25d13
leaq 0xe6e1(%rip), %rdx      # 0x25d3a
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b40d(%rip), %rsi     # 0x32a88
leaq 0x3db4(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe601(%rip), %rsi      # 0x25cad
leaq 0xe638(%rip), %rdx      # 0x25ceb
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b3b3(%rip), %rsi     # 0x32a88
leaq 0x3d5a(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe527(%rip), %rsi      # 0x25c2d
leaq 0xe55e(%rip), %rdx      # 0x25c6b
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b359(%rip), %rsi     # 0x32a88
leaq 0x3d00(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe50c(%rip), %rsi      # 0x25c6c
leaq 0xe545(%rip), %rdx      # 0x25cac
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b2ff(%rip), %rsi     # 0x32a88
leaq 0x3ca6(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe437(%rip), %rsi      # 0x25bf1
leaq 0xe46b(%rip), %rdx      # 0x25c2c
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b2a5(%rip), %rsi     # 0x32a88
leaq 0x3c4c(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0x17849
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0xe3a1(%rip), %rsi      # 0x25bb2
leaq 0xe3d8(%rip), %rdx      # 0x25bf0
leaq -0x40(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x40(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x1b24e(%rip), %rsi     # 0x32a88
leaq 0x3bf5(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x17882
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x17882
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x17965
movq %r14, %rdi
callq 0x6170
jmp 0x17965
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x178b8
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x178b8
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x17976
movq %r14, %rdi
callq 0x6170
jmp 0x17976
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x178ee
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x178ee
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x17987
movq %r14, %rdi
callq 0x6170
jmp 0x17987
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x17924
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x17924
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x17998
movq %r14, %rdi
callq 0x6170
jmp 0x17998
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x17953
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x17953
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x179a6
movq %r14, %rdi
callq 0x6170
jmp 0x179a6
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1acc4
jmp 0x17a15
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1aef6
jmp 0x17a15
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1b32c
jmp 0x17a15
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1b130
jmp 0x17a15
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1a3f4
jmp 0x17a15
jmp 0x17a12
jmp 0x17a12
jmp 0x17a12
jmp 0x17a12
jmp 0x17a12
jmp 0x179c7
jmp 0x179c7
jmp 0x179e1
jmp 0x179e1
jmp 0x179c7
jmp 0x179e1
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x179e7
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x179e7
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0x17a15
movq %r14, %rdi
callq 0x6170
jmp 0x17a15
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x17a15
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0x17a15
jmp 0x17a12
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x1a3f4
movq %rbx, %rdi
callq 0x6410