// File: 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
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x250(%rbp)
movq %rdi, %rax
movq %rax, -0x248(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x240(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x37a93
leaq -0x1a8(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x112e0
leaq -0x1a8(%rbp), %rdi
callq 0x38360
jmp 0x37aa3
movq -0x20(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x2ee00
movq -0x10(%rbp), %rdi
callq 0x383b0
movq %rax, %rdx
leaq -0x128(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x383d0
jmp 0x37ac4
movq -0x240(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x38330
jmp 0x37ad9
leaq -0x128(%rbp), %rdi
callq 0x2a400
leaq -0x1a8(%rbp), %rdi
callq 0x2a480
movq -0x10(%rbp), %rdi
callq 0x38430
testb $0x1, 0x78(%rax)
je 0x37b64
movq -0x250(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x37f80
jmp 0x37f61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x37b53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x2a400
leaq -0x1a8(%rbp), %rdi
callq 0x2a480
jmp 0x37f71
movq -0x10(%rbp), %rdi
callq 0x38430
movq 0x18(%rax), %rsi
movl $0x0, -0x1cc(%rbp)
leaq -0x1c8(%rbp), %rdi
movq %rdi, -0x258(%rbp)
leaq -0x1cc(%rbp), %rdx
callq 0x7d3b0
movq -0x258(%rbp), %rsi
movq $0x0, -0x1e8(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rdx
callq 0x7d4e0
jmp 0x37bbc
movq $0x0, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x10(%rbp), %rdi
callq 0x38430
movq %rax, %rdi
addq $0x20, %rdi
callq 0x2f160
movq %rax, %rcx
movq -0x260(%rbp), %rax
cmpq %rcx, %rax
jae 0x37d44
movq -0x10(%rbp), %rdi
callq 0x38430
movq %rax, %rdi
addq $0x20, %rdi
movq -0x1f0(%rbp), %rsi
callq 0x38450
testb $0x1, (%rax)
je 0x37ca8
movq -0x10(%rbp), %rdi
callq 0x38430
movq %rax, %rdi
addq $0x20, %rdi
movq -0x1f0(%rbp), %rsi
callq 0x38450
addq $0x8, %rax
movq %rax, -0x268(%rbp)
movq -0x18(%rbp), %rdi
movq -0x1f0(%rbp), %rsi
callq 0x24e40
movq -0x268(%rbp), %rsi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
leaq -0x1e0(%rbp), %rdi
callq 0x7de40
jmp 0x37c75
jmp 0x37d2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x37f53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x37f47
movq -0x10(%rbp), %rdi
callq 0x38430
movq %rax, %rdi
addq $0x20, %rdi
movq -0x1f0(%rbp), %rsi
callq 0x38450
movq %rax, %rsi
addq $0x8, %rsi
movq -0x20(%rbp), %rdx
leaq -0x1e0(%rbp), %rdi
callq 0x7de10
movq %rax, -0x270(%rbp)
jmp 0x37ce4
movq -0x270(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x18(%rbp), %rdi
movq -0x1f0(%rbp), %rsi
callq 0x24e40
movq -0x278(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x870e0
jmp 0x37d29
jmp 0x37d2b
jmp 0x37d2d
movq -0x1f0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1f0(%rbp)
jmp 0x37bc7
movq -0x10(%rbp), %rdi
callq 0x38430
addq $0x48, %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rdi
callq 0x38470
movq %rax, -0x208(%rbp)
movq -0x200(%rbp), %rdi
callq 0x384a0
movq %rax, -0x210(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x384d0
testb $0x1, %al
jne 0x37d97
jmp 0x37dda
leaq -0x208(%rbp), %rdi
callq 0x38500
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rsi
movq %rsi, %rdx
addq $0x8, %rdx
movq -0x20(%rbp), %rcx
leaq -0x1e0(%rbp), %rdi
callq 0x7de40
jmp 0x37dca
jmp 0x37dcc
leaq -0x208(%rbp), %rdi
callq 0x38530
jmp 0x37d7e
movq -0x10(%rbp), %rdi
callq 0x38430
movq %rax, %rdi
addq $0x38, %rdi
callq 0x2d300
movq %rax, %rsi
movq -0x28(%rbp), %rcx
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x228(%rbp), %rdi
leaq -0x1e0(%rbp), %rdx
callq *%rax
jmp 0x37e0e
leaq -0x228(%rbp), %rdi
callq 0x879c0
movl %eax, -0x27c(%rbp)
jmp 0x37e22
movl -0x27c(%rbp), %eax
cmpl $0x4, %eax
jne 0x37e90
movl $0x3, -0x22c(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x22c(%rbp), %rsi
callq 0x879e0
jmp 0x37e4c
movq -0x28(%rbp), %rdi
callq 0x2d8f0
movq -0x250(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x86d80
jmp 0x37e6a
movl $0x1, -0x230(%rbp)
jmp 0x37f15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x37f3b
movq -0x250(%rbp), %rdi
movb $0x0, -0x231(%rbp)
callq 0x86580
jmp 0x37ea5
movq -0x250(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x228(%rbp), %rsi
callq 0x870e0
jmp 0x37ec2
movq -0x28(%rbp), %rdi
callq 0x2d8f0
movb $0x1, -0x231(%rbp)
movl $0x1, -0x230(%rbp)
testb $0x1, -0x231(%rbp)
jne 0x37f13
jmp 0x37f07
movq -0x250(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
callq 0x86dc0
jmp 0x37f3b
movq -0x250(%rbp), %rdi
callq 0x86dc0
jmp 0x37f15
leaq -0x228(%rbp), %rdi
callq 0x86dc0
leaq -0x1e0(%rbp), %rdi
callq 0x7d790
leaq -0x1c8(%rbp), %rdi
callq 0x7d790
jmp 0x37f61
leaq -0x228(%rbp), %rdi
callq 0x86dc0
leaq -0x1e0(%rbp), %rdi
callq 0x7d790
leaq -0x1c8(%rbp), %rdi
callq 0x7d790
jmp 0x37f71
movq -0x248(%rbp), %rax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x1b0(%rbp), %rdi
callq 0x119c0
nopl (%rax)