// File: pollow[P]MIPSClide/dis.cpp
// Function: main
int main(int argc, char *argv[]) {
    try {
        string filename, type, outputfile;
        ostream *out;
        argv++;
        argc--;
        if ( argc % 2 ) {
            throw invalid_argument("Invalid 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];
            }
            // -o (outputfilename) -f (filename)
            if ( arg_map.count('f') ) {
                filename = arg_map['f'];
            } else {
                throw invalid_argument("File should be specified with -f filename.");
            }
            if ( arg_map.count('o') ) {
                outputfile = arg_map['o'];
                out = new ofstream(outputfile, ios::out);
            } else {
                out = &cout;
            }
        }

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

        unsigned int a = 0;
        vector<unsigned int> inst;
        while(fin >> a) {
            inst.push_back(a);
        }
        Disassembler D(inst);
        D.reverse();
        D.print(*out);

    } catch (exception &err) {
        cerr << err.what() << endl;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3d0, %rsp            # imm = 0x3D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x65f0
leaq -0x50(%rbp), %rdi
callq 0x65f0
leaq -0x70(%rbp), %rdi
callq 0x65f0
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 0xafe1
movl $0x10, %edi
callq 0x6210
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x368(%rbp)
leaq 0x3f07d(%rip), %rsi     # 0x4a004
callq 0x6820
jmp 0xaf8e
movq -0x368(%rbp), %rdi
movq 0x60034(%rip), %rsi     # 0x6afd0
movq 0x60015(%rip), %rdx     # 0x6afb8
callq 0x6730
jmp 0xb501
movq -0x368(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6350
jmp 0xb451
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb451
leaq -0xb8(%rbp), %rdi
callq 0xb510
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xb0f3
movq -0x10(%rbp), %rax
movslq -0xbc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0xb095
movl $0x10, %edi
callq 0x6210
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x370(%rbp)
leaq 0x3efdc(%rip), %rsi     # 0x4a017
callq 0x6820
jmp 0xb042
movq -0x370(%rbp), %rdi
movq 0x5ff80(%rip), %rsi     # 0x6afd0
movq 0x5ff61(%rip), %rdx     # 0x6afb8
callq 0x6730
jmp 0xb501
movq -0x370(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6350
jmp 0xb294
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb294
movq -0x10(%rbp), %rax
movslq -0xbc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x380(%rbp)
incq %rsi
leaq -0xb8(%rbp), %rdi
callq 0xb530
movq %rax, -0x378(%rbp)
jmp 0xb0c8
movq -0x380(%rbp), %rsi
movq -0x378(%rbp), %rdi
callq 0x65d0
jmp 0xb0dd
jmp 0xb0df
movl -0xbc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xbc(%rbp)
jmp 0xaff7
movb $0x66, -0xbd(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xbd(%rbp), %rsi
callq 0xb610
movq %rax, -0x388(%rbp)
jmp 0xb116
movq -0x388(%rbp), %rax
cmpq $0x0, %rax
je 0xb15a
movb $0x66, -0xbe(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xbe(%rbp), %rsi
callq 0xb670
movq %rax, -0x390(%rbp)
jmp 0xb146
movq -0x390(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x6070
jmp 0xb158
jmp 0xb1be
movl $0x10, %edi
callq 0x6210
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x398(%rbp)
leaq 0x3eebd(%rip), %rsi     # 0x4a035
callq 0x6820
jmp 0xb17f
movq -0x398(%rbp), %rdi
movq 0x5fe43(%rip), %rsi     # 0x6afd0
movq 0x5fe24(%rip), %rdx     # 0x6afb8
callq 0x6730
jmp 0xb501
movq -0x398(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6350
jmp 0xb294
movb $0x6f, -0xbf(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xbf(%rbp), %rsi
callq 0xb610
movq %rax, -0x3a0(%rbp)
jmp 0xb1e1
movq -0x3a0(%rbp), %rax
cmpq $0x0, %rax
je 0xb27b
movb $0x6f, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xb670
movq %rax, -0x3a8(%rbp)
jmp 0xb215
movq -0x3a8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x6070
jmp 0xb227
movl $0x200, %edi            # imm = 0x200
callq 0x6440
movq %rax, -0x3b0(%rbp)
jmp 0xb23a
movq -0x3b0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x10, %edx
callq 0x6840
jmp 0xb251
movq -0x3b0(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0xb286
movq -0x3b0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6400
jmp 0xb294
movq 0x5fd1e(%rip), %rax     # 0x6afa0
movq %rax, -0x78(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xb750
jmp 0xb2a5
leaq -0xb8(%rbp), %rdi
callq 0xb750
jmp 0xb451
leaq -0x2d0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x66e0
jmp 0xb2bc
xorl %edi, %edi
callq 0xb770
movl %eax, -0x3b4(%rbp)
jmp 0xb2cb
movl -0x3b4(%rbp), %eax
movl %eax, -0x2d4(%rbp)
movl -0x2d4(%rbp), %esi
leaq -0x2d0(%rbp), %rdi
callq 0x65b0
jmp 0xb2eb
movq -0x2d0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2d0(%rbp,%rax), %rdi
movl $0x4, %esi
callq 0x6130
jmp 0xb30a
movl $0x0, -0x2d8(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0xb790
leaq -0x2d0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0x6080
movq %rax, -0x3c0(%rbp)
jmp 0xb33c
movq -0x3c0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x6550
movb %al, -0x3c1(%rbp)
jmp 0xb35a
movb -0x3c1(%rbp), %al
testb $0x1, %al
jne 0xb366
jmp 0xb3a5
leaq -0x2f0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0xb7b0
jmp 0xb37b
jmp 0xb320
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb445
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb439
leaq -0x358(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
callq 0xb820
jmp 0xb3ba
leaq -0x358(%rbp), %rdi
callq 0xead0
jmp 0xb3c8
movq -0x78(%rbp), %rsi
leaq -0x358(%rbp), %rdi
callq 0xf1b0
jmp 0xb3da
leaq -0x358(%rbp), %rdi
callq 0xb870
leaq -0x2f0(%rbp), %rdi
callq 0xb8b0
leaq -0x2d0(%rbp), %rdi
callq 0x60d0
leaq -0x70(%rbp), %rdi
callq 0x62a0
leaq -0x50(%rbp), %rdi
callq 0x62a0
leaq -0x30(%rbp), %rdi
callq 0x62a0
jmp 0xb4cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x358(%rbp), %rdi
callq 0xb870
leaq -0x2f0(%rbp), %rdi
callq 0xb8b0
leaq -0x2d0(%rbp), %rdi
callq 0x60d0
leaq -0x70(%rbp), %rdi
callq 0x62a0
leaq -0x50(%rbp), %rdi
callq 0x62a0
leaq -0x30(%rbp), %rdi
callq 0x62a0
movl -0x84(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xb4f0
movq -0x80(%rbp), %rdi
callq 0x61a0
movq %rax, -0x360(%rbp)
movq -0x360(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
movq 0x5fb4b(%rip), %rdi     # 0x6aff0
callq 0x6430
movq %rax, -0x3d0(%rbp)
jmp 0xb4b3
movq -0x3d0(%rbp), %rdi
movq 0x5faaf(%rip), %rsi     # 0x6af70
callq 0x6480
jmp 0xb4c8
callq 0x66c0
xorl %eax, %eax
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x66c0
jmp 0xb4ee
jmp 0xb4f0
movq -0x80(%rbp), %rdi
callq 0x6790
movq %rax, %rdi
callq 0xb910
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)