// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, 0x8(%rsp)
movl %edi, %r13d
pushq $0x1
popq %rax
movl $0x100000, %ebx         # imm = 0x100000
movq $0x0, 0x20(%rsp)
movq $0x0, (%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movl %eax, %r15d
movl %r13d, %ebp
subl %r15d, %ebp
jle 0x3938
movl %r15d, %r14d
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %r12
cmpb $0x2d, (%r12)
jne 0x38b2
movq %r12, %rdi
leaq 0x628ee(%rip), %rsi     # 0x660ec
callq 0x3210
testl %eax, %eax
je 0x385f
movq %r12, %rdi
leaq 0x62905(%rip), %rsi     # 0x66116
callq 0x3210
testl %eax, %eax
je 0x388f
movq %r12, %rdi
leaq 0x628f7(%rip), %rsi     # 0x6611b
callq 0x3210
testl %eax, %eax
je 0x3898
movq %r12, %rdi
leaq 0x628eb(%rip), %rsi     # 0x66122
callq 0x3210
testl %eax, %eax
je 0x38a0
movq %r12, %rdi
leaq 0x628de(%rip), %rsi     # 0x66128
callq 0x3210
testl %eax, %eax
jne 0x38b2
pushq $0x1
popq %rax
movb $0x1, %cl
movq %rcx, 0x18(%rsp)
jmp 0x38aa
leal 0x1(%r15), %eax
cmpl %r13d, %eax
je 0x3988
movl %eax, %eax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3250
movq %rax, %rbx
pushq $0x2
popq %rax
testl %ebx, %ebx
jg 0x38aa
jmp 0x399d
movb $0x1, %al
movq %rax, 0x20(%rsp)
jmp 0x38a7
movb $0x1, %al
movq %rax, (%rsp)
jmp 0x38a7
movb $0x1, %al
movq %rax, 0x10(%rsp)
pushq $0x1
popq %rax
addl %eax, %r15d
jmp 0x37d1
movq 0x8(%rsp), %rax
leaq (%rax,%r14,8), %r15
callq 0x39bc
movq %rax, %r14
movq (%r15), %rsi
movq 0x18(%rsp), %rdx
notb %dl
leaq -0x261(%rip), %rax      # 0x3673
xorl %ecx, %ecx
testb $0x1, 0x10(%rsp)
cmoveq %rcx, %rax
movzbl %dl, %r10d
andl $0x1, %r10d
movq %r14, %rdi
xorl %edx, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
movl %ebp, %r9d
pushq %rax
pushq %r10
pushq %r10
pushq %r15
callq 0x39c6
addq $0x20, %rsp
testb %al, %al
je 0x3942
movq %r14, %rdi
callq 0x3d5d
testb %al, %al
je 0x3942
testb $0x1, 0x20(%rsp)
je 0x3966
movq (%r15), %rsi
movq %r14, %rdi
callq 0x354b
xorb $0x1, %al
movq (%rsp), %rcx
orb %al, %cl
testb $0x1, %cl
je 0x396c
movzbl %al, %ebx
jmp 0x394d
callq 0x34dc
pushq $0x1
popq %rbx
jmp 0x3955
movq %r14, %rdi
callq 0x369c
pushq $0x1
popq %rbx
movq %r14, %rdi
callq 0x3e17
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, (%rsp)
jne 0x3984
movq %r14, %rdi
callq 0x3d89
testl %eax, %eax
je 0x3984
movl %eax, %ebx
movq %r14, %rdi
callq 0x36ca
jmp 0x394d
xorl %ebx, %ebx
jmp 0x394d
movq 0x77669(%rip), %rax     # 0x7aff8
movq (%rax), %rcx
leaq 0x6275a(%rip), %rdi     # 0x660f3
pushq $0xe
jmp 0x39b0
movq 0x77654(%rip), %rax     # 0x7aff8
movq (%rax), %rcx
leaq 0x62754(%rip), %rdi     # 0x66102
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
callq 0x3390
jmp 0x393d
nop