// File: /workspace/github_c_makefile_star2_O0/vtereshkov[P]umka-lang/src/umka_common.c
// Function: moduleRegularizePath
bool moduleRegularizePath(const Modules *modules, const char *path, const char *curFolder, char *regularizedPath, int size)
{
    char *absolutePath = storageAdd(modules->storage, size);
    snprintf(absolutePath, size, "%s%s", modulePathIsAbsolute(path) ? "" : curFolder, path);

    char **separators = storageAdd(modules->storage, size * sizeof(char *));
    int numSeparators = 0;

    const char *readCh = absolutePath;
    char *writeCh = regularizedPath;
    int numDots = 0;

    while (*readCh)
    {
        switch (*readCh)
        {
            case '/':
            case '\\':
            {
                if (numDots == 1)   // "./" or ".\"
                {
                    numDots = 0;
                    break;
                }

                if (numDots == 2)   // "../" or "..\"
                {
                    if (numSeparators < 2)
                        return false;

                    numSeparators--;
                    writeCh = separators[numSeparators - 1] + 1;

                    numDots = 0;
                    break;
                }

                separators[numSeparators++] = writeCh;
                *(writeCh++) = '/';

                numDots = 0;
                break;
            }

            case '.':
            {
                numDots++;
                break;
            }

            case ' ':
            case '\t':
            {
                numDots = 0;
                // fallthrough
            }

            default:
            {
                while (numDots > 0)
                {
                    *(writeCh++) = '.';
                    numDots--;
                }

                *(writeCh++) = *readCh;
                break;
            }
        }

        readCh++;
    }

    if (numDots > 0)
        return false;

    *writeCh = 0;
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x4110(%rax), %rdi
movslq -0x2c(%rbp), %rsi
callq 0x4b20
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movslq -0x2c(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x57e0
testb $0x1, %al
jne 0x5bb6
jmp 0x5bc3
leaq 0x1d35e9(%rip), %rax    # 0x1d91a6
movq %rax, -0x78(%rbp)
jmp 0x5bcb
movq -0x20(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq 0x1ce78b(%rip), %rdx    # 0x1d436d
movb $0x0, %al
callq 0x3170
movq -0x10(%rbp), %rax
movq 0x4110(%rax), %rdi
movslq -0x2c(%rbp), %rsi
shlq $0x3, %rsi
callq 0x4b20
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x50(%rbp), %rax
cmpb $0x0, (%rax)
je 0x5d62
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x7c(%rbp)
subl $0x9, %eax
je 0x5d0e
jmp 0x5c45
movl -0x7c(%rbp), %eax
subl $0x20, %eax
je 0x5d0e
jmp 0x5c53
movl -0x7c(%rbp), %eax
subl $0x2e, %eax
je 0x5d03
jmp 0x5c61
movl -0x7c(%rbp), %eax
subl $0x2f, %eax
je 0x5c79
jmp 0x5c6b
movl -0x7c(%rbp), %eax
subl $0x5c, %eax
jne 0x5d15
jmp 0x5c79
cmpl $0x1, -0x5c(%rbp)
jne 0x5c8b
movl $0x0, -0x5c(%rbp)
jmp 0x5d51
cmpl $0x2, -0x5c(%rbp)
jne 0x5cce
cmpl $0x2, -0x44(%rbp)
jge 0x5ca0
movb $0x0, -0x1(%rbp)
jmp 0x5d79
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
jmp 0x5d51
movq -0x58(%rbp), %rdx
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x2f, (%rax)
movl $0x0, -0x5c(%rbp)
jmp 0x5d51
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x5d51
movl $0x0, -0x5c(%rbp)
jmp 0x5d17
cmpl $0x0, -0x5c(%rbp)
jle 0x5d3a
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x2e, (%rax)
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x5d17
movq -0x50(%rbp), %rax
movb (%rax), %cl
movq -0x58(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movb %cl, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x5c23
cmpl $0x0, -0x5c(%rbp)
jle 0x5d6e
movb $0x0, -0x1(%rbp)
jmp 0x5d79
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)