// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0x58, %rsp
movl $0x0, -0xc(%rbp)
movl %edi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x100000, -0x1c(%rbp)  # imm = 0x100000
movb $0x0, -0x1d(%rbp)
movb $0x0, -0x1e(%rbp)
movb $0x0, -0x1f(%rbp)
movb $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl -0x10(%rbp), %ecx
movb %al, -0x39(%rbp)
jge 0x38ca
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
sete %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x38d6
jmp 0x3a3f
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1d0960(%rip), %rsi    # 0x1d4249
callq 0x3220
cmpl $0x0, %eax
jne 0x397d
movl -0x24(%rbp), %eax
addl $0x1, %eax
cmpl -0x10(%rbp), %eax
jne 0x3926
movq 0x1e26ef(%rip), %rax    # 0x1e5ff8
movq (%rax), %rdi
leaq 0x1d093d(%rip), %rsi    # 0x1d4250
movb $0x0, %al
callq 0x3230
movl $0x1, -0xc(%rbp)
jmp 0x3b71
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x3260
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x396f
movq 0x1e26a6(%rip), %rax    # 0x1e5ff8
movq (%rax), %rdi
leaq 0x1d0903(%rip), %rsi    # 0x1d425f
movb $0x0, %al
callq 0x3230
movl $0x1, -0xc(%rbp)
jmp 0x3b71
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
jmp 0x3a3a
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1d08e3(%rip), %rsi    # 0x1d4273
callq 0x3220
cmpl $0x0, %eax
jne 0x39ac
movb $0x1, -0x1d(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3a38
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1d08b9(%rip), %rsi    # 0x1d4278
callq 0x3220
cmpl $0x0, %eax
jne 0x39d8
movb $0x1, -0x1e(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3a36
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1d0894(%rip), %rsi    # 0x1d427f
callq 0x3220
cmpl $0x0, %eax
jne 0x3a04
movb $0x1, -0x1f(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3a34
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1d086e(%rip), %rsi    # 0x1d4285
callq 0x3220
cmpl $0x0, %eax
jne 0x3a30
movb $0x1, -0x20(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3a32
jmp 0x3a3f
jmp 0x3a34
jmp 0x3a36
jmp 0x3a38
jmp 0x3a3a
jmp 0x38a5
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
jl 0x3a58
callq 0x34e0
movl $0x1, -0xc(%rbp)
jmp 0x3b71
callq 0x3b80
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movl -0x1c(%rbp), %ecx
movl -0x10(%rbp), %r9d
subl -0x24(%rbp), %r9d
movq -0x18(%rbp), %r10
movslq -0x24(%rbp), %rax
shlq $0x3, %rax
addq %rax, %r10
movb -0x20(%rbp), %dl
xorb $-0x1, %dl
movb -0x20(%rbp), %r8b
xorb $-0x1, %r8b
movb -0x1f(%rbp), %bl
xorl %eax, %eax
movl %eax, %r11d
leaq -0x3e8(%rip), %rax      # 0x36c0
testb $0x1, %bl
cmovneq %rax, %r11
xorl %eax, %eax
movq %rsp, %rax
movq %r11, 0x18(%rax)
movq %r10, (%rax)
movzbl %r8b, %r8d
andl $0x1, %r8d
movl %r8d, 0x10(%rax)
movzbl %dl, %edx
andl $0x1, %edx
movl %edx, 0x8(%rax)
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rdx
callq 0x3b90
andb $0x1, %al
movb %al, -0x31(%rbp)
movl $0x0, -0x38(%rbp)
testb $0x1, -0x31(%rbp)
je 0x3afd
movq -0x30(%rbp), %rdi
callq 0x4110
andb $0x1, %al
movb %al, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
je 0x3b4c
testb $0x1, -0x1d(%rbp)
je 0x3b23
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x3570
andb $0x1, %al
movb %al, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
je 0x3b3b
testb $0x1, -0x1e(%rbp)
jne 0x3b3b
movq -0x30(%rbp), %rdi
callq 0x4160
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x3b4a
movq -0x30(%rbp), %rdi
callq 0x3770
jmp 0x3b55
movq -0x30(%rbp), %rdi
callq 0x3710
testb $0x1, -0x31(%rbp)
jne 0x3b62
movl $0x1, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x42b0
movl -0x38(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)