// File: /workspace/github_cpp_makefile_star2_O1/zerolfx[P]P-Machine/ind.cpp
// Function: Ind::execute(StackMachine*)
void Ind::execute(StackMachine *stack)
{
	StackAddress p;
	
	if(typeid(p) != typeid(*(stack->fStore[stack->fSP])))
		throw ExecutionError("instruction ind: type pointed to by SP is not of type address.");
		
	StackAddress *oldpointer = dynamic_cast<StackAddress*>(stack->fStore[stack->fSP]);	
	
	StackElement *object;
	if(stack->fStore[stack->fSP]->heapAddress())
	{
		if(stack->fStore[stack->fSP]->getValue() < stack->fNP)
		{
			throw ExecutionError("instruction ind: invalid heap address.");
		}
		else
		{
			object = stack->fHeap[-stack->fStore[stack->fSP]->getValue() - 1];
		}
	}
	else
	{
		if(stack->fStore[stack->fSP]->getValue() > stack->fSP)
			throw ExecutionError("instruction ind: invalid stack address.");
		else
			object = stack->fStore[stack->fStore[stack->fSP]->getValue()];
	}
	
	switch(fType)
	{
		case integer:
		{
			StackInteger p1;

			if(typeid(p1) != typeid(*object))
			{
				throw ExecutionError("instruction ind: type pointed to is not of type integer.");
			}
			else
			{
				stack->fStore[stack->fSP] = new StackInteger(*(dynamic_cast<StackInteger*>(object)));
			}
				
			break;
		}	
		case real:
		{
			StackReal p1;

			if(typeid(p1) != typeid(*object))
			{
				throw ExecutionError("instruction ind: type pointed to is not of type real.");
			}
			else
			{
				stack->fStore[stack->fSP] = new StackReal(*(dynamic_cast<StackReal*>(object)));

			}

			break;
		}
		case boolean:
		{
			StackBoolean p1;
			
			if(typeid(p1) != typeid(*object))
			{
				throw ExecutionError("instruction ind: type pointed to is not of type boolean.");
			}
			else
			{
				stack->fStore[stack->fSP] = new StackBoolean(*(dynamic_cast<StackBoolean*>(object)));
			}

			break;
		}
		case character:
		{
			StackCharacter p1;
			
			if(typeid(p1) != typeid(*object))
			{
				throw ExecutionError("instruction ind: type pointed to is not of type character.");
			}
			else
			{
				stack->fStore[stack->fSP] = new StackCharacter(*(dynamic_cast<StackCharacter*>(object)));
			}


			break;
		}
		case address:
		{
			StackAddress p1;

			if(typeid(p1) != typeid(*object))
			{
				throw ExecutionError("instruction ind: type pointed to is not of type address.");
			}
			else
			{
				stack->fStore[stack->fSP] = new StackAddress(*(dynamic_cast<StackAddress*>(object)));
			}
				
			break;
		}
	}
	
	delete oldpointer;	
	
	// adding cost of this instruction
	stack->fTime.count("ind");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
callq 0x1a3d0
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r13
testq %r13, %r13
je 0xd8b8
movq (%r13), %r14
movq -0x8(%r14), %rax
leaq 0x2656b(%rip), %rcx     # 0x33960
movq 0x8(%rcx), %r12
movq 0x8(%rax), %rsi
cmpq %rsi, %r12
je 0xd41d
cmpb $0x2a, (%r12)
je 0xd85e
movq %r12, %rdi
callq 0x6310
testl %eax, %eax
jne 0xd85e
leaq 0x2660c(%rip), %rsi     # 0x33a30
leaq 0x26535(%rip), %rdx     # 0x33960
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x6260
movq %rax, -0x60(%rbp)
movq %r13, %rdi
callq *0x88(%r14)
movslq 0xb4(%rbx), %rcx
movq 0x18(%rbx), %rdx
movq (%rdx,%rcx,8), %rdi
movq (%rdi), %rcx
movq 0x68(%rcx), %rcx
testb %al, %al
je 0xd488
callq *%rcx
cmpl 0xb8(%rbx), %eax
jl 0xd8bd
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
leaq 0x30(%rbx), %r14
notl %eax
jmp 0xd4aa
callq *%rcx
movslq 0xb4(%rbx), %rcx
cmpl %ecx, %eax
jg 0xd917
leaq 0x18(%rbx), %r14
movq (%r14), %rax
movq (%rax,%rcx,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl 0x8(%r15), %ecx
cmpq $0x4, %rcx
ja 0xd7e4
cltq
movq (%r14), %rdx
movq (%rdx,%rax,8), %r15
leaq 0x16ee4(%rip), %rax     # 0x243ac
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq -0x58(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1aec8
testq %r15, %r15
je 0xdb3a
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x266d4(%rip), %rcx     # 0x33bc8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd517
cmpb $0x2a, (%rdi)
je 0xda7f
callq 0x6310
testl %eax, %eax
jne 0xda7f
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x26505(%rip), %rsi     # 0x33a30
leaq 0x26696(%rip), %rdx     # 0x33bc8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x265cd(%rip), %rcx     # 0x33b10
addq $0x10, %rcx
movq %rcx, (%r12)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%r12)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %r12, (%rcx,%rax,8)
leaq -0x58(%rbp), %rdi
callq 0x1aef6
jmp 0xd7e4
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x1a3d0
testq %r15, %r15
je 0xdb2b
movq (%r15), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r12
je 0xd5b3
cmpb $0x2a, (%r12)
je 0xd971
movq %r12, %rdi
callq 0x6310
testl %eax, %eax
jne 0xd971
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x26469(%rip), %rsi     # 0x33a30
leaq 0x26392(%rip), %rdx     # 0x33960
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x262c9(%rip), %rcx     # 0x338a8
addq $0x10, %rcx
movq %rcx, (%r12)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r12)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %r12, (%rcx,%rax,8)
leaq -0x58(%rbp), %rdi
callq 0x1a3f4
jmp 0xd7e4
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x1b10c
testq %r15, %r15
je 0xdb30
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x2666a(%rip), %rcx     # 0x33c98
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd651
cmpb $0x2a, (%rdi)
je 0xd9cb
callq 0x6310
testl %eax, %eax
jne 0xd9cb
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x263cb(%rip), %rsi     # 0x33a30
leaq 0x2662c(%rip), %rdx     # 0x33c98
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x26563(%rip), %rcx     # 0x33be0
addq $0x10, %rcx
movq %rcx, (%r12)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r12)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %r12, (%rcx,%rax,8)
leaq -0x58(%rbp), %rdi
callq 0x1b130
jmp 0xd7e4
leaq -0x58(%rbp), %rdi
movl $0x61, %esi
callq 0x1b308
testq %r15, %r15
je 0xdb35
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x26699(%rip), %rcx     # 0x33d68
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd6f2
cmpb $0x2a, (%rdi)
je 0xda25
callq 0x6310
testl %eax, %eax
jne 0xda25
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x2632a(%rip), %rsi     # 0x33a30
leaq 0x2665b(%rip), %rdx     # 0x33d68
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x26592(%rip), %rcx     # 0x33cb0
addq $0x10, %rcx
movq %rcx, (%r12)
movb 0x8(%rax), %al
movb %al, 0x8(%r12)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %r12, (%rcx,%rax,8)
leaq -0x58(%rbp), %rdi
callq 0x1b32c
jmp 0xd7e4
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x1aca0
testq %r15, %r15
je 0xdb3f
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x2638b(%rip), %rcx     # 0x33af8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd790
cmpb $0x2a, (%rdi)
je 0xdad6
callq 0x6310
testl %eax, %eax
jne 0xdad6
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x2628c(%rip), %rsi     # 0x33a30
leaq 0x2634d(%rip), %rdx     # 0x33af8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x26284(%rip), %rcx     # 0x33a40
addq $0x10, %rcx
movq %rcx, (%r12)
movl 0x8(%rax), %eax
movl %eax, 0x8(%r12)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %r12, (%rcx,%rax,8)
leaq -0x58(%rbp), %rdi
callq 0x1acc4
movq -0x60(%rbp), %r14
testq %r14, %r14
je 0xd802
movq %r14, %rdi
callq 0x1a3f4
movl $0x10, %esi
movq %r14, %rdi
callq 0x6210
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x16d5e(%rip), %rsi     # 0x2456f
leaq 0x16d5a(%rip), %rdx     # 0x24572
leaq -0x48(%rbp), %rdi
callq 0x746c
addq $0x78, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x1ce78
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0xd846
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
leaq -0x70(%rbp), %rdi
callq 0x1a3f4
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x16b4a(%rip), %rsi     # 0x243c5
leaq 0x16b81(%rip), %rdx     # 0x24403
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x251e4(%rip), %rsi     # 0x32a88
leaq 0xdb8b(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0xdb2b
callq 0x6250
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x16b2a(%rip), %rsi     # 0x24404
leaq 0x16b49(%rip), %rdx     # 0x2442a
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x25185(%rip), %rsi     # 0x32a88
leaq 0xdb2c(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0xdb2b
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x16af7(%rip), %rsi     # 0x2442b
leaq 0x16b17(%rip), %rdx     # 0x24452
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x2512b(%rip), %rsi     # 0x32a88
leaq 0xdad2(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0xdb2b
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x16ba8(%rip), %rsi     # 0x24536
leaq 0x16bd9(%rip), %rdx     # 0x2456e
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x250d1(%rip), %rsi     # 0x32a88
leaq 0xda78(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0xdb2b
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x16ada(%rip), %rsi     # 0x244c2
leaq 0x16b0b(%rip), %rdx     # 0x244fa
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x25077(%rip), %rsi     # 0x32a88
leaq 0xda1e(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0xdb2b
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x16ab9(%rip), %rsi     # 0x244fb
leaq 0x16aec(%rip), %rdx     # 0x24535
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x2501d(%rip), %rsi     # 0x32a88
leaq 0xd9c4(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0xdb2b
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x169f0(%rip), %rsi     # 0x2448c
leaq 0x16a1e(%rip), %rdx     # 0x244c1
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x24fc3(%rip), %rsi     # 0x32a88
leaq 0xd96a(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
jmp 0xdb2b
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x16960(%rip), %rsi     # 0x24453
leaq 0x16991(%rip), %rdx     # 0x2448b
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r15b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b418
xorl %r15d, %r15d
leaq 0x24f6c(%rip), %rsi     # 0x32a88
leaq 0xd913(%rip), %rdx      # 0x1b436
movq %r14, %rdi
callq 0x63e0
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xdb64
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdb64
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xdc6f
movq %r14, %rdi
callq 0x6170
jmp 0xdc6f
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xdb9a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdb9a
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xdc80
movq %r14, %rdi
callq 0x6170
jmp 0xdc80
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xdbd0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdbd0
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xdc8e
movq %r14, %rdi
callq 0x6170
jmp 0xdc8e
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xdc06
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdc06
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xdc9c
movq %r14, %rdi
callq 0x6170
jmp 0xdc9c
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xdc3c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdc3c
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xdcaa
movq %r14, %rdi
callq 0x6170
jmp 0xdcaa
jmp 0xdd02
jmp 0xdd02
jmp 0xdd02
jmp 0xdd02
jmp 0xdd02
jmp 0xdcb5
jmp 0xdcb5
jmp 0xdccf
jmp 0xdccf
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1acc4
jmp 0xdd05
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1aef6
jmp 0xdd05
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1b32c
jmp 0xdd05
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1b130
jmp 0xdd05
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1a3f4
jmp 0xdd05
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0xdcd5
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdcd5
movq %rax, %rbx
movb $0x1, %r15b
testb %r15b, %r15b
je 0xdd05
movq %r14, %rdi
callq 0x6170
jmp 0xdd05
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0xdd05
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdd05
jmp 0xdd02
jmp 0xdd02
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x1a3f4
movq %rbx, %rdi
callq 0x6410