// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x70(%rsp), %rdi
callq 0x97f4
cmpl $0x1, %ebp
jg 0x961f
pushq $0x48
popq %rdi
callq 0x50f0
movq %rax, %rbx
leaq 0x19a6(%rip), %rsi      # 0xaf8e
leaq 0x50(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x67c8
movb $0x1, %bpl
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x59b2
xorl %ebp, %ebp
leaq 0x67c8(%rip), %rsi      # 0xfdd8
leaq -0x366f(%rip), %rdx     # 0x5fa8
movq %rbx, %rdi
callq 0x5360
movq 0x8(%rbx), %rsi
leaq 0x10(%rsp), %rdi
callq 0x53e0
movq 0x79bc(%rip), %rdi      # 0x10ff0
leaq 0x19a2(%rip), %rsi      # 0xafdd
callq 0x51e0
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x51d0
leaq 0x199f(%rip), %rsi      # 0xaff3
movq %rax, %rdi
callq 0x51e0
movq %rax, %rdi
callq 0x50e0
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x52b0
leaq 0x70(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x8b64
leaq 0x30(%rsp), %rdi
callq 0x50d0
movq 0x795d(%rip), %rdi      # 0x10ff0
leaq 0x195e(%rip), %rsi      # 0xaff8
callq 0x51e0
movq 0x794a(%rip), %rdi      # 0x10ff0
leaq 0x196c(%rip), %rsi      # 0xb019
callq 0x51e0
movq %rax, %rdi
callq 0x50e0
leaq 0x70(%rsp), %rdi
callq 0x909c
movq 0x7925(%rip), %rdi      # 0x10ff0
leaq 0x1946(%rip), %rsi      # 0xb018
callq 0x51e0
movq %rax, %rdi
callq 0x50e0
movq 0x790a(%rip), %rdi      # 0x10ff0
leaq 0x1942(%rip), %rsi      # 0xb02f
callq 0x51e0
leaq 0x70(%rsp), %rdi
callq 0x90c0
movzbl %al, %edi
callq 0x5240
movq %rdx, %r14
movq %rax, %r15
leaq 0x30(%rsp), %rdi
callq 0x50d0
jmp 0x9743
movq %rdx, %r14
movq %rax, %r15
leaq 0x50(%rsp), %rdi
callq 0x50d0
testb %bpl, %bpl
jne 0x9733
jmp 0x9743
movq %rdx, %r14
movq %rax, %r15
movq %rbx, %rdi
callq 0x5170
jmp 0x9743
movq %rdx, %r14
movq %rax, %r15
movq %r15, %rdi
callq 0x50a0
cmpl $0x2, %r14d
jne 0x9796
movq %rax, %rbx
movq 0x7895(%rip), %rdi      # 0x10ff0
leaq 0x1906(%rip), %rsi      # 0xb068
callq 0x51e0
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x51e0
movq %rax, %rdi
callq 0x50e0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
movl %eax, %edi
callq 0x5240
movq 0x7853(%rip), %rdi      # 0x10ff0
leaq 0x189f(%rip), %rsi      # 0xb043
callq 0x51e0
movq %rax, %rdi
callq 0x50e0
pushq $-0x14
popq %rdi
callq 0x5240
movq %rax, %rbx
callq 0x5350
jmp 0x97cb
movq %rax, %rbx
callq 0x5350
leaq 0x70(%rsp), %rdi
callq 0x9848
jmp 0x97e2
movq %rax, %rdi
callq 0x7378
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x50d0
movq %rbx, %rdi
callq 0x5390