// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rsi, %r12
movl %edi, %r13d
movslq %edi, %r14
xorl %esi, %esi
pushq $0x1
popq %rdi
pushq $0x1
popq %rbx
movl %edi, %edx
movq $0x0, -0x30(%rbp)
xorl %r15d, %r15d
cmpq %r14, %rbx
jge 0x13cf
movq %rbx, %rax
movq (%r12,%rbx,8), %rcx
cmpb $0x2d, (%rcx)
jne 0x13c4
cmpb $0x66, 0x1(%rcx)
jne 0x1350
cmpb $0x0, 0x2(%rcx)
je 0x1390
cmpb $0x72, 0x1(%rcx)
jne 0x135c
cmpb $0x0, 0x2(%rcx)
je 0x13a0
cmpb $0x73, 0x1(%rcx)
jne 0x13b7
cmpb $0x0, 0x2(%rcx)
jne 0x13b7
leaq 0x1(%rax), %rbx
cmpl %r13d, %ebx
jge 0x132b
movq 0x8(%r12,%rax,8), %rdi
movq %r15, -0x38(%rbp)
movq %rsi, %r15
callq 0x11e0
pushq $0x1
popq %rdi
movq %r15, %rsi
movq -0x38(%rbp), %r15
movl %eax, %edx
jmp 0x132b
leaq 0x1(%rax), %rbx
cmpl %r13d, %ebx
jge 0x132b
movq 0x8(%r12,%rax,8), %r15
jmp 0x132b
leaq 0x1(%rax), %rbx
cmpl %r13d, %ebx
jge 0x132b
movq 0x8(%r12,%rax,8), %rax
movq %rax, -0x30(%rbp)
jmp 0x132b
cmpb $0x64, 0x1(%rcx)
jne 0x13c4
cmpb $0x0, 0x2(%rcx)
cmovel %edi, %esi
incq %rax
movq %rax, %rbx
jmp 0x132b
testq %r15, %r15
je 0x146a
movq %rsi, %rbx
pushq $0x40
popq %rcx
movl $0x100, %edi            # imm = 0x100
movl $0xc0, %esi
callq 0x1b14
movq %rax, %r12
leaq -0x40(%rbp), %rdx
andq $0x0, (%rdx)
movq %r15, %rdi
xorl %esi, %esi
callq 0x147e
movq %rax, %r15
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x141a
xorl %esi, %esi
callq 0x1606
movq %rax, %r14
jmp 0x141e
movq -0x40(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
movl %ebx, %ecx
callq 0x16d4
movq %rax, %rbx
movq %rax, %rdi
callq 0x17a9
movq %rbx, %rdi
callq 0x1772
movq %r15, %rdi
callq 0x1170
movq %r14, %rdi
callq 0x1170
movq %r12, %rdi
callq 0x1c53
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c13(%rip), %rdi      # 0x3084
callq 0x11d0
pushq $0x1
popq %rdi
callq 0x1180