// File: /workspace/github_cpp_makefile_star2_O2/zerolfx[P]P-Machine/conv.cpp
// Function: Conv::execute(StackMachine*)
void Conv::execute(StackMachine *stack) 
{
	// check if the stack contains at least one entries
	if(stack->fSP < 0)
		throw ExecutionError("instruction conv: requires 1 stackelement to be present.");
	
	int integervalue;
	
	switch(fType1)
	{
		case integer:
		{
			StackInteger p1;

			// check if the uppermost stackentry is of type integer
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
				throw ExecutionError("instruction conv: SP does not point to element of type integer.");
			
			integervalue = stack->fStore[stack->fSP]->getValue();
			
			break;
		}	
		case real:
		{
			StackReal p1;
			// check if the uppermost stackentry is of type real
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
				throw ExecutionError("instruction conv: SP does not point to element of type real.");
			
			double realvalue = stack->fStore[stack->fSP]->getReal();
			delete stack->fStore[stack->fSP];	
			
			switch(fType2)
			{
				case integer:
					stack->fStore[stack->fSP] = new StackInteger(realvalue);
					break;
				case boolean:
					stack->fStore[stack->fSP] = new StackBoolean(realvalue);
					break;
				case character:
					stack->fStore[stack->fSP] = new StackCharacter(realvalue);
					break;
				case address:
					stack->fStore[stack->fSP] = new StackAddress(realvalue);
					break;
				case real:
					stack->fStore[stack->fSP] = new StackReal(realvalue);
					break;
			}

			return;
		}
		case character:
		{
			StackCharacter p1;
			// check if the uppermost stackentry is of type character
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
				throw ExecutionError("instruction conv: SP does not point to element of type character.");
			
			integervalue = stack->fStore[stack->fSP]->getValue();
			
			break;  
		}
		case boolean:
		{
			StackBoolean p1;
			// check if the uppermost stackentry is of type boolean
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
				throw ExecutionError("instruction conv: SP does not point to element of type boolean.");

			integervalue = stack->fStore[stack->fSP]->getBoolean();
			
			break;
		}
		case address:
		{
			StackAddress p1;
			// check if the uppermost stackentry is of type address
			if(typeid(p1) != typeid(*(stack->fStore[stack->fSP])))
				throw ExecutionError("instruction conv: SP does not point to element of type address.");
			
			integervalue = stack->fStore[stack->fSP]->getValue();

			break;
		}
	}
	
	delete stack->fStore[stack->fSP];	
	
	switch(fType2)
	{
		case integer:
			stack->fStore[stack->fSP] = new StackInteger(integervalue);
			break;
		case boolean:
			stack->fStore[stack->fSP] = new StackBoolean(static_cast<bool>(integervalue));
			break;
		case character:
			stack->fStore[stack->fSP] = new StackCharacter(static_cast<char>(integervalue));
			break;
		case address:
			stack->fStore[stack->fSP] = new StackAddress(integervalue);
			break;
		case real:
			stack->fStore[stack->fSP] = new StackReal(integervalue);
			break;
	}
	
	// adding cost of this instruction
	stack->fTime.count("conv");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
cmpl $0x0, 0xb4(%rsi)
js 0x16c59
movq %rsi, %rbx
movq %rdi, %r14
movl 0x8(%rdi), %eax
cmpq $0x4, %rax
ja 0x16ab5
leaq 0xaa4c(%rip), %rcx      # 0x212b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x38(%rbp), %rdi
xorpd %xmm0, %xmm0
callq 0x177d4
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x16caf
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x18328(%rip), %rdi     # 0x2ebc8
callq 0x76ba
testb %al, %al
jne 0x16da2
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movsd %xmm0, -0x40(%rbp)
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r15
testq %r15, %r15
je 0x168e3
movq %r15, %rdi
callq 0x17248
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x61e0
movl 0xc(%r14), %eax
cmpq $0x4, %rax
ja 0x16c4b
leaq 0xa9c1(%rip), %rcx      # 0x212c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
movq %rax, %rdi
movsd -0x40(%rbp), %xmm0
callq 0x177d4
jmp 0x16c3c
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x1704c
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x16ca5
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x18006(%rip), %rdi     # 0x2e960
callq 0x76ba
testb %al, %al
jne 0x16cbe
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, %r15d
leaq -0x38(%rbp), %rdi
callq 0x17070
jmp 0x16ab5
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x17a18
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x16caa
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x182da(%rip), %rdi     # 0x2ec98
callq 0x76ba
testb %al, %al
jne 0x16d0a
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x70(%rax)
movzbl %al, %r15d
leaq -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0x16ab5
leaq -0x38(%rbp), %rdi
pushq $0x61
popq %rsi
callq 0x17c08
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x16cb4
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x18344(%rip), %rdi     # 0x2ed68
callq 0x76ba
testb %al, %al
jne 0x16d56
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, %r15d
leaq -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0x16ab5
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x175ac
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testq %rax, %rax
je 0x16cb9
movq (%rax), %rax
movq -0x8(%rax), %rsi
leaq 0x18073(%rip), %rdi     # 0x2eaf8
callq 0x76ba
testb %al, %al
jne 0x16deb
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
movl %eax, %r15d
leaq -0x38(%rbp), %rdi
callq 0x175d0
jmp 0x16ab5
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %r12
testq %r12, %r12
je 0x16ad1
movq %r12, %rdi
callq 0x17248
pushq $0x8
popq %rsi
movq %r12, %rdi
callq 0x61e0
movl 0xc(%r14), %eax
cmpq $0x4, %rax
ja 0x16b88
leaq 0xa7e7(%rip), %rcx      # 0x212d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
cvtsi2sd %r15d, %xmm0
movq %rax, %rdi
callq 0x177d4
jmp 0x16b79
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
movq %rax, %rdi
movl %r15d, %esi
callq 0x1704c
jmp 0x16b79
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
xorl %esi, %esi
testl %r15d, %r15d
setne %sil
movq %rax, %rdi
callq 0x17a18
jmp 0x16b79
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
movsbl %r15b, %esi
movq %rax, %rdi
callq 0x17c08
jmp 0x16b79
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
movq %rax, %rdi
movl %r15d, %esi
callq 0x175ac
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %r14, (%rcx,%rax,8)
leaq 0xa8db(%rip), %rsi      # 0x2146a
leaq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x72a6
addq $0x78, %rbx
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
callq 0x1925e
leaq -0x60(%rbp), %rdi
callq 0x60d0
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
cvttsd2si -0x40(%rbp), %esi
movq %rax, %rdi
callq 0x1704c
jmp 0x16c3c
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
xorpd %xmm0, %xmm0
movsd -0x40(%rbp), %xmm1
cmpneqsd %xmm0, %xmm1
movq %xmm1, %rsi
andl $0x1, %esi
movq %rax, %rdi
callq 0x17a18
jmp 0x16c3c
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
cvttsd2si -0x40(%rbp), %eax
movsbl %al, %esi
movq %r14, %rdi
callq 0x17c08
jmp 0x16c3c
pushq $0x10
popq %rdi
callq 0x61d0
movq %rax, %r14
cvttsd2si -0x40(%rbp), %esi
movq %rax, %rdi
callq 0x175ac
movslq 0xb4(%rbx), %rax
movq 0x18(%rbx), %rcx
movq %r14, (%rcx,%rax,8)
leaq -0x38(%rbp), %rdi
callq 0x17802
jmp 0x16bb5
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0xa687(%rip), %rsi      # 0x212f2
leaq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x16df7(%rip), %rsi     # 0x2da88
leaq 0x1082(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x16e32
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
callq 0x6220
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0xa75a(%rip), %rsi      # 0x2142a
leaq -0x60(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x16d92(%rip), %rsi     # 0x2da88
leaq 0x101d(%rip), %rdx      # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x16e32
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0xa6ce(%rip), %rsi      # 0x213ea
leaq -0x60(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x16d46(%rip), %rsi     # 0x2da88
leaq 0xfd1(%rip), %rdx       # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x16e32
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0xa640(%rip), %rsi      # 0x213a8
leaq -0x60(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x16cfa(%rip), %rsi     # 0x2da88
leaq 0xf85(%rip), %rdx       # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x16e32
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0xa5b7(%rip), %rsi      # 0x2136b
leaq -0x60(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x16cae(%rip), %rsi     # 0x2da88
leaq 0xf39(%rip), %rdx       # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x16e32
pushq $0x20
popq %rdi
callq 0x60f0
movq %rax, %r14
leaq 0xa52e(%rip), %rsi      # 0x2132b
leaq -0x60(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x72a6
movb $0x1, %r15b
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x17d10
xorl %r15d, %r15d
leaq 0x16c65(%rip), %rsi     # 0x2da88
leaq 0xef0(%rip), %rdx       # 0x17d1a
movq %r14, %rdi
callq 0x63c0
jmp 0x16e3a
jmp 0x16e3a
jmp 0x16e3a
jmp 0x16e3a
movq %rax, %rbx
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x61e0
jmp 0x16f19
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x16e7c
jmp 0x16f27
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x16e8c
jmp 0x16f19
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x16f27
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x16f19
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x16eb2
jmp 0x16f35
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x16f35
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x16ed2
jmp 0x16f43
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x16f43
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x16ef2
jmp 0x16f51
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x16f51
jmp 0x16f04
jmp 0x16f04
jmp 0x16f04
jmp 0x16f04
movq %rax, %rbx
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x61e0
jmp 0x16f8d
jmp 0x16f16
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17802
jmp 0x16f8d
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x175d0
jmp 0x16f8d
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17c2c
jmp 0x16f8d
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17a3c
jmp 0x16f8d
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x17070
jmp 0x16f8d
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60d0
testb %r15b, %r15b
jne 0x16f72
jmp 0x16f8d
movq %rax, %rbx
movq %r14, %rdi
callq 0x6150
jmp 0x16f8d
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60d0
jmp 0x16f8d
movq %rax, %rbx
movq %rbx, %rdi
callq 0x63f0
nop