// File: /workspace/github_c_makefile_star2_O0/hobo0xcc[P]rve/src/main.c
// Function: main
int main(int argc, char **argv) {
    if (argc < 2) {
        Error("Missing argument, at least 1 argument required.");
    }

    int prog_name_idx = 1;
    bool is_debug = false;
    if (!strcmp(argv[1], "--debug")) {
        is_debug = true;
        prog_name_idx++;
    } else if (!strcmp(argv[1], "--test")) {
        RunTest();
        return 0;
    }

    uint8_t *bin;
    size_t size = ReadBinaryFile(argv[prog_name_idx++], &bin);
    State *state = NewState(0x9000000/*0x7A12000*/);
    ResetState(state);

    if (argc > prog_name_idx && !strcmp(argv[prog_name_idx], "--disk")) {
        char *name = argv[++prog_name_idx];
        uint8_t *data;
        ReadBinaryFile(name, &data);
        SetDisk(state, data);
        prog_name_idx += 2;
    }

    uint64_t addr = LoadElf(state, size, bin);

    state->x[1] = (uint64_t)(-2);

    CPUMain(state, addr, size, is_debug);

    PrintRegisters(state, is_debug);
    int32_t result;
    result = state->x[10];

    free(bin);
    free(state->mem);
    free(state);
    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0xdbea
leaq 0x1b91(%rip), %rdi      # 0xf774
movb $0x0, %al
callq 0xd690
movl $0x1, -0x14(%rbp)
movb $0x0, -0x15(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1ba0(%rip), %rsi      # 0xf7a4
callq 0x10f0
cmpl $0x0, %eax
jne 0xdc1d
movb $0x1, -0x15(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xdc4b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1b80(%rip), %rsi      # 0xf7ac
callq 0x10f0
cmpl $0x0, %eax
jne 0xdc49
movb $0x0, %al
callq 0xded0
movl $0x0, -0x4(%rbp)
jmp 0xdd69
jmp 0xdc4b
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x20(%rbp), %rsi
callq 0xd9f0
movq %rax, -0x28(%rbp)
movl $0x9000000, %edi        # imm = 0x9000000
callq 0xd880
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xd8d0
movl -0x8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0xdce5
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1b13(%rip), %rsi      # 0xf7b3
callq 0x10f0
cmpl $0x0, %eax
jne 0xdce5
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xd9f0
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xdb90
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x14(%rbp)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xd4e0
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq $-0x2, 0x8010(%rax)
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rdx
movb -0x15(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0xdaa0
movq -0x30(%rbp), %rdi
movb -0x15(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xdb20
movq -0x30(%rbp), %rax
movq 0x8058(%rax), %rax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1040
movq -0x30(%rbp), %rax
movq 0x8108(%rax), %rdi
callq 0x1040
movq -0x30(%rbp), %rdi
callq 0x1040
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)