// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
cmpl $0x2, %edi
jl 0x71e8
movq %rsi, %r14
movl %edi, %ebx
movl $0x100000, %r15d        # imm = 0x100000
movl $0x1, %r13d
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movl %r13d, %r13d
movq (%r14,%r13,8), %rbp
cmpb $0x2d, (%rbp)
jne 0x71f7
movq %rbp, %rdi
leaq 0x6afbb(%rip), %rsi     # 0x720ec
callq 0x3210
testl %eax, %eax
je 0x7195
movq %rbp, %rdi
leaq 0x6afd2(%rip), %rsi     # 0x72116
callq 0x3210
movl $0x1, %r12d
testl %eax, %eax
je 0x71c3
movq %rbp, %rdi
leaq 0x6afbe(%rip), %rsi     # 0x7211b
callq 0x3210
testl %eax, %eax
je 0x71cc
movq %rbp, %rdi
leaq 0x6afb2(%rip), %rsi     # 0x72122
callq 0x3210
testl %eax, %eax
je 0x71d5
movq %rbp, %rdi
leaq 0x6afa5(%rip), %rsi     # 0x72128
callq 0x3210
testl %eax, %eax
jne 0x71f7
movb $0x1, %al
movq %rax, 0x18(%rsp)
jmp 0x71dc
leal 0x1(%r13), %eax
cmpl %ebx, %eax
je 0x72c8
movl %eax, %eax
movq (%r14,%rax,8), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3250
movq %rax, %r15
movl $0x2, %r12d
testl %r15d, %r15d
jg 0x71dc
jmp 0x72d2
movb $0x1, %al
movq %rax, 0x20(%rsp)
jmp 0x71dc
movb $0x1, %al
movq %rax, 0x8(%rsp)
jmp 0x71dc
movb $0x1, %al
movq %rax, 0x10(%rsp)
addl %r12d, %r13d
cmpl %ebx, %r13d
jl 0x7116
callq 0x6e9c
movl $0x1, %ebx
jmp 0x72b7
leaq (%r14,%r13,8), %r12
callq 0x72dc
movq %rax, %r14
movq (%r12), %rsi
subl %r13d, %ebx
movq 0x18(%rsp), %rdx
notb %dl
leaq -0x3e28(%rip), %rax     # 0x33f0
xorl %ecx, %ecx
testb $0x1, 0x10(%rsp)
cmoveq %rcx, %rax
movzbl %dl, %r10d
andl $0x1, %r10d
movq %r14, %rdi
xorl %edx, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
movl %ebx, %r9d
pushq %rax
pushq %r10
pushq %r10
pushq %r12
callq 0x72e6
addq $0x20, %rsp
testb %al, %al
je 0x72a2
movq %r14, %rdi
callq 0x7686
testb %al, %al
je 0x72a2
testb $0x1, 0x20(%rsp)
je 0x727f
movq (%r12), %rsi
movq %r14, %rdi
callq 0x6f0b
xorb $0x1, %al
movq 0x8(%rsp), %rcx
orb %al, %cl
testb $0x1, %cl
je 0x7286
movzbl %al, %ebx
jmp 0x72af
testb $0x1, 0x8(%rsp)
jne 0x729e
movq %r14, %rdi
callq 0x76b2
testl %eax, %eax
je 0x729e
movl %eax, %ebx
movq %r14, %rdi
callq 0x7000
jmp 0x72af
xorl %ebx, %ebx
jmp 0x72af
movq %r14, %rdi
callq 0x3419
movl $0x1, %ebx
movq %r14, %rdi
callq 0x7740
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x349b
jmp 0x71ed
callq 0x347f
jmp 0x71ed