// File: /workspace/github_cpp_makefile_star2_O1/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 $0x158, %rsp            # imm = 0x158
movq %rdx, 0x10(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x8(%rdi), %rax
cmpq (%rdi), %rax
je 0x3f74e
movq %rdi, %r12
movq 0x8(%rdi), %rax
cmpq (%rdi), %rax
je 0x3f743
leaq 0x50(%rsp), %r15
leaq 0xd0(%rsp), %rbp
movq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
movq %r12, 0x28(%rsp)
movq %rbx, %rsi
shlq $0x4, %rsi
movq 0x30(%rsp), %rax
addq (%rax), %rsi
leaq 0x18(%rsp), %rdi
callq 0x404c8
movq %rbx, 0x80(%rsp)
leaq (%rbx,%rbx,8), %r14
shlq $0x3, %r14
addq (%r12), %r14
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x379e8
leaq 0x18(%r14), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x37a82
movq %r15, %rbx
addq $0x30, %r14
leaq 0xb8(%rsp), %rdi
movq %r14, %rsi
callq 0x37814
leaq 0x110(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x41268
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
callq 0x3e0d2
movq 0x50(%rsp), %r13
movq 0x58(%rsp), %r14
movq %rbx, %rdi
callq 0x3743a
cmpq %r14, %r13
je 0x3f4ce
leaq 0x38(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3e0d2
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x41446
movq %r15, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x3fb5a
movq 0x40(%rsp), %rax
subq 0x38(%rsp), %rax
sarq $0x3, %rax
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
imulq %rcx, %rax
movq 0x60(%rsp), %rdx
leaq 0x58(%rsp), %rdi
movq %rdi, %rcx
testq %rdx, %rdx
je 0x3f3b3
movq %rdi, %rcx
xorl %esi, %esi
cmpq %rax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x3f39b
movq %rdi, %r12
cmpq %rdi, %rcx
je 0x3f3c6
cmpq 0x20(%rcx), %rax
cmovbq %rdi, %rcx
movq %rcx, %r12
cmpq %rdi, %r12
je 0x3f52a
movq 0x40(%r12), %r14
addq $0x30, %r12
xorl %r15d, %r15d
cmpq %r12, %r14
je 0x3f498
leaq 0x20(%r14), %rsi
movq %rbp, %r13
movq %rbp, %rdi
callq 0x3fafc
movq 0x38(%rsp), %rdi
cmpq %rdi, 0x40(%rsp)
je 0x3f45c
xorl %ebx, %ebx
xorl %ebp, %ebp
addq %rbx, %rdi
movq 0xd0(%rsp), %rsi
addq %rbx, %rsi
callq 0x3e312
cmpq $0x3, %rax
setne %cl
cmpq $0x3, %r15
setae %dl
orb %cl, %dl
cmpq %r15, %rax
cmovaq %rax, %r15
testb %dl, %dl
je 0x3f45c
incq %rbp
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
imulq %rcx, %rax
addq $0x48, %rbx
cmpq %rax, %rbp
jb 0x3f403
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
leaq 0x50(%rsp), %rbx
je 0x3f473
callq 0x1e6ee
movq %r13, %rbp
movq %r13, %rdi
callq 0x3743a
cmpq $0x3, %r15
je 0x3f498
movq %r14, %rdi
callq 0x102a0
movq %rax, %r14
cmpq %r12, %rax
jne 0x3f3e4
testq %r15, %r15
movq 0x28(%rsp), %r12
jne 0x3f4c1
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x41532
movl $0x1, %r15d
testb %al, %al
je 0x3f551
addq %r15, 0x8(%rsp)
movb $0x1, %r14b
jmp 0x3f554
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
callq 0x3e0e4
movq %rbp, %rdi
leaq 0x110(%rsp), %rsi
callq 0x3e0e4
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
movq %rax, %rdx
subq %rdi, %rdx
movq 0xd0(%rsp), %r14
movq 0xd8(%rsp), %rcx
subq %r14, %rcx
cmpq %rcx, %rdx
jne 0x3f54d
cmpq %rdi, %rax
je 0x3f577
movq %r14, %rsi
callq 0x10400
testl %eax, %eax
sete %bl
jmp 0x3f579
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x41532
movl %eax, %r14d
movzbl %al, %eax
addq %rax, 0x8(%rsp)
movq 0x28(%rsp), %r12
jmp 0x3f554
xorl %ebx, %ebx
jmp 0x3f579
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x40026
leaq 0x38(%rsp), %rdi
callq 0x3743a
testb %r14b, %r14b
jne 0x3f634
xorl %r14d, %r14d
jmp 0x3f63f
movb $0x1, %bl
testq %r14, %r14
je 0x3f591
movq 0xe0(%rsp), %rsi
subq %r14, %rsi
movq %r14, %rdi
callq 0x103d0
testb %bl, %bl
je 0x3f59d
addq $0x3, 0x8(%rsp)
jmp 0x3f614
movq 0x50(%rsp), %rax
movq (%rax), %r14
testq %r14, %r14
jle 0x3f5d0
leaq 0xf8(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x3e0e4
movq 0xf8(%rsp), %rax
cmpq $-0x1, (%rax)
sete %bl
jmp 0x3f5d2
xorl %ebx, %ebx
testq %r14, %r14
jle 0x3f5f4
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0x3f5f4
movq 0x108(%rsp), %rsi
subq %rdi, %rsi
callq 0x103d0
testb %bl, %bl
je 0x3f600
addq $0x2, 0x8(%rsp)
jmp 0x3f614
movq 0x50(%rsp), %rax
cmpq $-0xb, (%rax)
jne 0x3f6f4
incq 0x8(%rsp)
movb $0x1, %bl
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3f62d
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x103d0
testb %bl, %bl
je 0x3f639
movq %r15, %rbx
movb $0x1, %r14b
jmp 0x3f63f
xorl %r14d, %r14d
movq %r15, %rbx
leaq 0x140(%rsp), %rdi
callq 0x3743a
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x3f669
movq 0x138(%rsp), %rsi
subq %rdi, %rsi
callq 0x103d0
leaq 0x110(%rsp), %rdi
callq 0x3729c
leaq 0xb8(%rsp), %rdi
callq 0x3743a
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x3f6a0
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x103d0
leaq 0x88(%rsp), %rdi
callq 0x3729c
leaq 0x18(%rsp), %rdi
callq 0x404da
testb %r14b, %r14b
je 0x3f743
movq %rbx, %r15
movq 0x8(%r12), %rax
subq (%r12), %rax
movq 0x80(%rsp), %rbx
incq %rbx
sarq $0x3, %rax
movabsq $-0x71c71c71c71c71c7, %rcx # imm = 0x8E38E38E38E38E39
imulq %rcx, %rax
cmpq %rax, %rbx
jb 0x3f297
jmp 0x3f758
movq 0x30(%rsp), %rax
movq (%rax), %rdi
callq 0x41262
cmpl $-0x8, %eax
jne 0x3f73c
movq 0x50(%rsp), %rax
cmpq $-0x8, (%rax)
je 0x3f5f8
movq %r15, %rbx
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x411a4
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3d51a
testb %al, %al
jne 0x3f5f8
xorl %ebx, %ebx
jmp 0x3f616
movq $0x0, 0x8(%rsp)
jmp 0x3f758
movl $0x1, %eax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3f779
jmp 0x3f779
jmp 0x3f7e3
jmp 0x3f7e3
jmp 0x3f7a5
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3f80c
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x103d0
jmp 0x3f80c
jmp 0x3f7a5
movq %rax, %rbx
jmp 0x3f819
movq %rax, %rbx
jmp 0x3f7ca
movq %rax, %rbx
jmp 0x3f80c
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x3f7ca
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x103d0
leaq 0x88(%rsp), %rdi
callq 0x3729c
jmp 0x3f826
movq %rax, %rbx
jmp 0x3f826
movq %rax, %rbx
jmp 0x3f802
movq %rax, %rbx
jmp 0x3f7f8
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x3fb3e
leaq 0x50(%rsp), %rdi
callq 0x40026
leaq 0x38(%rsp), %rdi
callq 0x3743a
leaq 0x110(%rsp), %rdi
callq 0x37330
leaq 0x88(%rsp), %rdi
callq 0x37330
leaq 0x18(%rsp), %rdi
callq 0x404da
movq %rbx, %rdi
callq 0x106f0