// File: /workspace/github_cpp_makefile_star2_O3/pollow[P]MIPSClide/sim.cpp
// Function: main
int main(int argc, char **argv) {
    try {
        string filename, mode;
        argv++;
        argc--;
        if ( argc % 2 ) {
            throw invalid_argument("Lack of Arguments!");
        } else {
            map<char, string> arg_map;
            for (int i = 0; i < argc; i+=2) {
                if (argv[i][0] != '-') {
                    throw invalid_argument("Option should start with '-'!");
                }
                arg_map[argv[i][1]] = argv[i+1];
            }
            // -m (run|debug) -f (filename)
            if ( arg_map.count('m') ) {
                mode = arg_map['m'];
            } else {
                throw invalid_argument("Mode should be specified with -m (run|debug).");
            }
            if ( arg_map.count('f') ) {
                filename = arg_map['f'];
            } else {
                throw invalid_argument("File should be specified with -f filename.");
            }
        }

        fstream fin(filename, ios::in);
        fin.exceptions(fin.failbit);

        string ins, content;
        while(!fin.eof()) {
            getline(fin, ins);
            content += ins + "\n";
        }

        Simulator sim(content);
        sim.init();

        if ( mode == "run" ) {
            sim.run();
        } else if ( mode == "debug" ) {
            sim.debug();
        } else {
            throw invalid_argument("Mode should be specified with -m (run|debug).");
        }
    } catch (exception &err) {
        cerr << err.what() << endl;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
leaq -0xa0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x60(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leal -0x1(%rdi), %eax
testb $0x1, %al
jne 0x904b
leaq -0x428(%rbp), %rdx
movl $0x0, (%rdx)
xorl %ecx, %ecx
movq %rcx, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rcx, 0x20(%rdx)
cmpl $0x2, %edi
jl 0x8ffb
movq %rsi, %rbx
movl %eax, %eax
movq %rax, -0x30(%rbp)
xorl %r14d, %r14d
movq 0x8(%rbx,%r14,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x8fc4
movq 0x10(%rbx,%r14,8), %r15
incq %rsi
leaq -0x430(%rbp), %rdi
callq 0x920e
movq %rax, %r12
movq 0x8(%rax), %r13
movq %r15, %rdi
callq 0x5150
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0x5470
addq $0x2, %r14
cmpq -0x30(%rbp), %r14
jb 0x8c10
movq -0x420(%rbp), %rsi
testq %rsi, %rsi
leaq -0x428(%rbp), %rbx
je 0x8ffb
movq %rbx, %rdi
movq %rdi, %rax
movq %rsi, %rcx
movb 0x20(%rsi), %dl
xorl %esi, %esi
cmpb $0x6d, %dl
setl %sil
movq %rcx, %rdi
cmovlq %rax, %rdi
movq 0x10(%rcx,%rsi,8), %rsi
testq %rsi, %rsi
jne 0x8c78
cmpq %rbx, %rdi
je 0x8ffb
cmpb $0x6d, %dl
cmovlq %rax, %rcx
cmpb $0x6d, 0x20(%rcx)
jg 0x8ffb
leaq -0x220(%rbp), %rsi
movb $0x6d, (%rsi)
leaq -0x430(%rbp), %rdi
callq 0x9276
leaq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x51b0
movq -0x420(%rbp), %rsi
testq %rsi, %rsi
je 0x9019
movq %rbx, %rdi
movq %rdi, %rax
movq %rsi, %rcx
movb 0x20(%rsi), %dl
xorl %esi, %esi
cmpb $0x66, %dl
setl %sil
movq %rcx, %rdi
cmovlq %rax, %rdi
movq 0x10(%rcx,%rsi,8), %rsi
testq %rsi, %rsi
jne 0x8cea
cmpq %rbx, %rdi
je 0x9019
cmpb $0x66, %dl
cmovlq %rax, %rcx
cmpb $0x66, 0x20(%rcx)
jg 0x9019
leaq -0x220(%rbp), %rsi
movb $0x66, (%rsi)
leaq -0x430(%rbp), %rdi
callq 0x9276
leaq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x51b0
leaq -0x430(%rbp), %rdi
callq 0x9ae4
leaq -0x430(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x8, %edx
callq 0x54e0
movq -0x430(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x430, %rdi           # imm = 0xFBD0
movl $0x4, 0x1c(%rdi)
movl 0x20(%rdi), %esi
callq 0x5510
leaq -0x40(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x80(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq -0x430(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x410(%rbp,%rax)
jne 0x8e89
leaq (%rax,%rbp), %rdi
addq $-0x430, %rdi           # imm = 0xFBD0
leaq -0x430(%rbp), %rbx
leaq -0x50(%rbp), %r14
leaq -0x220(%rbp), %r15
leaq 0x1a7cb(%rip), %r12     # 0x235bb
leaq -0x90(%rbp), %r13
movl $0xa, %esi
callq 0x52f0
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x55a0
leaq -0x210(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9c9c
movq %r15, %rdi
movq %r12, %rsi
callq 0x55f0
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rdx
movq %r13, %rdi
callq 0x50c0
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x8e69
callq 0x52d0
movq -0x430(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rax,%rbp), %rdi
addq $-0x430, %rdi           # imm = 0xFBD0
testb $0x2, 0x20(%rdi)
je 0x8df7
leaq -0x220(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x92de
leaq -0x220(%rbp), %rdi
callq 0xb070
leaq 0x1a1df(%rip), %rsi     # 0x2308e
leaq -0x70(%rbp), %rdi
callq 0x50b0
testl %eax, %eax
je 0x8ee2
leaq 0x1a1cf(%rip), %rsi     # 0x23092
leaq -0x70(%rbp), %rdi
callq 0x50b0
testl %eax, %eax
jne 0x907f
leaq -0x220(%rbp), %rdi
callq 0xacde
jmp 0x8eee
leaq -0x220(%rbp), %rdi
callq 0xa564
leaq -0xe0(%rbp), %rdi
callq 0xa156
leaq -0x180(%rbp), %rdi
callq 0x9bf8
leaq -0x1b8(%rbp), %rbx
movq %rbx, %rdi
callq 0xa210
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x8f23
callq 0x52d0
leaq -0x1e8(%rbp), %rdi
callq 0xa1c0
leaq -0x200(%rbp), %rbx
movq %rbx, %rdi
callq 0x9bf8
movq -0x20(%rbx), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x8f53
callq 0x52d0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x8f68
callq 0x52d0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x8f7a
callq 0x52d0
leaq -0x430(%rbp), %rdi
callq 0x5080
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x8f98
callq 0x52d0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x8fb0
callq 0x52d0
xorl %eax, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x5180
movq %rax, %r15
leaq 0x1a03f(%rip), %rsi     # 0x23017
movq %rax, %rdi
callq 0x55e0
movq 0x24fd9(%rip), %rsi     # 0x2dfc0
movq 0x24fba(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5520
jmp 0x90b1
movl $0x10, %edi
callq 0x5180
movq %rax, %r15
leaq 0x1a026(%rip), %rsi     # 0x23035
movq %rax, %rdi
callq 0x55e0
jmp 0x9035
movl $0x10, %edi
callq 0x5180
movq %rax, %r15
leaq 0x1a036(%rip), %rsi     # 0x23063
movq %rax, %rdi
callq 0x55e0
movq 0x24f84(%rip), %rsi     # 0x2dfc0
movq 0x24f65(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5520
movl $0x10, %edi
callq 0x5180
movq %rax, %r15
leaq 0x19fa5(%rip), %rsi     # 0x23004
movq %rax, %rdi
callq 0x55e0
movq 0x24f52(%rip), %rsi     # 0x2dfc0
movq 0x24f33(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5520
jmp 0x90b1
movl $0x10, %edi
callq 0x5180
movq %rax, %r15
leaq 0x19fa2(%rip), %rsi     # 0x23035
movq %rax, %rdi
callq 0x55e0
movq 0x24f1e(%rip), %rsi     # 0x2dfc0
movq 0x24eff(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5520
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
callq 0x5260
jmp 0x9102
jmp 0x90e3
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
callq 0x5260
jmp 0x9195
jmp 0x9148
movq %rdx, %rbx
movq %rax, %r14
jmp 0x9175
movq %rdx, %rbx
movq %rax, %r14
jmp 0x9195
jmp 0x9138
jmp 0x9183
jmp 0x9183
jmp 0x9138
movq %rdx, %rbx
movq %rax, %r14
leaq -0x220(%rbp), %rdi
callq 0x9a72
jmp 0x914e
jmp 0x9183
jmp 0x9148
jmp 0x9116
movq %rdx, %rbx
movq %rax, %r14
movq -0x220(%rbp), %rdi
leaq -0x210(%rbp), %rax
cmpq %rax, %rdi
je 0x914e
callq 0x52d0
jmp 0x914e
jmp 0x9183
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
callq 0x5260
jmp 0x9189
movq %rdx, %rbx
movq %rax, %r14
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x9163
callq 0x52d0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x9175
callq 0x52d0
leaq -0x430(%rbp), %rdi
callq 0x5080
jmp 0x9195
movq %rdx, %rbx
movq %rax, %r14
leaq -0x430(%rbp), %rdi
callq 0x9ae4
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x91a7
callq 0x52d0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x91bf
callq 0x52d0
cmpl $0x1, %ebx
jne 0x91fe
movq %r14, %rdi
callq 0x5130
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x24e0c(%rip), %rdi     # 0x2dfe8
movq %rax, %rsi
callq 0x5300
movq %rax, %rdi
callq 0x5170
callq 0x54d0
jmp 0x8fb0
movq %rax, %r14
callq 0x54d0
movq %r14, %rdi
callq 0x5570
movq %rax, %rdi
callq 0x9ad6