// File: /workspace/github_cpp_makefile_star2_O1/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 0xa7a0
leaq 0x120(%rsp), %rdi
callq 0x9ce4
cmpl $0x1, %ebp
jg 0xb3d0
movl $0x48, %edi
callq 0x6100
movq %rax, %r14
leaq 0x50(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x1c0e(%rip), %rsi      # 0xcfa5
leaq 0x1c55(%rip), %rdx      # 0xcff3
leaq 0x40(%rsp), %rdi
callq 0x8e9a
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x6e1a
xorl %ebp, %ebp
leaq 0x59d7(%rip), %rsi      # 0x10d98
leaq -0x3c14(%rip), %rdx     # 0x77b4
movq %r14, %rdi
callq 0x6380
movq 0x8(%r14), %r14
movq %rsp, %r15
movq 0x8(%r15), %r12
movq %r14, %rdi
callq 0x60e0
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x6320
movq 0x6bf3(%rip), %rdi      # 0x11ff0
leaq 0x1bf0(%rip), %rsi      # 0xcff4
movl $0x15, %edx
callq 0x6240
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x6bd2(%rip), %rdi      # 0x11ff0
callq 0x6240
movq %rax, %r14
leaq 0x1bdd(%rip), %rsi      # 0xd00a
movl $0x4, %edx
movq %rax, %rdi
callq 0x6240
movq %r14, %rdi
callq 0x60f0
leaq 0x30(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0xb722
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xa848
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xb487
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6210
movq 0x6b62(%rip), %rdi      # 0x11ff0
leaq 0x1b7a(%rip), %rsi      # 0xd00f
movl $0x1f, %edx
callq 0x6240
movq 0x6b4a(%rip), %rdi      # 0x11ff0
leaq 0x1b83(%rip), %rsi      # 0xd030
movl $0x15, %edx
callq 0x6240
movq 0x6b32(%rip), %rdi      # 0x11ff0
callq 0x60f0
leaq 0x60(%rsp), %rdi
callq 0xae72
movq 0x6b1c(%rip), %rdi      # 0x11ff0
leaq 0x1b54(%rip), %rsi      # 0xd02f
movl $0x16, %edx
callq 0x6240
movq 0x6b04(%rip), %rdi      # 0x11ff0
callq 0x60f0
movq 0x6af8(%rip), %rdi      # 0x11ff0
leaq 0x1b47(%rip), %rsi      # 0xd046
movl $0x13, %edx
callq 0x6240
leaq 0x60(%rsp), %rdi
callq 0xae8e
movzbl %al, %edi
callq 0x6270
movq %rdx, %r15
movq %rax, %r12
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xb577
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6210
jmp 0xb577
movq %rdx, %r15
movq %rax, %r12
movq 0x40(%rsp), %rdi
cmpq %rbx, %rdi
je 0xb562
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6210
jmp 0xb562
movq %rdx, %r15
movq %rax, %r12
movb $0x1, %bpl
testb %bpl, %bpl
je 0xb577
movq %r14, %rdi
callq 0x6190
jmp 0xb577
movq %rdx, %r15
movq %rax, %r12
movq %r12, %rdi
callq 0x60c0
cmpl $0x2, %r15d
jne 0xb5cb
movq %rax, %r14
movq 0x6a61(%rip), %r15      # 0x11ff0
leaq 0x1ae9(%rip), %rsi      # 0xd07f
movl $0x14, %edx
movq %r15, %rdi
callq 0x6240
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
testq %rax, %rax
jne 0xb61b
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x6370
jmp 0xb638
movq 0x6a1e(%rip), %r14      # 0x11ff0
leaq 0x1a81(%rip), %rsi      # 0xd05a
movl $0x24, %edx
movq %r14, %rdi
callq 0x6240
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x61f0
movsbl %al, %esi
movq 0x69ec(%rip), %rdi      # 0x11ff0
callq 0x6040
movq %rax, %rdi
callq 0x6160
movl $0xffffffec, %edi       # imm = 0xFFFFFFEC
callq 0x6270
movq %rax, %r12
movq %rax, %rdi
callq 0x60e0
movq 0x69c3(%rip), %rdi      # 0x11ff0
movq %r12, %rsi
movq %rax, %rdx
callq 0x6240
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x61f0
movsbl %al, %esi
movq 0x699a(%rip), %rdi      # 0x11ff0
callq 0x6040
movq %rax, %rdi
callq 0x6160
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movl %eax, %edi
callq 0x6270
movq %rax, %r14
callq 0x6360
jmp 0xb685
movq %rax, %r14
callq 0x6360
leaq 0x120(%rsp), %rdi
callq 0x9d0e
jmp 0xb69f
movq %rax, %rdi
callq 0x8e8e
movq %rax, %r14
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0xb6b1
callq 0xaf14
leaq 0x68(%rsp), %rdi
callq 0xb6da
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0xb6d1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6210
movq %r14, %rdi
callq 0x63a0
nop