// File: Nallantli[P]Rossa/main/rossa/instruction/instruction.cpp
// Function: SwitchI::evaluate(object_t const*, std::vector<std::pair<token_t, function_t>, std::allocator<std::pair<token_t, function_t>>>&) const
const symbol_t SwitchI::evaluate(const object_t *scope, trace_t &stack_trace) const
{
	const object_t newScope(scope, 0);
	const symbol_t eval = switchs->evaluate(&newScope, stack_trace);
	size_t index = 0;
	const auto it = cases_solved.find(eval);
	if (it != cases_solved.end())
	{
		index = it->second;
	}
	else if (!cases_unsolved.empty())
	{
		for (auto &&e : cases_unsolved)
		{
			const symbol_t evalE = e.first->evaluate(&newScope, stack_trace);
			if (evalE.equals(&eval, &token, stack_trace))
			{
				index = e.second;
				break;
			}
		}
	}

	if (index > 0)
	{
		return cases[index - 1]->evaluate(&newScope, stack_trace);
	}
	else if (elses)
	{
		return elses->evaluate(&newScope, stack_trace);
	}

	return symbol_t();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0xc8(%rbp)
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rsi
movq $0x0, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
leaq -0x38(%rbp), %rdx
callq 0x7d4e0
movq -0xb8(%rbp), %rdi
addq $0x90, %rdi
callq 0x2d300
movq -0xb0(%rbp), %rdx
movq %rax, %rsi
movq -0x20(%rbp), %rcx
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x48(%rbp), %rdi
callq *%rax
jmp 0x132016
movq -0xb8(%rbp), %rdi
movq $0x0, -0x60(%rbp)
addq $0xa0, %rdi
leaq -0x48(%rbp), %rsi
callq 0x136c20
movq %rax, -0xd0(%rbp)
jmp 0x13203e
movq -0xb8(%rbp), %rdi
movq -0xd0(%rbp), %rax
movq %rax, -0x68(%rbp)
addq $0xa0, %rdi
callq 0x136c80
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x136c50
testb $0x1, %al
jne 0x132073
jmp 0x1320ab
leaq -0x68(%rbp), %rdi
callq 0x136cb0
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x1321e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1322d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1322c9
movq -0xb8(%rbp), %rdi
addq $0xd0, %rdi
callq 0x136cd0
testb $0x1, %al
jne 0x1321e6
movq -0xb8(%rbp), %rax
addq $0xd0, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0x136cf0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
callq 0x136d20
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x136d50
testb $0x1, %al
jne 0x13210d
jmp 0x1321e4
leaq -0x80(%rbp), %rdi
callq 0x136d80
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x2d300
movq %rax, %rsi
movq -0x20(%rbp), %rcx
movq (%rsi), %rax
movq (%rax), %rax
leaq -0xa0(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq *%rax
jmp 0x132145
movq -0xb8(%rbp), %rdx
addq $0x8, %rdx
movq -0x20(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x8ace0
movb %al, -0xd1(%rbp)
jmp 0x13216c
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x132178
jmp 0x1321b0
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x2, -0xa4(%rbp)
jmp 0x1321ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x86dc0
jmp 0x1322c9
movl $0x0, -0xa4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x86dc0
movl -0xa4(%rbp), %eax
testl %eax, %eax
je 0x1321d4
jmp 0x1321d2
jmp 0x1321e4
jmp 0x1321d6
leaq -0x80(%rbp), %rdi
callq 0x136db0
jmp 0x1320f4
jmp 0x1321e6
jmp 0x1321e8
cmpq $0x0, -0x60(%rbp)
jbe 0x132239
movq -0xb8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movq -0x60(%rbp), %rsi
decq %rsi
callq 0x136de0
movq %rax, %rdi
callq 0x2d300
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rcx
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x30(%rbp), %rdx
callq *%rax
jmp 0x13222d
movl $0x1, -0xa4(%rbp)
jmp 0x1322a7
movq -0xb8(%rbp), %rdi
addq $0x118, %rdi            # imm = 0x118
callq 0x136880
testb $0x1, %al
jne 0x132252
jmp 0x13228d
movq -0xb8(%rbp), %rdi
addq $0x118, %rdi            # imm = 0x118
callq 0x2d300
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rcx
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x30(%rbp), %rdx
callq *%rax
jmp 0x132281
movl $0x1, -0xa4(%rbp)
jmp 0x1322a7
jmp 0x13228f
movq -0xc8(%rbp), %rdi
callq 0x86580
jmp 0x13229d
movl $0x1, -0xa4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x86dc0
leaq -0x30(%rbp), %rdi
callq 0x7d790
movq -0xc0(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x86dc0
leaq -0x30(%rbp), %rdi
callq 0x7d790
movq -0x50(%rbp), %rdi
callq 0x119c0
nopw %cs:(%rax,%rax)