// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_ident.c
// Function: identFindEx
static const Ident *identFindEx(const Idents *idents, const Modules *modules, const Blocks *blocks, int module, const char *name, const Type *rcvType, bool markAsUsed, bool isModule)
{
    const unsigned int nameHash = hash(name);

    for (int i = blocks->top; i >= 0; i--)
    {
        for (const Ident *ident = idents->first; ident; ident = ident->next)
            if (ident->hash == nameHash && strcmp(ident->name, name) == 0 && ident->block == blocks->item[i].block && (ident->kind == IDENT_MODULE) == isModule)
            {
                // What we found has correct name and block scope, check module scope
                const bool identModuleValid = (ident->module == 0 && blocks->module == module) ||                                                // Universe module
                                              (ident->module == module && (blocks->module == module ||                                           // Current module
                                              (ident->exported && (rcvType || modules->module[blocks->module]->importAlias[ident->module]))));   // Imported module

                if (identModuleValid)
                {
                    // Method names need not be unique in the given scope - check the receiver type to see if we found the right name
                    const bool methodFound = ident->type->kind == TYPE_FN && ident->type->sig.isMethod;

                    const bool found = (!rcvType && !methodFound) || (rcvType && methodFound && typeCompatibleRcv(ident->type->sig.param[0]->type, rcvType));
                    if (found)
                    {
                        if (markAsUsed)
                            identSetUsed(ident);
                        return ident;
                    }
                }
            }
    }

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %ecx, -0x6c(%rbp)
movq %rdx, %rax
movl -0x6c(%rbp), %edx
movq %rax, -0x68(%rbp)
movq %rsi, %rax
movq -0x68(%rbp), %rsi
movq %rax, -0x60(%rbp)
movq %rdi, %r10
movq -0x60(%rbp), %rdi
movb 0x18(%rbp), %al
movb 0x10(%rbp), %cl
movq %r10, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
andb $0x1, %cl
movb %cl, -0x39(%rbp)
andb $0x1, %al
movb %al, -0x3a(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1a8f0
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movl 0x964(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jl 0x1986b
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x1985b
movq -0x50(%rbp), %rax
movl 0x104(%rax), %eax
cmpl -0x40(%rbp), %eax
jne 0x19845
movq -0x50(%rbp), %rdi
addq $0x4, %rdi
movq -0x30(%rbp), %rsi
callq 0x3220
cmpl $0x0, %eax
jne 0x19845
movq -0x50(%rbp), %rax
movl 0x114(%rax), %eax
movq -0x20(%rbp), %rcx
movslq -0x44(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jne 0x19845
movq -0x50(%rbp), %rax
cmpl $0x4, (%rax)
sete %al
andb $0x1, %al
movzbl %al, %eax
movb -0x3a(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x19845
movq -0x50(%rbp), %rax
cmpl $0x0, 0x110(%rax)
jne 0x196fe
movq -0x20(%rbp), %rax
movl 0x968(%rax), %ecx
movb $0x1, %al
cmpl -0x24(%rbp), %ecx
movb %al, -0x6d(%rbp)
je 0x19789
movq -0x50(%rbp), %rax
movl 0x110(%rax), %ecx
xorl %eax, %eax
cmpl -0x24(%rbp), %ecx
movb %al, -0x6e(%rbp)
jne 0x19783
movq -0x20(%rbp), %rax
movl 0x968(%rax), %ecx
movb $0x1, %al
cmpl -0x24(%rbp), %ecx
movb %al, -0x6f(%rbp)
je 0x1977d
movq -0x50(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x118(%rcx)
movb %al, -0x70(%rbp)
je 0x19777
movb $0x1, %al
cmpq $0x0, -0x38(%rbp)
movb %al, -0x71(%rbp)
jne 0x19771
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq 0x968(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movslq 0x110(%rcx), %rcx
cmpq $0x0, 0x310(%rax,%rcx,8)
setne %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
movb %al, -0x70(%rbp)
movb -0x70(%rbp), %al
movb %al, -0x6f(%rbp)
movb -0x6f(%rbp), %al
movb %al, -0x6e(%rbp)
movb -0x6e(%rbp), %al
movb %al, -0x6d(%rbp)
movb -0x6d(%rbp), %al
andb $0x1, %al
movb %al, -0x51(%rbp)
testb $0x1, -0x51(%rbp)
je 0x19843
movq -0x50(%rbp), %rax
movq 0x108(%rax), %rcx
xorl %eax, %eax
cmpl $0x1a, (%rcx)
movb %al, -0x72(%rbp)
jne 0x197c1
movq -0x50(%rbp), %rax
movq 0x108(%rax), %rax
movb 0x30(%rax), %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
andb $0x1, %al
movb %al, -0x52(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x197db
movb $0x1, %al
testb $0x1, -0x52(%rbp)
movb %al, -0x73(%rbp)
je 0x1981a
xorl %eax, %eax
cmpq $0x0, -0x38(%rbp)
movb %al, -0x74(%rbp)
je 0x19814
xorl %eax, %eax
testb $0x1, -0x52(%rbp)
movb %al, -0x74(%rbp)
je 0x19814
movq -0x50(%rbp), %rax
movq 0x108(%rax), %rax
movq 0x38(%rax), %rax
movq 0x108(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x1a930
movb %al, -0x74(%rbp)
movb -0x74(%rbp), %al
movb %al, -0x73(%rbp)
movb -0x73(%rbp), %al
andb $0x1, %al
movb %al, -0x53(%rbp)
testb $0x1, -0x53(%rbp)
je 0x19841
testb $0x1, -0x39(%rbp)
je 0x19837
movq -0x50(%rbp), %rdi
callq 0x1a6a0
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x19873
jmp 0x19843
jmp 0x19845
jmp 0x19847
movq -0x50(%rbp), %rax
movq 0x140(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x19660
jmp 0x1985d
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1964b
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq