// File: /workspace/github_cpp_makefile_star2_O2/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 -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq -0x38(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
decl %edi
testb $0x1, %dil
jne 0x8a5f
movq %rsi, %rbx
leaq -0x420(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movslq %edi, %r12
xorl %r13d, %r13d
leaq -0x428(%rbp), %r14
cmpq %r12, %r13
jge 0x882c
movq 0x8(%rbx,%r13,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x8a2a
movq 0x10(%rbx,%r13,8), %r15
incq %rsi
movq %r14, %rdi
callq 0x8c30
movq %rax, %rdi
movq %r15, %rsi
callq 0x5600
addq $0x2, %r13
jmp 0x87f8
leaq -0x218(%rbp), %rsi
movb $0x6d, (%rsi)
leaq -0x428(%rbp), %rdi
callq 0x8c82
testq %rax, %rax
je 0x8a91
leaq -0x218(%rbp), %rsi
movb $0x6d, (%rsi)
leaq -0x428(%rbp), %rdi
callq 0x8ca6
leaq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x51d0
leaq -0x218(%rbp), %rsi
movb $0x66, (%rsi)
leaq -0x428(%rbp), %rdi
callq 0x8c82
testq %rax, %rax
je 0x8aad
leaq -0x218(%rbp), %rsi
movb $0x66, (%rsi)
leaq -0x428(%rbp), %rdi
callq 0x8ca6
leaq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x51d0
leaq -0x428(%rbp), %rdi
callq 0x9380
leaq -0x428(%rbp), %rbx
leaq -0x88(%rbp), %rsi
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x5500
movq -0x428(%rbp), %rax
addq -0x18(%rax), %rbx
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x50d0
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x58(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
leaq -0x428(%rbp), %rbx
leaq -0xa8(%rbp), %r14
leaq 0x16cf1(%rip), %r15     # 0x1f615
leaq -0x218(%rbp), %r12
leaq -0x68(%rbp), %r13
movq -0x428(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x408(%rbp,%rax)
jne 0x8972
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5070
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x8cf7
movq %r13, %rdi
movq %r12, %rsi
callq 0x5610
movq %r12, %rdi
callq 0x5170
jmp 0x892f
leaq -0x218(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x8d30
leaq -0x218(%rbp), %rdi
callq 0xa790
leaq 0x166f9(%rip), %rsi     # 0x1f08e
leaq -0x48(%rbp), %rdi
callq 0x9331
testb %al, %al
je 0x89b0
leaq -0x218(%rbp), %rdi
callq 0x9e98
jmp 0x89d4
leaq 0x166db(%rip), %rsi     # 0x1f092
leaq -0x48(%rbp), %rdi
callq 0x9331
testb %al, %al
je 0x8add
leaq -0x218(%rbp), %rdi
callq 0xa4ec
leaq -0x218(%rbp), %rdi
callq 0x9342
leaq -0x68(%rbp), %rdi
callq 0x5170
leaq -0xa8(%rbp), %rdi
callq 0x5170
leaq -0x428(%rbp), %rdi
callq 0x5080
leaq -0x48(%rbp), %rdi
callq 0x5170
leaq -0x88(%rbp), %rdi
callq 0x5170
xorl %eax, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x51a0
movq %rax, %r15
leaq 0x165db(%rip), %rsi     # 0x1f017
movq %rax, %rdi
callq 0x55e0
movq 0x25575(%rip), %rsi     # 0x2dfc0
movq 0x25556(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5530
jmp 0x8b0d
pushq $0x10
popq %rdi
callq 0x51a0
movq %rax, %r15
leaq 0x16593(%rip), %rsi     # 0x1f004
movq %rax, %rdi
callq 0x55e0
movq 0x25540(%rip), %rsi     # 0x2dfc0
movq 0x25521(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5530
jmp 0x8b0d
pushq $0x10
popq %rdi
callq 0x51a0
movq %rax, %r15
leaq 0x16592(%rip), %rsi     # 0x1f035
movq %rax, %rdi
callq 0x55e0
jmp 0x8ac7
pushq $0x10
popq %rdi
callq 0x51a0
movq %rax, %r15
leaq 0x165a4(%rip), %rsi     # 0x1f063
movq %rax, %rdi
callq 0x55e0
movq 0x254f2(%rip), %rsi     # 0x2dfc0
movq 0x254d3(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5530
pushq $0x10
popq %rdi
callq 0x51a0
movq %rax, %r15
leaq 0x16546(%rip), %rsi     # 0x1f035
movq %rax, %rdi
callq 0x55e0
movq 0x254c2(%rip), %rsi     # 0x2dfc0
movq 0x254a3(%rip), %rdx     # 0x2dfa8
movq %r15, %rdi
callq 0x5530
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
callq 0x5270
jmp 0x8b5b
jmp 0x8b6b
jmp 0x8b6b
jmp 0x8b40
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
callq 0x5270
jmp 0x8bcc
jmp 0x8b91
movq %rdx, %rbx
movq %rax, %r14
jmp 0x8bac
movq %rdx, %rbx
movq %rax, %r14
jmp 0x8bcc
jmp 0x8bba
jmp 0x8bba
jmp 0x8bba
jmp 0x8bba
jmp 0x8bba
movq %rdx, %rbx
movq %rax, %r14
leaq -0x218(%rbp), %rdi
callq 0x9342
jmp 0x8b97
jmp 0x8bba
movq %rdx, %rbx
movq %rax, %r14
movq %r15, %rdi
callq 0x5270
jmp 0x8bc0
movq %rdx, %rbx
movq %rax, %r14
leaq -0x218(%rbp), %rdi
callq 0x5170
jmp 0x8b97
jmp 0x8b91
movq %rdx, %rbx
movq %rax, %r14
leaq -0x68(%rbp), %rdi
callq 0x5170
leaq -0xa8(%rbp), %rdi
callq 0x5170
leaq -0x428(%rbp), %rdi
callq 0x5080
jmp 0x8bcc
movq %rdx, %rbx
movq %rax, %r14
leaq -0x428(%rbp), %rdi
callq 0x9380
leaq -0x48(%rbp), %rdi
callq 0x5170
leaq -0x88(%rbp), %rdi
callq 0x5170
cmpl $0x1, %ebx
jne 0x8c20
movq %r14, %rdi
callq 0x5130
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x253ea(%rip), %rdi     # 0x2dfe8
movq %rax, %rsi
callq 0x5310
movq %rax, %rdi
callq 0x5190
callq 0x54f0
jmp 0x8a16
movq %rax, %r14
callq 0x54f0
movq %r14, %rdi
callq 0x5580
movq %rax, %rdi
callq 0x9371