// File: /workspace/github_cpp_makefile_star2_O3/Nallantli[P]Rossa/main/rossa/function/function.cpp
// Function: function_evaluate(std::shared_ptr<function_t> const&, std::vector<symbol_t, std::allocator<symbol_t>> const&, token_t const*, std::vector<std::pair<token_t, function_t>, std::allocator<std::pair<token_t, function_t>>>&)
const symbol_t function_evaluate(const ptr_function_t &function, const std::vector<symbol_t> &paramValues, const token_t *token, trace_t &stack_trace)
{
	stack_trace.push_back({(token == NULL ? token_t() : *token), *function.get()});
	if (function->isVargs)
		return function_evaluate_vargs(function, paramValues, token, stack_trace);

	object_t p(function->parent, object_type_enum::OBJECT_WEAK);
	const object_t newScope(&p, 0);

	for (size_t i = 0; i < function->params.size(); i++)
	{
		if (function->params[i].first) {
			newScope.createVariable(function->params[i].second, paramValues[i], token);
		} else {
			const symbol_t &temp = newScope.createVariable(function->params[i].second, token);
			temp.set(&paramValues[i], token, stack_trace);
		}
	}

	for (const std::pair<const hash_ull, const symbol_t> &e : function->captures)
	{
		newScope.createVariable(e.first, e.second, token);
	}

	symbol_t temp = function->body->evaluate(&newScope, stack_trace);

	if (temp.getSymbolType() == symbol_t::type_t::ID_REFER)
	{
		temp.setSymbolType(symbol_t::type_t::ID_CASUAL);

		stack_trace.pop_back();
		return temp;
	}

	const symbol_t ret = symbol_t();
	ret.set(&temp, token, stack_trace);

	stack_trace.pop_back();
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %r8, %rbp
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r14
leaq 0x68(%rsp), %rbx
testq %rcx, %rcx
je 0x24923
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x1e566
leaq 0x58(%rsp), %rdi
movq %rbx, (%rdi)
movq 0x28(%r15), %rsi
movq 0x30(%r15), %rdx
addq %rsi, %rdx
callq 0x1ded4
movups 0x48(%r15), %xmm0
leaq 0x88(%rsp), %rdi
movups %xmm0, -0x10(%rdi)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x58(%r15), %rsi
movq 0x60(%r15), %rdx
addq %rsi, %rdx
callq 0x1ded4
movl 0x78(%r15), %eax
movl %eax, 0xa8(%rsp)
jmp 0x24989
xorps %xmm0, %xmm0
movq %rbp, %rbx
leaq 0x30(%rsp), %rbp
movaps %xmm0, 0x70(%rbp)
movaps %xmm0, 0x60(%rbp)
movaps %xmm0, 0x50(%rbp)
movaps %xmm0, 0x40(%rbp)
movaps %xmm0, 0x30(%rbp)
movaps %xmm0, 0x20(%rbp)
movaps %xmm0, 0x10(%rbp)
movaps %xmm0, (%rbp)
movq %rbp, %rdi
callq 0x24fda
leaq 0x68(%rsp), %rax
movq %rax, 0x28(%rbp)
xorl %eax, %eax
movq %rax, 0x30(%rbp)
movb %al, 0x38(%rbp)
movq %rbx, %rbp
leaq 0x68(%rsp), %rbx
leaq 0x98(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl $0x0, 0x10(%rcx)
movq (%r12), %rdx
leaq 0xb8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x24e88
leaq 0xb8(%rsp), %rsi
movq %rbp, %rdi
callq 0x25002
leaq 0xb8(%rsp), %rdi
callq 0x1ebac
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x249dd
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x58(%rsp), %rdi
cmpq %rbx, %rdi
je 0x249f4
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x103d0
leaq 0x30(%rsp), %rdi
callq 0x1d5ee
movq (%r12), %rax
cmpb $0x1, 0x78(%rax)
jne 0x24a21
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %rbp, %r8
callq 0x24c7a
jmp 0x24bce
movq %rbp, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq 0x18(%rax), %rsi
leaq 0x30(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0xb8(%rsp), %rbp
movq %rbp, %rdi
callq 0x3c8bc
leaq 0x8(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x3c968
movq (%r12), %rax
movq 0x20(%rax), %rcx
cmpq %rcx, 0x28(%rax)
je 0x24ade
xorl %ebx, %ebx
leaq 0x30(%rsp), %rbp
xorl %r14d, %r14d
leaq (%rcx,%rbx), %rsi
addq $0x8, %rsi
cmpb $0x1, -0x8(%rsi)
jne 0x24a9d
movq (%r13), %rdx
addq %rbx, %rdx
movq %rbp, %rdi
movq %r15, %rcx
callq 0x3cee2
jmp 0x24abf
movq %rbp, %rdi
movq %r15, %rdx
callq 0x3ceda
movq (%r13), %rsi
addq %rbx, %rsi
movq %rax, %rdi
movq %r15, %rdx
movq 0x18(%rsp), %rcx
callq 0x3ff88
incq %r14
movq (%r12), %rax
movq 0x20(%rax), %rcx
movq 0x28(%rax), %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
addq $0x10, %rbx
cmpq %rdx, %r14
jb 0x24a7b
movq 0x60(%rax), %r13
leaq 0x50(%rax), %rbx
cmpq %rbx, %r13
movq 0x20(%rsp), %r14
je 0x24b1c
leaq 0x30(%rsp), %rbp
leaq 0x20(%r13), %rsi
leaq 0x28(%r13), %rdx
movq %rbp, %rdi
movq %r15, %rcx
callq 0x3cee2
movq %r13, %rdi
callq 0x104b0
movq %rax, %r13
cmpq %rbx, %rax
jne 0x24af5
movq (%r12), %rax
movq 0x38(%rax), %rsi
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rbx
movq %rbx, %rcx
callq *(%rax)
leaq 0x8(%rsp), %rdi
callq 0x4040c
cmpl $0x4, %eax
jne 0x24b7e
leaq 0x2c(%rsp), %rsi
movl $0x3, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x40410
movq $-0x100, %rdi
addq 0x8(%rbx), %rdi
movq %rdi, 0x8(%rbx)
callq 0x1ebac
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3fdf4
jmp 0x24bad
movq %r14, %rdi
callq 0x3f9d0
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x3ff88
movq $-0x100, %rdi
addq 0x8(%rbx), %rdi
movq %rdi, 0x8(%rbx)
callq 0x1ebac
leaq 0x8(%rsp), %rdi
callq 0x3fe06
leaq 0x30(%rsp), %rdi
callq 0x3cb40
leaq 0xb8(%rsp), %rdi
callq 0x3cb40
movq %r14, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rax, %r14
callq 0x3fe06
jmp 0x24c27
jmp 0x24c24
jmp 0x24c58
movq %rax, %r14
jmp 0x24c65
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %rbx, %rdi
je 0x24c18
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x24c18
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x1d5ee
jmp 0x24c72
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x3fe06
jmp 0x24c5b
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x1ebac
jmp 0x24c48
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x2108a
jmp 0x24c72
jmp 0x24c58
jmp 0x24c58
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x3cb40
leaq 0xb8(%rsp), %rdi
callq 0x3cb40
movq %r14, %rdi
callq 0x106f0