// File: /workspace/github_cpp_makefile_star2_O3/QFSW[P]MIPS1-Simulator/src/main.cpp
// Function: main
int main(int argc, const char * argv[])
{
    std::string fileName;
    Simulator sim;
        
    try
    {
        if (argc <= 1) { throw BadBinaryIO("please add the file path to the binary code to simulate as the first argument."); }
        else { fileName = argv[1]; }

        std::cerr << "loading binary file '" << fileName << "'..." << std::endl;
        sim.loadMachineCode(fileName);
        std::cerr << "load success\nsimulating CPU...\n";
        std::cerr << "=====================" << std::endl;
        sim.simulate();
        std::cerr << "\n=====================" << std::endl;
        std::cerr << "simulation success\n";
        std::exit(sim.getExitCode());
    }
    catch (const MIPSException &e)
    {
        std::cerr << "\n\nsimulation failed\n" << e.what() << std::endl;
        std::exit(e.exitCode());
    }
    catch (...)
    {
        std::cerr << "\n\nan unknown internal error occurred" << std::endl;
        std::exit(-20);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %r14
movl %edi, %ebp
leaq 0x10(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq 0x90(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, -0x10(%rdi)
movaps %xmm0, -0x20(%rdi)
movaps %xmm0, -0x30(%rdi)
callq 0x979c
leaq 0x120(%rsp), %rdi
callq 0x8cd0
cmpl $0x1, %ebp
jg 0xa39f
movl $0x48, %edi
callq 0x5100
movq %rax, %r14
leaq 0x50(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1c3e(%rip), %rsi      # 0xbfa5
leaq 0x1c85(%rip), %rdx      # 0xbff3
leaq 0x40(%rsp), %rdi
callq 0x7e20
movb $0x1, %bl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x5e1a
xorl %ebx, %ebx
leaq 0x5a40(%rip), %rsi      # 0xfdd0
leaq -0x3be5(%rip), %rdx     # 0x67b2
movq %r14, %rdi
callq 0x5380
movq 0x8(%r14), %r14
movq %rsp, %r15
movq 0x8(%r15), %r12
movq %r14, %rdi
callq 0x50e0
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x5320
movq 0x6c24(%rip), %rdi      # 0x10ff0
leaq 0x1c21(%rip), %rsi      # 0xbff4
movl $0x15, %edx
callq 0x5240
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x6c03(%rip), %rdi      # 0x10ff0
callq 0x5240
movq %rax, %r14
leaq 0x1c0e(%rip), %rsi      # 0xc00a
movl $0x4, %edx
movq %rax, %rdi
callq 0x5240
movq %r14, %rdi
callq 0x50f0
leaq 0x30(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0xa6f2
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x9844
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xa456
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5210
movq 0x6b93(%rip), %rdi      # 0x10ff0
leaq 0x1bab(%rip), %rsi      # 0xc00f
movl $0x1f, %edx
callq 0x5240
movq 0x6b7b(%rip), %rdi      # 0x10ff0
leaq 0x1bb4(%rip), %rsi      # 0xc030
movl $0x15, %edx
callq 0x5240
movq 0x6b63(%rip), %rdi      # 0x10ff0
callq 0x50f0
leaq 0x60(%rsp), %rdi
callq 0x9e60
movq 0x6b4d(%rip), %rdi      # 0x10ff0
leaq 0x1b85(%rip), %rsi      # 0xc02f
movl $0x16, %edx
callq 0x5240
movq 0x6b35(%rip), %rdi      # 0x10ff0
callq 0x50f0
movq 0x6b29(%rip), %rdi      # 0x10ff0
leaq 0x1b78(%rip), %rsi      # 0xc046
movl $0x13, %edx
callq 0x5240
leaq 0x60(%rsp), %rdi
callq 0x9e7c
movzbl %al, %edi
callq 0x5270
movq %rdx, %r15
movq %rax, %r12
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xa542
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5210
jmp 0xa542
movq %rdx, %r15
movq %rax, %r12
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xa526
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5210
testb %bl, %bl
jne 0xa532
jmp 0xa542
movq %rdx, %r15
movq %rax, %r12
movq %r14, %rdi
callq 0x5190
jmp 0xa542
movq %rdx, %r15
movq %rax, %r12
movq %r12, %rdi
callq 0x50c0
cmpl $0x2, %r15d
jne 0xa596
movq %rax, %r14
movq 0x6a96(%rip), %r15      # 0x10ff0
leaq 0x1b1e(%rip), %rsi      # 0xc07f
movl $0x14, %edx
movq %r15, %rdi
callq 0x5240
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
testq %rax, %rax
jne 0xa5e6
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x5370
jmp 0xa603
movq 0x6a53(%rip), %r14      # 0x10ff0
leaq 0x1ab6(%rip), %rsi      # 0xc05a
movl $0x24, %edx
movq %r14, %rdi
callq 0x5240
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x51f0
movsbl %al, %esi
movq 0x6a21(%rip), %rdi      # 0x10ff0
callq 0x5040
movq %rax, %rdi
callq 0x5160
movl $0xffffffec, %edi       # imm = 0xFFFFFFEC
callq 0x5270
movq %rax, %r12
movq %rax, %rdi
callq 0x50e0
movq 0x69f8(%rip), %rdi      # 0x10ff0
movq %r12, %rsi
movq %rax, %rdx
callq 0x5240
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x51f0
movsbl %al, %esi
movq 0x69cf(%rip), %rdi      # 0x10ff0
callq 0x5040
movq %rax, %rdi
callq 0x5160
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movl %eax, %edi
callq 0x5270
movq %rax, %r14
callq 0x5360
jmp 0xa650
movq %rax, %r14
callq 0x5360
leaq 0x120(%rsp), %rdi
callq 0x8cfa
jmp 0xa66a
movq %rax, %rdi
callq 0x7e14
movq %rax, %r14
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0xa67c
callq 0x9f02
leaq 0x68(%rsp), %rdi
callq 0xa6a4
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0xa69c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5210
movq %r14, %rdi
callq 0x53a0