// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x50, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0xc5b4
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x22784(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0xc5b9
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r12
testq %r12, %r12
je 0xc21a
leaq 0x2282c(%rip), %rsi     # 0x2ea30
leaq 0x22755(%rip), %rdx     # 0x2e960
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x6230
movq %rax, %r14
jmp 0xc21d
xorl %r14d, %r14d
movq (%r12), %rax
movq %r12, %rdi
callq *0x88(%rax)
movslq 0xb4(%rbx), %rcx
movq 0x18(%rbx), %rdx
movq (%rdx,%rcx,8), %rdi
movq (%rdi), %rcx
movq 0x68(%rcx), %rcx
testb %al, %al
je 0xc26f
callq *%rcx
cmpl 0xb8(%rbx), %eax
jl 0xc605
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
leaq 0x30(%rbx), %r12
notl %eax
jmp 0xc292
callq *%rcx
movslq 0xb4(%rbx), %rcx
cmpl %ecx, %eax
jg 0xc651
leaq 0x18(%rbx), %r12
movq (%r12), %rax
movq (%rax,%rcx,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl 0x8(%r15), %ecx
cmpq $0x4, %rcx
ja 0xc559
cltq
movq (%r12), %rdx
movq (%rdx,%rax,8), %r15
leaq 0x130fb(%rip), %rax     # 0x1f3ac
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq -0x38(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x177d4
testq %r15, %r15
je 0xc6a7
movq (%r15), %rax
movq -0x8(%rax), %rsi
leaq 0x228eb(%rip), %rdi     # 0x2ebc8
callq 0x76ba
testb %al, %al
jne 0xc79a
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r12
leaq 0x22734(%rip), %rsi     # 0x2ea30
leaq 0x228c5(%rip), %rdx     # 0x2ebc8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x227fc(%rip), %rcx     # 0x2eb10
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 -0x38(%rbp), %rdi
callq 0x17802
jmp 0xc559
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
testq %r15, %r15
je 0xc69d
movq (%r15), %rax
movq -0x8(%rax), %rsi
leaq 0x225f9(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0xc6b6
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r12
leaq 0x226aa(%rip), %rsi     # 0x2ea30
leaq 0x225d3(%rip), %rdx     # 0x2e960
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x2250a(%rip), %rcx     # 0x2e8a8
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 -0x38(%rbp), %rdi
callq 0x17070
jmp 0xc559
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x17a18
testq %r15, %r15
je 0xc6a2
movq (%r15), %rax
movq -0x8(%rax), %rsi
leaq 0x228ab(%rip), %rdi     # 0x2ec98
callq 0x76ba
testb %al, %al
jne 0xc702
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r12
leaq 0x22624(%rip), %rsi     # 0x2ea30
leaq 0x22885(%rip), %rdx     # 0x2ec98
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x227bc(%rip), %rcx     # 0x2ebe0
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 -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0xc559
leaq -0x38(%rbp), %rdi
pushq $0x61
popq %rsi
callq 0x17c08
testq %r15, %r15
je 0xc6ac
movq (%r15), %rax
movq -0x8(%rax), %rsi
leaq 0x228f4(%rip), %rdi     # 0x2ed68
callq 0x76ba
testb %al, %al
jne 0xc74e
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r12
leaq 0x2259d(%rip), %rsi     # 0x2ea30
leaq 0x228ce(%rip), %rdx     # 0x2ed68
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x22805(%rip), %rcx     # 0x2ecb0
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 -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0xc559
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x175ac
testq %r15, %r15
je 0xc6b1
movq (%r15), %rax
movq -0x8(%rax), %rsi
leaq 0x225fe(%rip), %rdi     # 0x2eaf8
callq 0x76ba
testb %al, %al
jne 0xc7e3
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r12
leaq 0x22517(%rip), %rsi     # 0x2ea30
leaq 0x225d8(%rip), %rdx     # 0x2eaf8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6230
leaq 0x2250f(%rip), %rcx     # 0x2ea40
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 -0x38(%rbp), %rdi
callq 0x175d0
testq %r14, %r14
je 0xc566
movq %r14, %rdi
callq 0x17070
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x61e0
leaq 0x12ff7(%rip), %rsi     # 0x1f56f
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x72a6
addq $0x78, %rbx
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0x1925e
leaq -0x58(%rbp), %rdi
callq 0x60d0
leaq -0x68(%rbp), %rdi
callq 0x17070
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x6220
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12dfa(%rip), %rsi     # 0x1f3c5
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x21497(%rip), %rsi     # 0x2da88
leaq 0xb722(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xc82a
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12ded(%rip), %rsi     # 0x1f404
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x2144b(%rip), %rsi     # 0x2da88
leaq 0xb6d6(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xc82a
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12dc8(%rip), %rsi     # 0x1f42b
leaq -0x58(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x213ff(%rip), %rsi     # 0x2da88
leaq 0xb68a(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xc82a
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12e6e(%rip), %rsi     # 0x1f536
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x2139a(%rip), %rsi     # 0x2da88
leaq 0xb625(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xc82a
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12dae(%rip), %rsi     # 0x1f4c2
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x2134e(%rip), %rsi     # 0x2da88
leaq 0xb5d9(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xc82a
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12d9b(%rip), %rsi     # 0x1f4fb
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x21302(%rip), %rsi     # 0x2da88
leaq 0xb58d(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xc82a
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12ce0(%rip), %rsi     # 0x1f48c
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x212b6(%rip), %rsi     # 0x2da88
leaq 0xb541(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0xc82a
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0x12c5e(%rip), %rsi     # 0x1f453
leaq -0x58(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x2126d(%rip), %rsi     # 0x2da88
leaq 0xb4f8(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xc859
jmp 0xc900
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xc869
jmp 0xc90e
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xc900
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xc90e
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xc88f
jmp 0xc91c
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xc91c
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xc8b2
jmp 0xc92a
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xc92a
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xc8d2
jmp 0xc938
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xc938
jmp 0xc975
jmp 0xc975
jmp 0xc975
jmp 0xc975
jmp 0xc975
jmp 0xc943
jmp 0xc943
jmp 0xc956
jmp 0xc956
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x175d0
jmp 0xc978
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17802
jmp 0xc978
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0xc978
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0xc978
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17070
jmp 0xc978
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0xc959
jmp 0xc978
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0xc978
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x60d0
jmp 0xc978
jmp 0xc975
jmp 0xc975
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x17070
movq %rbx, %rdi
callq 0x63f0
nop