// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1425
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3cca(%rip), %rsi      # 0x5004
callq 0x11a0
cmpl $0x0, %eax
jne 0x1369
movl -0x2c(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jge 0x1364
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
jmp 0x1415
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3c8b(%rip), %rsi      # 0x5007
callq 0x11a0
cmpl $0x0, %eax
jne 0x13a8
movl -0x2c(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jge 0x13a6
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
jmp 0x1413
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3c4f(%rip), %rsi      # 0x500a
callq 0x11a0
cmpl $0x0, %eax
jne 0x13eb
movl -0x2c(%rbp), %eax
addl $0x1, %eax
cmpl -0x8(%rbp), %eax
jge 0x13e9
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x11c0
movl %eax, -0x24(%rbp)
jmp 0x1411
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3c0f(%rip), %rsi      # 0x500d
callq 0x11a0
cmpl $0x0, %eax
jne 0x140f
movl $0x1, -0x28(%rbp)
jmp 0x1411
jmp 0x1413
jmp 0x1415
jmp 0x1417
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x131b
cmpq $0x0, -0x18(%rbp)
jne 0x1444
leaq 0x3bdd(%rip), %rdi      # 0x5010
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1170
movl -0x24(%rbp), %edx
movl $0x100, %edi            # imm = 0x100
movl $0xc0, %esi
movl $0x40, %ecx
callq 0x1df0
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
leaq -0x40(%rbp), %rdx
callq 0x1500
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1490
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x1700
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0x28(%rbp), %ecx
callq 0x17f0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1950
movq -0x50(%rbp), %rdi
callq 0x18e0
movq -0x48(%rbp), %rdi
callq 0x1160
cmpq $0x0, -0x40(%rbp)
je 0x14d3
movq -0x40(%rbp), %rdi
callq 0x1160
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1fb0
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)