// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq %rcx, %r15
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %rbx
testq %rcx, %rcx
je 0x225d5
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x1f71a
jmp 0x22601
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, 0x70(%rdi)
movaps %xmm0, 0x60(%rdi)
movaps %xmm0, 0x50(%rdi)
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0x22a5a
movq (%r12), %rdx
leaq 0xb8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x22a8c
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x22b02
leaq 0xb8(%rsp), %rdi
callq 0x1def2
leaq 0x30(%rsp), %rdi
callq 0x1df38
movq (%r12), %rax
cmpb $0x1, 0x78(%rax)
jne 0x22661
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x2286d
jmp 0x227ec
movq %r14, 0x18(%rsp)
movq 0x18(%rax), %rsi
leaq 0x30(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
callq 0x3618c
leaq 0x8(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x36228
movq %rbx, 0x20(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movq %r12, %r13
movq (%r12), %r12
movq 0x20(%r12), %rax
movq 0x28(%r12), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
cmpq %rcx, %r14
jae 0x22716
leaq (%rax,%rbx), %rsi
addq $0x8, %rsi
cmpb $0x1, -0x8(%rsi)
jne 0x226e6
movq (%rbp), %rdx
addq %rbx, %rdx
leaq 0x30(%rsp), %rdi
movq %r15, %rcx
callq 0x366fc
movq %r13, %r12
jmp 0x2270d
leaq 0x30(%rsp), %rdi
movq %r15, %rdx
callq 0x366f4
movq %r13, %r12
movq (%rbp), %rsi
addq %rbx, %rsi
movq %rax, %rdi
movq %r15, %rdx
movq 0x18(%rsp), %rcx
callq 0x3927a
incq %r14
addq $0x10, %rbx
jmp 0x226a2
movq 0x60(%r12), %rbp
addq $0x50, %r12
leaq 0x30(%rsp), %rbx
cmpq %r12, %rbp
je 0x22749
leaq 0x20(%rbp), %rsi
leaq 0x28(%rbp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x366fc
movq %rbp, %rdi
callq 0x104a0
movq %rax, %rbp
jmp 0x22724
movq (%r13), %rax
movq 0x38(%rax), %rsi
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq 0x18(%rsp), %r14
movq %r14, %rcx
callq *(%rax)
leaq 0x8(%rsp), %rdi
callq 0x39682
movq 0x20(%rsp), %rbx
cmpl $0x4, %eax
jne 0x227a8
leaq 0x2c(%rsp), %rsi
movl $0x3, (%rsi)
leaq 0x8(%rsp), %rdi
callq 0x39686
movq %r14, %rdi
callq 0x22ac6
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x390f0
jmp 0x227cb
movq %rbx, %rdi
callq 0x38d00
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x3927a
movq %r14, %rdi
callq 0x22ac6
leaq 0x8(%rsp), %rdi
callq 0x39102
leaq 0x30(%rsp), %rdi
callq 0x363f2
leaq 0xb8(%rsp), %rdi
callq 0x363f2
movq %rbx, %rax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0x39102
jmp 0x2281a
jmp 0x22817
jmp 0x2284b
movq %rax, %r14
jmp 0x22858
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x39102
jmp 0x2284e
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x1def2
jmp 0x2283b
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x1df38
jmp 0x22865
jmp 0x2284b
jmp 0x2284b
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x363f2
leaq 0xb8(%rsp), %rdi
callq 0x363f2
movq %r14, %rdi
callq 0x106f0