// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r15
movq %r8, %r14
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, 0x28(%rsp)
movq %rdi, 0x30(%rsp)
movq %r8, %rdi
callq 0x10cf5
movl %eax, %r12d
movq %rbx, 0x18(%rsp)
movl 0x964(%rbx), %ebx
testq %r15, %r15
sete %al
movslq %ebp, %rcx
movq %rcx, 0x20(%rsp)
andb 0x70(%rsp), %al
movb %al, 0x7(%rsp)
movq %r15, 0x8(%rsp)
testl %ebx, %ebx
js 0x103c2
movl %ebx, %eax
imulq $0x18, %rax, %r13
addq 0x18(%rsp), %r13
movq 0x30(%rsp), %r15
movq (%r15), %r15
testq %r15, %r15
je 0x103bb
cmpl %r12d, 0x104(%r15)
jne 0x103af
leaq 0x4(%r15), %rdi
movq %r14, %rsi
callq 0x3210
testl %eax, %eax
jne 0x103af
movl 0x114(%r15), %eax
cmpl (%r13), %eax
jne 0x103af
cmpl $0x4, (%r15)
setne %al
cmpb 0x78(%rsp), %al
je 0x103af
movl 0x110(%r15), %eax
testl %eax, %eax
jne 0x102c4
movq 0x18(%rsp), %rcx
cmpl %ebp, 0x968(%rcx)
je 0x1030f
cmpl %ebp, %eax
jne 0x103af
movq 0x18(%rsp), %rax
movslq 0x968(%rax), %rax
cmpl %ebp, %eax
je 0x1030f
cmpb $0x1, 0x118(%r15)
jne 0x103af
cmpq $0x0, 0x8(%rsp)
jne 0x1030f
movq 0x28(%rsp), %rcx
movq (%rcx,%rax,8), %rax
movq 0x20(%rsp), %rcx
cmpq $0x0, 0x310(%rax,%rcx,8)
je 0x103af
movq 0x108(%r15), %rax
cmpl $0x1a, (%rax)
jne 0x1036a
movb 0x30(%rax), %cl
xorb $0x1, %cl
cmpq $0x0, 0x8(%rsp)
je 0x1037a
testb %cl, %cl
jne 0x1037a
movq 0x38(%rax), %rax
movq 0x108(%rax), %rax
cmpl $0x10, (%rax)
jne 0x103af
movq 0x8(%rsp), %rcx
cmpl $0x10, (%rcx)
jne 0x103af
movq 0x8(%rax), %rax
movq 0x18(%rax), %rdx
movq 0x8(%rcx), %rax
movq 0x18(%rax), %rsi
cmpq %rsi, %rdx
sete %al
movl %eax, %ecx
andb 0x70(%rsp), %cl
cmpq %rsi, %rdx
je 0x1038f
jmp 0x10394
cmpq $0x0, 0x8(%rsp)
jne 0x103af
movb $0x1, %al
movb 0x7(%rsp), %cl
jmp 0x1038f
cmpq $0x0, 0x8(%rsp)
sete %al
andb %cl, %al
movl %eax, %ecx
andb 0x70(%rsp), %cl
cmpb $0x1, %al
jne 0x10394
movq %r15, 0x10(%rsp)
testb %cl, %cl
je 0x103ab
movb $0x1, 0x11a(%r15)
movq %r15, 0x10(%rsp)
testb %al, %al
je 0x103af
jmp 0x103df
testb %al, %al
jne 0x103cb
addq $0x140, %r15            # imm = 0x140
jmp 0x1025d
decl %ebx
jmp 0x10245
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x10(%rsp)
jmp 0x103cb