// File: Nallantli[P]Rossa/main/rossa/symbol/symbol.cpp
// Function: symbol_t::getFunction(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
const ptr_function_t symbol_t::getFunction(const std::vector<symbol_t> &params, const token_t *token, trace_t &stack_trace) const
{
	if (d->type != value_type_enum::FUNCTION)
	{
		throw rossa_error_t(_NOT_FUNCTION_, *token, stack_trace);
	}

	const auto it = std::get<wrapper_t>(d->value).map.find(params.size());
	if (it == std::get<wrapper_t>(d->value).map.end())
	{
		if (std::get<wrapper_t>(d->value).varg != nullptr)
		{
			return std::get<wrapper_t>(d->value).varg;
		}
		throw rossa_error_t(_FUNCTION_ARG_SIZE_FAILURE_, *token, stack_trace);
	}

	ptr_function_t f = nullptr;
	size_t cur_v = 0;
	for (auto &f2 : it->second)
	{
		size_t v = f2.first.validity(params, stack_trace);
		if (v > cur_v)
		{
			cur_v = v;
			f = f2.second;
			if (v == params.size() * 3)
			{
				break;
			}
		}
	}

	if (f == nullptr)
	{
		if (std::get<wrapper_t>(d->value).varg != nullptr)
		{
			return std::get<wrapper_t>(d->value).varg;
		}
		throw rossa_error_t(_FUNCTION_VALUE_NOT_EXIST_, *token, stack_trace);
	}

	return f;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x128(%rbp)
movq %rdi, %rax
movq %rax, -0x120(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x118(%rbp)
movq (%rax), %rax
cmpl $-0x6, (%rax)
je 0x88a27
movb $0x1, -0x5d(%rbp)
movl $0xa8, %edi
callq 0x112b0
movq %rax, -0x138(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x119d0
movq -0x130(%rbp), %rdx
leaq 0xc9740(%rip), %rsi     # 0x1520da
leaq -0x48(%rbp), %rdi
callq 0x24740
jmp 0x889a5
movq -0x138(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x48(%rbp), %rsi
callq 0x9c360
jmp 0x889bf
movq -0x138(%rbp), %rdi
movb $0x0, -0x5d(%rbp)
leaq 0x1582af(%rip), %rsi    # 0x1e0c80
leaq -0x2e038(%rip), %rdx    # 0x5a9a0
callq 0x11970
jmp 0x88eb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x88a05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x11360
leaq -0x49(%rbp), %rdi
callq 0x11600
testb $0x1, -0x5d(%rbp)
jne 0x88a16
jmp 0x88a22
movq -0x138(%rbp), %rdi
callq 0x11420
jmp 0x88eab
movq -0x118(%rbp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
callq 0x8bdb0
movq %rax, -0x140(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30a90
movq -0x140(%rbp), %rdi
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rsi
callq 0x844b0
movq %rax, %rcx
movq -0x118(%rbp), %rax
movq %rcx, -0x68(%rbp)
movq (%rax), %rdi
addq $0x8, %rdi
callq 0x8bdb0
movq %rax, %rdi
callq 0x84510
movq %rax, -0x78(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x844e0
testb $0x1, %al
jne 0x88a9a
jmp 0x88bc6
movq -0x118(%rbp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
callq 0x8bdb0
movq %rax, %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8bdd0
testb $0x1, %al
jne 0x88ac3
jmp 0x88aee
movq -0x118(%rbp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
callq 0x8bdb0
movq -0x128(%rbp), %rdi
movq %rax, %rsi
addq $0x30, %rsi
callq 0x85e40
jmp 0x88e9b
movb $0x1, -0x9a(%rbp)
movl $0xa8, %edi
callq 0x112b0
movq %rax, -0x150(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x119d0
movq -0x148(%rbp), %rdx
leaq 0xc95d3(%rip), %rsi     # 0x1520fa
leaq -0x98(%rbp), %rdi
callq 0x24740
jmp 0x88b35
movq -0x150(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x98(%rbp), %rsi
callq 0x9c360
jmp 0x88b52
movq -0x150(%rbp), %rdi
movb $0x0, -0x9a(%rbp)
leaq 0x158119(%rip), %rsi    # 0x1e0c80
leaq -0x2e1ce(%rip), %rdx    # 0x5a9a0
callq 0x11970
jmp 0x88eb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x88b9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x11360
leaq -0x99(%rbp), %rdi
callq 0x11600
testb $0x1, -0x9a(%rbp)
jne 0x88bb5
jmp 0x88bc1
movq -0x150(%rbp), %rdi
callq 0x11420
jmp 0x88eab
leaq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8be00
movq $0x0, -0xb8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x84540
addq $0x8, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x84560
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x84590
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x845c0
testb $0x1, %al
jne 0x88c37
jmp 0x88cfc
leaq -0xc8(%rbp), %rdi
callq 0x845f0
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x838f0
movq %rax, -0x158(%rbp)
jmp 0x88c67
movq -0x158(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jbe 0x88ce9
movq -0xe0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xd8(%rbp), %rsi
addq $0x18, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x8be20
movq -0xe0(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30a90
movq %rax, %rcx
movq -0x160(%rbp), %rax
imulq $0x3, %rcx, %rcx
cmpq %rcx, %rax
jne 0x88ce7
jmp 0x88cfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x88e8d
jmp 0x88ce9
jmp 0x88ceb
leaq -0xc8(%rbp), %rdi
callq 0x846a0
jmp 0x88c1b
leaq -0xb0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8be50
testb $0x1, %al
jne 0x88d15
jmp 0x88e62
movq -0x118(%rbp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
callq 0x8bdb0
movq %rax, -0x168(%rbp)
jmp 0x88d31
movq -0x168(%rbp), %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8bdd0
testb $0x1, %al
jne 0x88d4b
jmp 0x88d8d
movq -0x118(%rbp), %rax
movq (%rax), %rdi
addq $0x8, %rdi
callq 0x8bdb0
movq %rax, -0x170(%rbp)
jmp 0x88d67
movq -0x128(%rbp), %rdi
movq -0x170(%rbp), %rsi
addq $0x30, %rsi
callq 0x85e40
movl $0x1, -0xe4(%rbp)
jmp 0x88e7f
movb $0x1, -0x10a(%rbp)
movl $0xa8, %edi
callq 0x112b0
movq %rax, -0x180(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x119d0
movq -0x178(%rbp), %rdx
leaq 0xc936c(%rip), %rsi     # 0x152132
leaq -0x108(%rbp), %rdi
callq 0x24740
jmp 0x88dd4
movq -0x180(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x108(%rbp), %rsi
callq 0x9c360
jmp 0x88df1
movq -0x180(%rbp), %rdi
movb $0x0, -0x10a(%rbp)
leaq 0x157e7a(%rip), %rsi    # 0x1e0c80
leaq -0x2e46d(%rip), %rdx    # 0x5a9a0
callq 0x11970
jmp 0x88eb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x88e3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x11360
leaq -0x109(%rbp), %rdi
callq 0x11600
testb $0x1, -0x10a(%rbp)
jne 0x88e54
jmp 0x88e60
movq -0x180(%rbp), %rdi
callq 0x11420
jmp 0x88e8d
movq -0x128(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x8be80
movl $0x1, -0xe4(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x85eb0
jmp 0x88e9b
leaq -0xb0(%rbp), %rdi
callq 0x85eb0
jmp 0x88eab
movq -0x120(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x119c0
nopw %cs:(%rax,%rax)