// File: /workspace/github_cpp_makefile_star2_O2/Nallantli[P]Rossa/main/rossa/signature/signature.cpp
// Function: signature_t::validity(std::vector<symbol_t, std::allocator<symbol_t>> const&, std::vector<std::pair<token_t, function_t>, std::allocator<std::pair<token_t, function_t>>>&) const
const size_t signature_t::validity(const std::vector<symbol_t> &check, trace_t &stack_trace) const
{
	if (values.size() == 0)
	{
		return 1;
	}

	size_t v = 0;
	for (size_t i = 0; i < values.size(); i++)
	{
		auto check_i = check[i];
		auto values_i = values[i];
		auto vt = check_i.getAugValueType();
		if (values_i.getQualifiers().empty())
		{
			auto base = values_i.getBase();
			if (base == vt.getBase())
			{
				v += 3;
			}
			else if (base[0] > 0 && vt.getBase()[0] == value_type_enum::NIL)
			{
				v += 2;
			}
			else if (base[0] == value_type_enum::ANY)
			{
				v += 1;
			}
			else if (check[0].getValueType() == value_type_enum::OBJECT)
			{
				if (base[0] == value_type_enum::OBJECT || check_i.getObject(NULL, stack_trace)->extendsObject(base))
				{
					v += 2;
				}
				else
				{
					return 0;
				}
			}
			else
			{
				return 0;
			}
		}
		else
		{
			auto ql = values_i.getQualifiers();
			auto fo = check_i.getFunctionOverloads(NULL, stack_trace);
			const auto it = fo.find(ql.size());
			if (it == fo.end())
			{
				if (check_i.hasVarg(NULL, stack_trace))
				{
					v += 1;
				}
				else
				{
					return 0;
				}
			}
			else
			{
				size_t flag = 0;
				for (auto f : it->second)
				{
					for (size_t i = 0; i < ql.size(); i++)
					{
						auto val = ql[i] & f.first.values[i];
						if (val > flag)
						{
							flag = val;
							if (val == 3)
							{
								break;
							}
						}
					}
					if (flag == 3)
					{
						break;
					}
				}
				if (flag > 0)
				{
					v += flag;
				}
				else
				{
					if (check_i.hasVarg(NULL, stack_trace))
					{
						v += 1;
					}
					else
					{
						return 0;
					}
				}
			}
		}
	}
	return v;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdx, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
movq 0x8(%rdi), %rax
cmpq (%rdi), %rax
je 0x3844b
movq %rdi, %r13
pushq $0x48
popq %r12
leaq 0x20(%rsp), %r14
leaq 0x30(%rsp), %rbp
xorl %r15d, %r15d
movq $0x0, (%rsp)
movq %rdi, 0x10(%rsp)
movq 0x8(%r13), %rax
subq (%r13), %rax
cqto
idivq %r12
cmpq %rax, %r15
jae 0x38450
movq %r15, %rsi
shlq $0x4, %rsi
movq 0x18(%rsp), %rax
addq (%rax), %rsi
movq %r14, %rdi
callq 0x390f0
movq %r15, 0x78(%rsp)
imulq $0x48, %r15, %rsi
addq (%r13), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x2f7ea
leaq 0xf0(%rsp), %rdi
movq %r14, %rsi
callq 0x39cac
movq %rbp, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x371c8
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r14
movq %rbp, %rdi
callq 0x2eb6c
cmpq %r14, %rbx
je 0x38293
leaq 0x60(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x371c8
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x39e08
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x386ea
movq 0x68(%rsp), %rax
subq 0x60(%rsp), %rax
cqto
idivq %r12
movq %rax, 0x80(%rsp)
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
callq 0x38c42
movq %rax, %r13
leaq 0x38(%rsp), %rax
cmpq %rax, %r13
je 0x382eb
movq 0x40(%r13), %rbp
addq $0x30, %r13
xorl %r15d, %r15d
cmpq %r13, %rbp
je 0x3830a
leaq 0x20(%rbp), %rsi
leaq 0x80(%rsp), %rdi
callq 0x38690
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rax
subq %rdi, %rax
cqto
idivq %r12
cmpq %rax, %r14
jae 0x38262
addq %rbx, %rdi
movq 0x80(%rsp), %rsi
addq %rbx, %rsi
callq 0x37304
cmpq %r15, %rax
jbe 0x38255
movq %rax, %r15
cmpq $0x3, %rax
je 0x3825e
incq %r14
addq $0x48, %rbx
jmp 0x3821d
pushq $0x3
popq %r15
leaq 0x80(%rsp), %rdi
callq 0x386ba
cmpq $0x3, %r15
leaq 0x20(%rsp), %r14
leaq 0x30(%rsp), %rbx
je 0x3832f
movq %rbp, %rdi
callq 0x102b0
movq %rax, %rbp
jmp 0x381fe
movq %rbp, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x371da
leaq 0x20(%rsp), %r14
movq %rbp, %rbx
leaq 0x80(%rsp), %r15
movq %r15, %rdi
leaq 0xf0(%rsp), %rsi
callq 0x371da
movq %rbx, %rdi
movq %r15, %rsi
callq 0x36dee
movl %eax, %ebp
movq %r15, %rdi
callq 0x2fa2a
testb %bpl, %bpl
je 0x38361
addq $0x3, (%rsp)
jmp 0x383f8
movq %r14, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x39ed8
movl %eax, %ebp
movzbl %al, %eax
addq %rax, (%rsp)
movq 0x10(%rsp), %r13
jmp 0x3833f
testq %r15, %r15
movq 0x10(%rsp), %r13
jne 0x38338
movq %r14, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x39ed8
pushq $0x1
popq %r15
testb %al, %al
jne 0x38338
xorl %ebp, %ebp
jmp 0x3833f
pushq $0x3
popq %r15
movq 0x10(%rsp), %r13
addq %r15, (%rsp)
movb $0x1, %bpl
movq %rbx, %rdi
callq 0x38c2e
leaq 0x60(%rsp), %rdi
callq 0x2eb6c
testb %bpl, %bpl
je 0x3840c
movb $0x1, %bl
jmp 0x3840e
movq 0x30(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
jle 0x383ac
leaq 0x80(%rsp), %r15
movq %r15, %rdi
leaq 0xf0(%rsp), %rsi
callq 0x371da
movq 0x80(%rsp), %rax
movq (%rax), %rbx
movq %r15, %rdi
callq 0x2fa2a
cmpq $-0x1, %rbx
je 0x383f3
movq 0x30(%rsp), %rax
movq (%rax), %rax
leaq 0x30(%rsp), %rbx
cmpq $-0xb, %rax
jne 0x383b8
incq (%rsp)
jmp 0x383f8
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x39ca6
cmpl $-0x8, %eax
jne 0x38447
movq 0x30(%rsp), %rax
cmpq $-0x8, (%rax)
je 0x383f3
movq %r14, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x39c02
movq %rax, %rdi
movq %rbx, %rsi
callq 0x36704
testb %al, %al
je 0x38447
addq $0x2, (%rsp)
movb $0x1, %bl
leaq 0x30(%rsp), %rdi
callq 0x2fa2a
testb %bl, %bl
jne 0x3835a
xorl %ebx, %ebx
leaq 0xf0(%rsp), %rdi
callq 0x2e9f6
leaq 0xa8(%rsp), %rdi
callq 0x2e9f6
movq %r14, %rdi
callq 0x39102
movq 0x78(%rsp), %r15
incq %r15
testb %bl, %bl
leaq 0x30(%rsp), %rbp
jne 0x38103
jmp 0x38456
xorl %ebx, %ebx
jmp 0x383fa
pushq $0x1
popq %rax
jmp 0x38458
movq (%rsp), %rax
jmp 0x38458
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x384ad
jmp 0x38486
jmp 0x38486
jmp 0x384ad
jmp 0x384a3
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2fa2a
jmp 0x38489
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2fa2a
jmp 0x384d6
jmp 0x384ad
jmp 0x384a3
movq %rax, %rbx
jmp 0x384f0
movq %rax, %rbx
jmp 0x384e3
movq %rax, %rbx
jmp 0x384d6
movq %rax, %rbx
jmp 0x384cc
movq %rax, %rbx
jmp 0x384c2
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x386ba
leaq 0x30(%rsp), %rdi
callq 0x38c2e
leaq 0x60(%rsp), %rdi
callq 0x2eb6c
leaq 0xf0(%rsp), %rdi
callq 0x2e9f6
leaq 0xa8(%rsp), %rdi
callq 0x2e9f6
leaq 0x20(%rsp), %rdi
callq 0x39102
movq %rbx, %rdi
callq 0x106f0