// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_decl.c
// Function: parseImportItem
static void parseImportItem(Compiler *comp)
{
    char *alias = NULL;
    if (comp->lex.tok.kind == TOK_IDENT)
    {
        alias = storageAdd(&comp->storage, DEFAULT_STR_LEN + 1);
        strcpy(alias, comp->lex.tok.name);
        lexNext(&comp->lex);
        lexEat(&comp->lex, TOK_EQ);
    }

    lexCheck(&comp->lex, TOK_STRLITERAL);

    char path[DEFAULT_STR_LEN + 1] = "";

    // Module source strings, if any, have precedence over files
    const char *sourceString = NULL;
    bool sourceTrusted = false;

    if (moduleRegularizePath(&comp->modules, comp->lex.tok.strVal, comp->modules.curFolder, path, DEFAULT_STR_LEN + 1))
    {
        const ModuleSource *sourceDesc = moduleFindSource(&comp->modules, path);
        if (sourceDesc)
        {
            sourceString = sourceDesc->source;
            sourceTrusted = sourceDesc->trusted;
        }
    }

    if (!sourceString)
        moduleAssertRegularizePath(&comp->modules, comp->lex.tok.strVal, comp->modules.module[comp->blocks.module]->folder, path, DEFAULT_STR_LEN + 1);

    char folder[DEFAULT_STR_LEN + 1] = "";
    char name  [DEFAULT_STR_LEN + 1] = "";

    moduleNameFromPath(&comp->modules, path, folder, name, DEFAULT_STR_LEN + 1);

    if (!alias)
    {
        alias = storageAdd(&comp->storage, DEFAULT_STR_LEN + 1);
        strcpy(alias, name);
    }

    if (moduleFindImported(&comp->modules, &comp->blocks, alias) >= 0)
        comp->modules.error->handler(comp->modules.error->context, "Duplicate imported module %s", alias);

    int importedModule = moduleFind(&comp->modules, path);
    if (importedModule < 0)
    {
        // Save context
        int currentModule       = comp->blocks.module;
        DebugInfo currentDebug  = comp->debug;
        Lexer currentLex        = comp->lex;
        lexInit(&comp->lex, &comp->storage, &comp->debug, path, sourceString, sourceTrusted, &comp->error);

        lexNext(&comp->lex);
        importedModule = parseModule(comp);

        // Restore context
        lexFree(&comp->lex);
        comp->lex               = currentLex;
        comp->debug             = currentDebug;
        comp->blocks.module     = currentModule;
    }

    // Imported module is registered but its body has not been compiled yet - this is only possible if it's imported in a cycle
    if (!comp->modules.module[importedModule]->isCompiled)
        comp->modules.error->handler(comp->modules.error->context, "Cyclic import of module %s", alias);

    // Module is imported iff it has an import alias (which may coincide with the module name if not specified explicitly)
    char **importAlias = &comp->modules.module[comp->blocks.module]->importAlias[importedModule];
    if (*importAlias)
         comp->modules.error->handler(comp->modules.error->context, "Duplicate imported module %s", path);
    *importAlias = alias;

    identAddModule(&comp->idents, &comp->modules, &comp->blocks, alias, comp->voidType, importedModule);

    lexNext(&comp->lex);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5d0, %rsp            # imm = 0x5D0
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x45, 0x4bd0(%rax)
jne 0xc9be
movq -0x8(%rbp), %rdi
addq $0xf0, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x4b20
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x4ba8, %rsi           # imm = 0x4BA8
addq $0x28, %rsi
addq $0x8, %rsi
callq 0x30a0
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x31, %esi
callq 0x1b150
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movl $0x49, %esi
callq 0x1b080
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x3190
movq $0x0, -0x118(%rbp)
movb $0x0, -0x119(%rbp)
movq -0x8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movq -0x8(%rbp), %rax
movq 0x4bd8(%rax), %rsi
movq -0x8(%rbp), %rdx
addq $0x100, %rdx            # imm = 0x100
addq $0x4008, %rdx           # imm = 0x4008
leaq -0x110(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
callq 0x5b60
testb $0x1, %al
jne 0xca38
jmp 0xca8c
movq -0x8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq -0x110(%rbp), %rsi
callq 0x5870
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
je 0xca8a
movq -0x128(%rbp), %rax
movq 0x308(%rax), %rax
movq %rax, -0x118(%rbp)
movq -0x128(%rbp), %rax
movb 0x310(%rax), %al
andb $0x1, %al
movb %al, -0x119(%rbp)
jmp 0xca8c
cmpq $0x0, -0x118(%rbp)
jne 0xcadc
movq -0x8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movq -0x8(%rbp), %rax
movq 0x4bd8(%rax), %rsi
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x4b88(%rcx), %rcx
movq 0x100(%rax,%rcx,8), %rdx
addq $0x100, %rdx            # imm = 0x100
leaq -0x110(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
callq 0x5d90
leaq -0x230(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x3190
leaq -0x330(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x3190
movq -0x8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq -0x110(%rbp), %rsi
leaq -0x230(%rbp), %rdx
leaq -0x330(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
callq 0x50a0
cmpq $0x0, -0x10(%rbp)
jne 0xcb5d
movq -0x8(%rbp), %rdi
addq $0xf0, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x4b20
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x30a0
movq -0x8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
movq -0x8(%rbp), %rsi
addq $0x4220, %rsi           # imm = 0x4220
movq -0x10(%rbp), %rdx
callq 0x5370
cmpl $0x0, %eax
jl 0xcbad
movq -0x8(%rbp), %rax
movq 0x4218(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x4218(%rax), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1cb9e9(%rip), %rsi    # 0x1d8592
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq -0x110(%rbp), %rsi
callq 0x52a0
movl %eax, -0x334(%rbp)
cmpl $0x0, -0x334(%rbp)
jge 0xcd0b
movq -0x8(%rbp), %rax
movl 0x4b88(%rax), %eax
movl %eax, -0x338(%rbp)
movq -0x8(%rbp), %rax
movq 0x50e0(%rax), %rcx
movq %rcx, -0x350(%rbp)
movq 0x50e8(%rax), %rcx
movq %rcx, -0x348(%rbp)
movq 0x50f0(%rax), %rax
movq %rax, -0x340(%rbp)
movq -0x8(%rbp), %rsi
addq $0x4ba8, %rsi           # imm = 0x4BA8
leaq -0x5c0(%rbp), %rdi
movl $0x270, %edx            # imm = 0x270
callq 0x3270
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
movq -0x8(%rbp), %rsi
addq $0xf0, %rsi
movq -0x8(%rbp), %rdx
addq $0x50e0, %rdx           # imm = 0x50E0
leaq -0x110(%rbp), %rcx
movq -0x118(%rbp), %r8
movb -0x119(%rbp), %r9b
movq -0x8(%rbp), %rax
addq $0x50f8, %rax           # imm = 0x50F8
andb $0x1, %r9b
movzbl %r9b, %r9d
movq %rax, (%rsp)
callq 0x1a9e0
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
movq -0x8(%rbp), %rdi
callq 0xb0a0
movl %eax, -0x334(%rbp)
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad40
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
leaq -0x5c0(%rbp), %rsi
movl $0x270, %edx            # imm = 0x270
callq 0x3270
movq -0x8(%rbp), %rax
movq -0x350(%rbp), %rcx
movq %rcx, 0x50e0(%rax)
movq -0x348(%rbp), %rcx
movq %rcx, 0x50e8(%rax)
movq -0x340(%rbp), %rcx
movq %rcx, 0x50f0(%rax)
movl -0x338(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4b88(%rax)
movq -0x8(%rbp), %rax
movslq -0x334(%rbp), %rcx
movq 0x100(%rax,%rcx,8), %rax
testb $0x1, 0x2310(%rax)
jne 0xcd53
movq -0x8(%rbp), %rax
movq 0x4218(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x4218(%rax), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1cb860(%rip), %rsi    # 0x1d85af
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x4b88(%rcx), %rcx
movq 0x100(%rax,%rcx,8), %rax
addq $0x310, %rax            # imm = 0x310
movslq -0x334(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x5c8(%rbp)
movq -0x5c8(%rbp), %rax
cmpq $0x0, (%rax)
je 0xcdc1
movq -0x8(%rbp), %rax
movq 0x4218(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x4218(%rax), %rax
movq 0x20(%rax), %rdi
leaq -0x110(%rbp), %rdx
leaq 0x1cb7d5(%rip), %rsi    # 0x1d8592
movb $0x0, %al
callq *%rcx
movq -0x10(%rbp), %rcx
movq -0x5c8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
addq $0x4e38, %rdi           # imm = 0x4E38
movq -0x8(%rbp), %rsi
addq $0x100, %rsi            # imm = 0x100
movq -0x8(%rbp), %rdx
addq $0x4220, %rdx           # imm = 0x4220
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x5218(%rax), %r8
movl -0x334(%rbp), %r9d
callq 0x1a2b0
movq -0x8(%rbp), %rdi
addq $0x4ba8, %rdi           # imm = 0x4BA8
callq 0x1ad90
addq $0x5d0, %rsp            # imm = 0x5D0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop