// File: /workspace/github_c_makefile_star2_O1/vtereshkov[P]umka-lang/src/umka.c
// Function: main
int main(int argc, char **argv)
{
    // Parse interpreter parameters
    int stackSize       = DEFAULT_STACK_SIZE;
    bool writeAsm       = false;
    bool compileOnly    = false;
    bool printWarnings  = false;
    bool isSandbox      = false;

    int i = 1;
    while (i < argc && argv[i][0] == '-')
    {
        if (strcmp(argv[i], "-stack") == 0)
        {
            if (i + 1 == argc)
            {
                fprintf(stderr, "No stack size\n");
                return 1;
            }

            stackSize = strtol(argv[i + 1], NULL, 0);
            if (stackSize <= 0)
            {
                fprintf(stderr, "Illegal stack size\n");
                return 1;
            }

            i += 2;
        }
        else if (strcmp(argv[i], "-asm") == 0)
        {
            writeAsm = true;
            i += 1;
        }
        else if (strcmp(argv[i], "-check") == 0)
        {
            compileOnly = true;
            i += 1;
        }
        else if (strcmp(argv[i], "-warn") == 0)
        {
            printWarnings = true;
            i += 1;
        }
        else if (strcmp(argv[i], "-sandbox") == 0)
        {
            isSandbox = true;
            i += 1;
        }
        else
            break;
    }

    // Parse file name
    if (i >= argc)
    {
        help();
        return 1;
    }

    void *umka = umkaAlloc();
    bool ok = umkaInit(umka, argv[i], NULL, stackSize, NULL, argc - i, argv + i, !isSandbox, !isSandbox, printWarnings ? printCompileWarning : NULL);
    int exitCode = 0;

    if (ok)
        ok = umkaCompile(umka);

    if (ok)
    {
        if (writeAsm)
            ok = writeAsmFile(umka, argv[i]);

        if (ok && !compileOnly)
            exitCode = umkaRun(umka);

        if (exitCode)
            printRuntimeError(umka);
    }
    else
        printCompileError(umka);

    if (!ok)
        exitCode = 1;

    umkaFree(umka);
    return exitCode;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x10(%rsp)
movl %edi, 0xc(%rsp)
cmpl $0x2, %edi
setge %r12b
jl 0xc4c5
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rbp
cmpb $0x2d, (%rbp)
jne 0xc402
movl $0x1, %r13d
movl $0x100000, %eax         # imm = 0x100000
movq %rax, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r15d, %r15d
movq %rbp, %rdi
leaq 0x66de3(%rip), %rsi     # 0x730ec
callq 0x3210
testl %eax, %eax
je 0xc36b
movq %rbp, %rdi
leaq 0x66dfa(%rip), %rsi     # 0x73116
callq 0x3210
movl $0x1, %ebx
testl %eax, %eax
je 0xc3a3
movq %rbp, %rdi
leaq 0x66de7(%rip), %rsi     # 0x7311b
callq 0x3210
testl %eax, %eax
je 0xc3ac
movq %rbp, %rdi
leaq 0x66ddb(%rip), %rsi     # 0x73122
callq 0x3210
testl %eax, %eax
je 0xc3b5
movq %rbp, %rdi
leaq 0x66dce(%rip), %rsi     # 0x73128
callq 0x3210
movb $0x1, %r14b
testl %eax, %eax
je 0xc3bf
jmp 0xc4e0
leal 0x1(%r13), %eax
cmpl 0xc(%rsp), %eax
je 0xc506
movl %eax, %eax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3250
movl $0x2, %ebx
movl %r15d, %r14d
movq %rax, 0x28(%rsp)
testl %eax, %eax
jg 0xc3bf
jmp 0xc50d
movb $0x1, %al
movq %rax, 0x20(%rsp)
jmp 0xc3bc
movb $0x1, %al
movq %rax, 0x18(%rsp)
jmp 0xc3bc
movb $0x1, %al
movq %rax, 0x30(%rsp)
movl %r15d, %r14d
addl %ebx, %r13d
cmpl 0xc(%rsp), %r13d
setl %r12b
jge 0xc4c5
movl %r13d, %eax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rbp
cmpb $0x2d, (%rbp)
movl %r14d, %r15d
je 0xc2ff
xorb $0x1, %r14b
leaq -0x9005(%rip), %rax     # 0x33f0
xorl %ebx, %ebx
testb $0x1, 0x30(%rsp)
cmovneq %rax, %rbx
jmp 0xc429
movl $0x100000, %eax         # imm = 0x100000
movq %rax, 0x28(%rsp)
movb $0x1, %r14b
movl $0x1, %r13d
xorl %ebx, %ebx
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
testb $0x1, %r12b
je 0xc4c5
callq 0xc514
movq %rax, %r12
movslq %r13d, %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %r15
movq (%r15), %rsi
movl 0xc(%rsp), %r9d
subl %eax, %r9d
movzbl %r14b, %eax
andl $0x1, %eax
movq %r12, %rdi
xorl %edx, %edx
movq 0x28(%rsp), %rcx
xorl %r8d, %r8d
pushq %rbx
pushq %rax
pushq %rax
pushq %r15
callq 0xc51e
addq $0x20, %rsp
movl %eax, %ebx
testb %al, %al
je 0xc484
movq %r12, %rdi
callq 0xc8be
movl %eax, %ebx
testb %bl, %bl
je 0xc4e8
testb $0x1, 0x20(%rsp)
je 0xc49c
movq (%r15), %rsi
movq %r12, %rdi
callq 0xc0db
movl %eax, %ebx
movl %ebx, %eax
notb %al
orb 0x18(%rsp), %al
movl $0x0, %ebp
testb $0x1, %al
jne 0xc4b7
movq %r12, %rdi
callq 0xc8ea
movl %eax, %ebp
testl %ebp, %ebp
je 0xc4f0
movq %r12, %rdi
callq 0xc1d0
jmp 0xc4f2
callq 0xc06c
movl $0x1, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %r14d
jmp 0xc3ea
movq %r12, %rdi
callq 0x3419
xorl %ebp, %ebp
testb %bl, %bl
movl $0x1, %ebx
cmovnel %ebp, %ebx
movq %r12, %rdi
callq 0xc978
jmp 0xc4cf
callq 0x349b
jmp 0xc4ca
callq 0x347f
jmp 0xc4ca