// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_common.c
// Function: moduleAdd
int moduleAdd(Modules *modules, const char *path)
{
    if (modules->numModules >= MAX_MODULES)
        modules->error->handler(modules->error->context, "Too many modules");

    char folder[DEFAULT_STR_LEN + 1] = "";
    char name  [DEFAULT_STR_LEN + 1] = "";

    moduleNameFromPath(modules, path, folder, name, DEFAULT_STR_LEN + 1);

    for (int i = 0; name[i]; i++)
        if (name[i] == ' ' || name[i] == '\t')
            modules->error->handler(modules->error->context, "Module name cannot contain spaces or tabs");

    int res = moduleFind(modules, path);
    if (res >= 0)
        modules->error->handler(modules->error->context, "Duplicate module %s", path);

    Module *module = storageAdd(modules->storage, sizeof(Module));

    strncpy(module->path, path, DEFAULT_STR_LEN);
    module->path[DEFAULT_STR_LEN] = 0;

    strncpy(module->folder, folder, DEFAULT_STR_LEN);
    module->folder[DEFAULT_STR_LEN] = 0;

    strncpy(module->name, name, DEFAULT_STR_LEN);
    module->name[DEFAULT_STR_LEN] = 0;

    module->pathHash = hash(path);

    if (modules->implLibsEnabled)
    {
        char libPath[2 + 2 * DEFAULT_STR_LEN + 8 + 4 + 1];

        const char *pathPrefix = modulePathIsAbsolute(module->path) ? "" : "./";

        // First, search for an implementation library with an OS-specific suffix
        sprintf(libPath, "%s%s%s%s.umi", pathPrefix, module->folder, module->name, moduleImplLibSuffix());
        module->implLib = moduleLoadImplLib(libPath);

        // If not found, search for an implementation library without suffix
        if (!module->implLib)
        {
            sprintf(libPath, "%s%s%s.umi", pathPrefix, module->folder, module->name);
            module->implLib = moduleLoadImplLib(libPath);
        }
    }

    // Self-import
    module->importAlias[modules->numModules] = storageAdd(modules->storage, DEFAULT_STR_LEN + 1);
    strcpy(module->importAlias[modules->numModules], name);

    module->isCompiled = false;

    modules->module[modules->numModules] = module;
    return modules->numModules++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x400, 0x4000(%rax)    # imm = 0x400
jl 0x544b
movq -0x8(%rbp), %rax
movq 0x4118(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x4118(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x1ceeaf(%rip), %rsi    # 0x1d42f6
movb $0x0, %al
callq *%rcx
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x3190
leaq -0x210(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x3190
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x110(%rbp), %rdx
leaq -0x210(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
callq 0x50a0
movl $0x0, -0x214(%rbp)
movslq -0x214(%rbp), %rax
cmpb $0x0, -0x210(%rbp,%rax)
je 0x5510
movslq -0x214(%rbp), %rax
movsbl -0x210(%rbp,%rax), %eax
cmpl $0x20, %eax
je 0x54d5
movslq -0x214(%rbp), %rax
movsbl -0x210(%rbp,%rax), %eax
cmpl $0x9, %eax
jne 0x54fd
movq -0x8(%rbp), %rax
movq 0x4118(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x4118(%rax), %rax
movq 0x20(%rax), %rdi
leaq 0x1cee0e(%rip), %rsi    # 0x1d4307
movb $0x0, %al
callq *%rcx
jmp 0x54ff
movl -0x214(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x214(%rbp)
jmp 0x549c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x52a0
movl %eax, -0x218(%rbp)
cmpl $0x0, -0x218(%rbp)
jl 0x5558
movq -0x8(%rbp), %rax
movq 0x4118(%rax), %rax
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x4118(%rax), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1ceddd(%rip), %rsi    # 0x1d4331
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movq 0x4110(%rax), %rdi
movl $0x2318, %esi           # imm = 0x2318
callq 0x4b20
movq %rax, -0x220(%rbp)
movq -0x220(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0xff, %edx
callq 0x3080
movq -0x220(%rbp), %rax
movb $0x0, 0xff(%rax)
movq -0x220(%rbp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq -0x110(%rbp), %rsi
movl $0xff, %edx
callq 0x3080
movq -0x220(%rbp), %rax
movb $0x0, 0x1ff(%rax)
movq -0x220(%rbp), %rdi
addq $0x200, %rdi            # imm = 0x200
leaq -0x210(%rbp), %rsi
movl $0xff, %edx
callq 0x3080
movq -0x220(%rbp), %rax
movb $0x0, 0x2ff(%rax)
movq -0x10(%rbp), %rdi
callq 0x5330
movl %eax, %ecx
movq -0x220(%rbp), %rax
movl %ecx, 0x300(%rax)
movq -0x8(%rbp), %rax
testb $0x1, 0x4108(%rax)
je 0x573f
movq -0x220(%rbp), %rdi
callq 0x57e0
movb %al, %dl
leaq 0x1ced16(%rip), %rax    # 0x1d4345
leaq 0x1d3b70(%rip), %rcx    # 0x1d91a6
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x438(%rbp)
leaq -0x430(%rbp), %rax
movq %rax, -0x458(%rbp)
movq -0x438(%rbp), %rax
movq %rax, -0x450(%rbp)
movq -0x220(%rbp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, -0x448(%rbp)
movq -0x220(%rbp), %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x440(%rbp)
callq 0x61c0
movq -0x458(%rbp), %rdi
movq -0x450(%rbp), %rdx
movq -0x448(%rbp), %rcx
movq -0x440(%rbp), %r8
movq %rax, %r9
leaq 0x1cec95(%rip), %rsi    # 0x1d4348
movb $0x0, %al
callq 0x3380
leaq -0x430(%rbp), %rdi
callq 0x5860
movq %rax, %rcx
movq -0x220(%rbp), %rax
movq %rcx, 0x308(%rax)
movq -0x220(%rbp), %rax
cmpq $0x0, 0x308(%rax)
jne 0x573d
leaq -0x430(%rbp), %rdi
movq -0x438(%rbp), %rdx
movq -0x220(%rbp), %rcx
addq $0x100, %rcx            # imm = 0x100
movq -0x220(%rbp), %r8
addq $0x200, %r8             # imm = 0x200
leaq 0x1cec31(%rip), %rsi    # 0x1d434a
movb $0x0, %al
callq 0x3380
leaq -0x430(%rbp), %rdi
callq 0x5860
movq %rax, %rcx
movq -0x220(%rbp), %rax
movq %rcx, 0x308(%rax)
jmp 0x573f
movq -0x8(%rbp), %rax
movq 0x4110(%rax), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x4b20
movq %rax, %rdx
movq -0x220(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x4000(%rcx), %rcx
movq %rdx, 0x310(%rax,%rcx,8)
movq -0x220(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x4000(%rcx), %rcx
movq 0x310(%rax,%rcx,8), %rdi
leaq -0x210(%rbp), %rsi
callq 0x30a0
movq -0x220(%rbp), %rax
movb $0x0, 0x2310(%rax)
movq -0x220(%rbp), %rdx
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x4000(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rcx
movl 0x4000(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x4000(%rcx)
addq $0x460, %rsp            # imm = 0x460
popq %rbp
retq
nopl (%rax)