// File: /workspace/github_c_makefile_star2_O1/minkcv[P]vm/main.c
// Function: main
int main (int argc, char** argv)
{
    char* programName = NULL;
    char* romName = NULL;
    int scale = 1;
    int debugMode = 0;
    int i;
    for (i = 1; i < argc; i++)
    {
        if (!strcmp(argv[i], "-f"))
        {
            if (i + 1 < argc)
                programName = argv[i + 1];
        }
        else if (!strcmp(argv[i], "-r"))
        {
            if (i + 1 < argc)
                romName = argv[i + 1];
        }
        else if (!strcmp(argv[i], "-s"))
        {
            if (i + 1 < argc)
                scale = atoi(argv[i + 1]);
        }
        else if (!strcmp(argv[i], "-d"))
            debugMode = 1;
    }
    if (programName == NULL)
    {
        printf("Usage: main -f program.vaporbin\n");
        exit(1);
    }

    Display* display = createDisplay(SCREEN_WIDTH, SCREEN_HEIGHT, scale, SCREEN_WIDTH / 4);
    uint8_t* rom = NULL;
    uint16_t* code = readBinary(programName, 0, &rom);
    if (romName != NULL) // ROM is optional
        rom = readRom(romName, 0);

    VM* vm = createVM(code, rom, display, debugMode);
    run(vm);
    destroyVM(vm);
    free(code);
    if (rom != NULL)
        free(rom);
    code = NULL;
    rom = NULL;
    quitDisplay(display);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x2, %edi
jl 0x13ef
movq %rsi, %r12
movl %edi, %r14d
movl $0x1, %ebx
subq %r14, %rbx
movq $0x0, -0x48(%rbp)
movl $0x2, %r13d
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x1, -0x2c(%rbp)
movq -0x8(%r12,%r13,8), %r15
movq %r15, %rdi
leaq 0x1cac(%rip), %rsi      # 0x3004
callq 0x11b0
testl %eax, %eax
je 0x13aa
movq %r15, %rdi
leaq 0x1c9c(%rip), %rsi      # 0x3007
callq 0x11b0
testl %eax, %eax
je 0x13b9
movq %r15, %rdi
leaq 0x1c8c(%rip), %rsi      # 0x300a
callq 0x11b0
testl %eax, %eax
je 0x13c8
movq %r15, %rdi
leaq 0x1c7c(%rip), %rsi      # 0x300d
callq 0x11b0
testl %eax, %eax
movq -0x38(%rbp), %rax
movl $0x1, %ecx
cmovel %ecx, %eax
movq %rax, -0x38(%rbp)
jmp 0x13d9
cmpq %r14, %r13
jae 0x13d9
movq (%r12,%r13,8), %rax
movq %rax, -0x48(%rbp)
jmp 0x13d9
cmpq %r14, %r13
jae 0x13d9
movq (%r12,%r13,8), %rax
movq %rax, -0x40(%rbp)
jmp 0x13d9
cmpq %r14, %r13
jae 0x13d9
movq (%r12,%r13,8), %rdi
callq 0x11e0
movl %eax, -0x2c(%rbp)
leaq (%rbx,%r13), %rax
incq %rax
incq %r13
cmpq $0x2, %rax
jne 0x1349
jmp 0x140e
movq $0x0, -0x38(%rbp)
movl $0x1, -0x2c(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rbx
testq %rbx, %rbx
je 0x14c0
movl $0x100, %edi            # imm = 0x100
movl $0xc0, %esi
movl -0x2c(%rbp), %edx
movl $0x40, %ecx
callq 0x1bdc
movq %rax, %r14
leaq -0x50(%rbp), %rdx
movq $0x0, (%rdx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x14d6
movq %rax, %r15
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x1461
xorl %esi, %esi
callq 0x168c
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq -0x38(%rbp), %rcx
callq 0x176c
movq %rax, %rbx
movq %rax, %rdi
callq 0x184c
movq %rbx, %rdi
callq 0x180d
movq %r15, %rdi
callq 0x1160
testq %r12, %r12
je 0x149f
movq %r12, %rdi
callq 0x1160
movq $0x0, -0x50(%rbp)
movq %r14, %rdi
callq 0x1d21
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bc9(%rip), %rdi      # 0x3090
callq 0x11d0
movl $0x1, %edi
callq 0x1170