// File: /workspace/github_cpp_makefile_star2_O3/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 0x1a104
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r13
testq %r13, %r13
je 0xd7c7
movq (%r13), %r14
movq -0x8(%r14), %rax
leaq 0x2665b(%rip), %rcx     # 0x33960
movq 0x8(%rcx), %r12
movq 0x8(%rax), %rsi
cmpq %rsi, %r12
je 0xd32d
cmpb $0x2a, (%r12)
je 0xd76e
movq %r12, %rdi
callq 0x6310
testl %eax, %eax
jne 0xd76e
leaq 0x266fc(%rip), %rsi     # 0x33a30
leaq 0x26625(%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 0xd398
callq *%rcx
cmpl 0xb8(%rbx), %eax
jl 0xd7cc
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 0xd3ba
callq *%rcx
movslq 0xb4(%rbx), %rcx
cmpl %ecx, %eax
jg 0xd825
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 0xd6f4
cltq
movq (%r14), %rdx
movq (%rdx,%rax,8), %r15
leaq 0x16fd4(%rip), %rax     # 0x243ac
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq -0x58(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x1abfc
testq %r15, %r15
je 0xda42
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x267c4(%rip), %rcx     # 0x33bc8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd427
cmpb $0x2a, (%rdi)
je 0xd989
callq 0x6310
testl %eax, %eax
jne 0xd989
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x265f5(%rip), %rsi     # 0x33a30
leaq 0x26786(%rip), %rdx     # 0x33bc8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x266bd(%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 0x1ac2a
jmp 0xd6f4
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x1a104
testq %r15, %r15
je 0xda33
movq (%r15), %rax
movq -0x8(%rax), %rax
movq 0x8(%rax), %rsi
cmpq %rsi, %r12
je 0xd4c3
cmpb $0x2a, (%r12)
je 0xd87e
movq %r12, %rdi
callq 0x6310
testl %eax, %eax
jne 0xd87e
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x26559(%rip), %rsi     # 0x33a30
leaq 0x26482(%rip), %rdx     # 0x33960
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x263b9(%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 0x1a128
jmp 0xd6f4
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x1ae40
testq %r15, %r15
je 0xda38
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x2675a(%rip), %rcx     # 0x33c98
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd561
cmpb $0x2a, (%rdi)
je 0xd8d7
callq 0x6310
testl %eax, %eax
jne 0xd8d7
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x264bb(%rip), %rsi     # 0x33a30
leaq 0x2671c(%rip), %rdx     # 0x33c98
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x26653(%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 0x1ae64
jmp 0xd6f4
leaq -0x58(%rbp), %rdi
movl $0x61, %esi
callq 0x1b03c
testq %r15, %r15
je 0xda3d
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x26789(%rip), %rcx     # 0x33d68
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd602
cmpb $0x2a, (%rdi)
je 0xd930
callq 0x6310
testl %eax, %eax
jne 0xd930
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x2641a(%rip), %rsi     # 0x33a30
leaq 0x2674b(%rip), %rdx     # 0x33d68
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x26682(%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 0x1b060
jmp 0xd6f4
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x1a9d4
testq %r15, %r15
je 0xda47
movq (%r15), %rax
movq -0x8(%rax), %rax
leaq 0x2647b(%rip), %rcx     # 0x33af8
movq 0x8(%rcx), %rdi
movq 0x8(%rax), %rsi
cmpq %rsi, %rdi
je 0xd6a0
cmpb $0x2a, (%rdi)
je 0xd9df
callq 0x6310
testl %eax, %eax
jne 0xd9df
movl $0x10, %edi
callq 0x6200
movq %rax, %r12
leaq 0x2637c(%rip), %rsi     # 0x33a30
leaq 0x2643d(%rip), %rdx     # 0x33af8
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x6260
leaq 0x26374(%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 0x1a9f8
movq -0x60(%rbp), %r14
testq %r14, %r14
je 0xd705
movq %r14, %rdi
callq 0x1a128
movl $0x10, %esi
movq %r14, %rdi
callq 0x6210
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x16e4e(%rip), %rsi     # 0x2456f
leaq 0x16e4a(%rip), %rdx     # 0x24572
leaq -0x48(%rbp), %rdi
callq 0x746c
addq $0x78, %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x1cbc8
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0xd756
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
leaq -0x70(%rbp), %rdi
callq 0x1a128
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), %r15
movq %r15, -0x10(%r15)
leaq 0x16c3b(%rip), %rsi     # 0x243c5
leaq 0x16c72(%rip), %rdx     # 0x24403
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x252d5(%rip), %rsi     # 0x32a88
leaq 0xd9b0(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xda33
callq 0x6250
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x16c1c(%rip), %rsi     # 0x24404
leaq 0x16c3b(%rip), %rdx     # 0x2442a
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x25277(%rip), %rsi     # 0x32a88
leaq 0xd952(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xda33
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x16bea(%rip), %rsi     # 0x2442b
leaq 0x16c0a(%rip), %rdx     # 0x24452
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x2521e(%rip), %rsi     # 0x32a88
leaq 0xd8f9(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xda33
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x16c9c(%rip), %rsi     # 0x24536
leaq 0x16ccd(%rip), %rdx     # 0x2456e
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x251c5(%rip), %rsi     # 0x32a88
leaq 0xd8a0(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xda33
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x16bcf(%rip), %rsi     # 0x244c2
leaq 0x16c00(%rip), %rdx     # 0x244fa
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x2516c(%rip), %rsi     # 0x32a88
leaq 0xd847(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xda33
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x16baf(%rip), %rsi     # 0x244fb
leaq 0x16be2(%rip), %rdx     # 0x24535
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x25113(%rip), %rsi     # 0x32a88
leaq 0xd7ee(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xda33
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x16ae7(%rip), %rsi     # 0x2448c
leaq 0x16b15(%rip), %rdx     # 0x244c1
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x250ba(%rip), %rsi     # 0x32a88
leaq 0xd795(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
jmp 0xda33
movl $0x20, %edi
callq 0x6100
movq %rax, %r14
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x16a58(%rip), %rsi     # 0x24453
leaq 0x16a89(%rip), %rdx     # 0x2448b
leaq -0x48(%rbp), %rdi
callq 0x746c
movb $0x1, %r12b
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x1b14c
xorl %r12d, %r12d
leaq 0x25064(%rip), %rsi     # 0x32a88
leaq 0xd73f(%rip), %rdx      # 0x1b16a
movq %r14, %rdi
callq 0x63e0
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
callq 0x6250
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0xda64
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xda71
jmp 0xdb61
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xdb61
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0xda96
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xdaa3
jmp 0xdb72
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xdb72
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0xdac8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xdad5
jmp 0xdb80
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xdb80
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0xdafa
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xdb07
jmp 0xdb8e
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xdb8e
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0xdb29
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xdb33
jmp 0xdb9c
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xdb9c
jmp 0xdbf1
jmp 0xdbf1
jmp 0xdbf1
jmp 0xdbf1
jmp 0xdbf1
jmp 0xdba7
jmp 0xdba7
jmp 0xdbc6
jmp 0xdbc6
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1a9f8
jmp 0xdbf4
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1ac2a
jmp 0xdbf4
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1b060
jmp 0xdbf4
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1ae64
jmp 0xdbf4
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x1a128
jmp 0xdbf4
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0xdbbf
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
testb %r12b, %r12b
jne 0xdbc9
jmp 0xdbf4
movq %rax, %rbx
movq %r14, %rdi
callq 0x6170
jmp 0xdbf4
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0xdbf4
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x6210
jmp 0xdbf4
jmp 0xdbf1
jmp 0xdbf1
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x1a128
movq %rbx, %rdi
callq 0x6410
nop