// File: 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
subq $0x4f0, %rsp            # imm = 0x4F0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x6610
leaq -0x50(%rbp), %rdi
callq 0x6610
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xb792
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x488(%rbp)
leaq 0x438c6(%rip), %rsi     # 0x4f004
callq 0x6860
jmp 0xb745
movq -0x488(%rbp), %rdi
movq 0x6586d(%rip), %rsi     # 0x70fc0
movq 0x6584e(%rip), %rdx     # 0x70fa8
callq 0x6760
jmp 0xbd76
movq -0x488(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x6360
jmp 0xbcd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbcd5
leaq -0x90(%rbp), %rdi
callq 0xbd80
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xb89e
movq -0x10(%rbp), %rax
movslq -0x94(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0xb840
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x490(%rbp)
leaq 0x4382b(%rip), %rsi     # 0x4f017
callq 0x6860
jmp 0xb7f3
movq -0x490(%rbp), %rdi
movq 0x657bf(%rip), %rsi     # 0x70fc0
movq 0x657a0(%rip), %rdx     # 0x70fa8
callq 0x6760
jmp 0xbd76
movq -0x490(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x6360
jmp 0xba39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xba39
movq -0x10(%rbp), %rax
movslq -0x94(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x4a0(%rbp)
incq %rsi
leaq -0x90(%rbp), %rdi
callq 0xbda0
movq %rax, -0x498(%rbp)
jmp 0xb873
movq -0x4a0(%rbp), %rsi
movq -0x498(%rbp), %rdi
callq 0x65f0
jmp 0xb888
jmp 0xb88a
movl -0x94(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x94(%rbp)
jmp 0xb7a8
movb $0x6d, -0x95(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x95(%rbp), %rsi
callq 0xbe80
movq %rax, -0x4a8(%rbp)
jmp 0xb8c1
movq -0x4a8(%rbp), %rax
cmpq $0x0, %rax
je 0xb905
movb $0x6d, -0x96(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x96(%rbp), %rsi
callq 0xbee0
movq %rax, -0x4b0(%rbp)
jmp 0xb8f1
movq -0x4b0(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x6070
jmp 0xb903
jmp 0xb966
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4b8(%rbp)
leaq 0x43712(%rip), %rsi     # 0x4f035
callq 0x6860
jmp 0xb92a
movq -0x4b8(%rbp), %rdi
movq 0x65688(%rip), %rsi     # 0x70fc0
movq 0x65669(%rip), %rdx     # 0x70fa8
callq 0x6760
jmp 0xbd76
movq -0x4b8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x6360
jmp 0xba39
movb $0x66, -0x97(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x97(%rbp), %rsi
callq 0xbe80
movq %rax, -0x4c0(%rbp)
jmp 0xb989
movq -0x4c0(%rbp), %rax
cmpq $0x0, %rax
je 0xb9cd
movb $0x66, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xbee0
movq %rax, -0x4c8(%rbp)
jmp 0xb9b9
movq -0x4c8(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x6070
jmp 0xb9cb
jmp 0xba2b
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4d0(%rbp)
leaq 0x43678(%rip), %rsi     # 0x4f063
callq 0x6860
jmp 0xb9f2
movq -0x4d0(%rbp), %rdi
movq 0x655c0(%rip), %rsi     # 0x70fc0
movq 0x655a1(%rip), %rdx     # 0x70fa8
callq 0x6760
jmp 0xbd76
movq -0x4d0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x6360
jmp 0xba39
leaq -0x90(%rbp), %rdi
callq 0xbfc0
jmp 0xba4a
leaq -0x90(%rbp), %rdi
callq 0xbfc0
jmp 0xbcd5
leaq -0x2a8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x6710
jmp 0xba61
movq -0x2a8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2a8(%rbp,%rax), %rdi
movl $0x4, %esi
callq 0x6140
jmp 0xba80
leaq -0x2c8(%rbp), %rdi
callq 0x6610
leaq -0x2e8(%rbp), %rdi
callq 0x6610
movq -0x2a8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2a8(%rbp,%rax), %rdi
callq 0x6810
movb %al, -0x4d1(%rbp)
jmp 0xbab8
movb -0x4d1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xbac9
jmp 0xbb5f
leaq -0x2a8(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x60c0
jmp 0xbade
leaq 0x43baa(%rip), %rdx     # 0x4f68f
leaq -0x308(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0xbfe0
jmp 0xbafa
leaq -0x2e8(%rbp), %rdi
leaq -0x308(%rbp), %rsi
callq 0x6590
jmp 0xbb0f
leaq -0x308(%rbp), %rdi
callq 0x62b0
jmp 0xba98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbcc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbcb1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x62b0
jmp 0xbcb1
leaq -0x478(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0xc060
jmp 0xbb74
leaq -0x478(%rbp), %rdi
callq 0x123e0
jmp 0xbb82
leaq 0x43505(%rip), %rsi     # 0x4f08e
leaq -0x50(%rbp), %rdi
callq 0xd2a0
movb %al, -0x4d2(%rbp)
jmp 0xbb9a
movb -0x4d2(%rbp), %al
testb $0x1, %al
jne 0xbba6
jmp 0xbbca
leaq -0x478(%rbp), %rdi
callq 0x110f0
jmp 0xbbb4
jmp 0xbc5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbca5
leaq 0x434c1(%rip), %rsi     # 0x4f092
leaq -0x50(%rbp), %rdi
callq 0xd2a0
movb %al, -0x4d3(%rbp)
jmp 0xbbe2
movb -0x4d3(%rbp), %al
testb $0x1, %al
jne 0xbbee
jmp 0xbbfe
leaq -0x478(%rbp), %rdi
callq 0x12070
jmp 0xbbfc
jmp 0xbc5c
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4e0(%rbp)
leaq 0x43419(%rip), %rsi     # 0x4f035
callq 0x6860
jmp 0xbc23
movq -0x4e0(%rbp), %rdi
movq 0x6538f(%rip), %rsi     # 0x70fc0
movq 0x65370(%rip), %rdx     # 0x70fa8
callq 0x6760
jmp 0xbd76
movq -0x4e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x6360
jmp 0xbca5
jmp 0xbc5e
leaq -0x478(%rbp), %rdi
callq 0xd2d0
leaq -0x2e8(%rbp), %rdi
callq 0x62b0
leaq -0x2c8(%rbp), %rdi
callq 0x62b0
leaq -0x2a8(%rbp), %rdi
callq 0x60e0
leaq -0x50(%rbp), %rdi
callq 0x62b0
leaq -0x30(%rbp), %rdi
callq 0x62b0
jmp 0xbd45
leaq -0x478(%rbp), %rdi
callq 0xd2d0
leaq -0x2e8(%rbp), %rdi
callq 0x62b0
leaq -0x2c8(%rbp), %rdi
callq 0x62b0
leaq -0x2a8(%rbp), %rdi
callq 0x60e0
leaq -0x50(%rbp), %rdi
callq 0x62b0
leaq -0x30(%rbp), %rdi
callq 0x62b0
movl -0x5c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xbd65
movq -0x58(%rbp), %rdi
callq 0x61b0
movq %rax, -0x480(%rbp)
movq -0x480(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
movq 0x652cb(%rip), %rdi     # 0x70fe8
callq 0x6450
movq %rax, -0x4e8(%rbp)
jmp 0xbd2b
movq -0x4e8(%rbp), %rdi
movq 0x65227(%rip), %rsi     # 0x70f60
callq 0x64a0
jmp 0xbd40
callq 0x66f0
xorl %eax, %eax
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x66f0
jmp 0xbd63
jmp 0xbd65
movq -0x58(%rbp), %rdi
callq 0x67c0
movq %rax, %rdi
callq 0xd310
nopw %cs:(%rax,%rax)