// File: pollow[P]MIPSClide/ass.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];
            }
            // -t (coe|plain) -o (outputfilename) -f (filename)
            if ( arg_map.count('t') ) {
                type = arg_map['t'];
            } else {
                type = "plain";
            }
            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.exceptions(fin.failbit);

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

        Assembler A(content);
        A.split();
        A.trim();
        A.format();
        A.calc_label();
        A.parse();
        A.print(type, *out);

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

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x6600
leaq -0x50(%rbp), %rdi
callq 0x6600
leaq -0x70(%rbp), %rdi
callq 0x6600
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 0xb001
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x400(%rbp)
leaq 0x3f05d(%rip), %rsi     # 0x4a004
callq 0x6840
jmp 0xafae
movq -0x400(%rbp), %rdi
movq 0x5f014(%rip), %rsi     # 0x69fd0
movq 0x5eff5(%rip), %rdx     # 0x69fb8
callq 0x6740
jmp 0xb64c
movq -0x400(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6360
jmp 0xb59c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb59c
leaq -0xb8(%rbp), %rdi
callq 0xb650
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xb113
movq -0x10(%rbp), %rax
movslq -0xbc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0xb0b5
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x408(%rbp)
leaq 0x3efbc(%rip), %rsi     # 0x4a017
callq 0x6840
jmp 0xb062
movq -0x408(%rbp), %rdi
movq 0x5ef60(%rip), %rsi     # 0x69fd0
movq 0x5ef41(%rip), %rdx     # 0x69fb8
callq 0x6740
jmp 0xb64c
movq -0x408(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6360
jmp 0xb32f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb32f
movq -0x10(%rbp), %rax
movslq -0xbc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x418(%rbp)
incq %rsi
leaq -0xb8(%rbp), %rdi
callq 0xb670
movq %rax, -0x410(%rbp)
jmp 0xb0e8
movq -0x418(%rbp), %rsi
movq -0x410(%rbp), %rdi
callq 0x65e0
jmp 0xb0fd
jmp 0xb0ff
movl -0xbc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xbc(%rbp)
jmp 0xb017
movb $0x74, -0xbd(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xbd(%rbp), %rsi
callq 0xb750
movq %rax, -0x420(%rbp)
jmp 0xb136
movq -0x420(%rbp), %rax
cmpq $0x0, %rax
je 0xb17a
movb $0x74, -0xbe(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xbe(%rbp), %rsi
callq 0xb7b0
movq %rax, -0x428(%rbp)
jmp 0xb166
movq -0x428(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x6070
jmp 0xb178
jmp 0xb18e
leaq 0x3eeb4(%rip), %rsi     # 0x4a035
leaq -0x50(%rbp), %rdi
callq 0x65e0
jmp 0xb18c
jmp 0xb18e
movb $0x66, -0xbf(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xbf(%rbp), %rsi
callq 0xb750
movq %rax, -0x430(%rbp)
jmp 0xb1b1
movq -0x430(%rbp), %rax
cmpq $0x0, %rax
je 0xb1f5
movb $0x66, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xb7b0
movq %rax, -0x438(%rbp)
jmp 0xb1e1
movq -0x438(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x6070
jmp 0xb1f3
jmp 0xb259
movl $0x10, %edi
callq 0x6220
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x440(%rbp)
leaq 0x3ee28(%rip), %rsi     # 0x4a03b
callq 0x6840
jmp 0xb21a
movq -0x440(%rbp), %rdi
movq 0x5eda8(%rip), %rsi     # 0x69fd0
movq 0x5ed89(%rip), %rdx     # 0x69fb8
callq 0x6740
jmp 0xb64c
movq -0x440(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6360
jmp 0xb32f
movb $0x6f, -0xc1(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc1(%rbp), %rsi
callq 0xb750
movq %rax, -0x448(%rbp)
jmp 0xb27c
movq -0x448(%rbp), %rax
cmpq $0x0, %rax
je 0xb316
movb $0x6f, -0xc2(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc2(%rbp), %rsi
callq 0xb7b0
movq %rax, -0x450(%rbp)
jmp 0xb2b0
movq -0x450(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x6070
jmp 0xb2c2
movl $0x200, %edi            # imm = 0x200
callq 0x6450
movq %rax, -0x458(%rbp)
jmp 0xb2d5
movq -0x458(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x10, %edx
callq 0x6860
jmp 0xb2ec
movq -0x458(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0xb321
movq -0x458(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x6410
jmp 0xb32f
movq 0x5ec83(%rip), %rax     # 0x69fa0
movq %rax, -0x78(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xb890
jmp 0xb340
leaq -0xb8(%rbp), %rdi
callq 0xb890
jmp 0xb59c
leaq -0x2d8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0x66f0
jmp 0xb357
movq -0x2d8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2d8(%rbp,%rax), %rdi
movl $0x4, %esi
callq 0x6140
jmp 0xb376
leaq -0x2f8(%rbp), %rdi
callq 0x6600
leaq -0x318(%rbp), %rdi
callq 0x6600
movq -0x2d8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2d8(%rbp,%rax), %rdi
callq 0x67f0
movb %al, -0x459(%rbp)
jmp 0xb3ae
movb -0x459(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xb3bf
jmp 0xb45e
leaq -0x2d8(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0x60c0
jmp 0xb3d4
leaq 0x3f1a0(%rip), %rdx     # 0x4a57b
leaq -0x338(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0xb8b0
jmp 0xb3f0
leaq -0x318(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x6580
jmp 0xb405
leaq -0x338(%rbp), %rdi
callq 0x62b0
jmp 0xb38e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb590
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb578
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x62b0
jmp 0xb578
leaq -0x3d0(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0xb930
jmp 0xb473
leaq -0x3d0(%rbp), %rdi
callq 0x13f80
jmp 0xb481
leaq -0x3d0(%rbp), %rdi
callq 0x13d90
jmp 0xb48f
leaq -0x3d0(%rbp), %rdi
callq 0x14120
jmp 0xb49d
leaq -0x3d0(%rbp), %rdi
callq 0x13b30
jmp 0xb4ab
leaq -0x3d0(%rbp), %rdi
callq 0x11560
jmp 0xb4b9
leaq -0x3f0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x61e0
jmp 0xb4cb
movq -0x78(%rbp), %rdx
leaq -0x3d0(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0x14550
jmp 0xb4e4
leaq -0x3f0(%rbp), %rdi
callq 0x62b0
leaq -0x3d0(%rbp), %rdi
callq 0xb990
leaq -0x318(%rbp), %rdi
callq 0x62b0
leaq -0x2f8(%rbp), %rdi
callq 0x62b0
leaq -0x2d8(%rbp), %rdi
callq 0x60e0
leaq -0x70(%rbp), %rdi
callq 0x62b0
leaq -0x50(%rbp), %rdi
callq 0x62b0
leaq -0x30(%rbp), %rdi
callq 0x62b0
jmp 0xb618
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0xb56c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x62b0
leaq -0x3d0(%rbp), %rdi
callq 0xb990
leaq -0x318(%rbp), %rdi
callq 0x62b0
leaq -0x2f8(%rbp), %rdi
callq 0x62b0
leaq -0x2d8(%rbp), %rdi
callq 0x60e0
leaq -0x70(%rbp), %rdi
callq 0x62b0
leaq -0x50(%rbp), %rdi
callq 0x62b0
leaq -0x30(%rbp), %rdi
callq 0x62b0
movl -0x84(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xb63b
movq -0x80(%rbp), %rdi
callq 0x61b0
movq %rax, -0x3f8(%rbp)
movq -0x3f8(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
movq 0x5ea00(%rip), %rdi     # 0x69ff0
callq 0x6440
movq %rax, -0x468(%rbp)
jmp 0xb5fe
movq -0x468(%rbp), %rdi
movq 0x5e964(%rip), %rsi     # 0x69f70
callq 0x6490
jmp 0xb613
callq 0x66d0
xorl %eax, %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x66d0
jmp 0xb639
jmp 0xb63b
movq -0x80(%rbp), %rdi
callq 0x67a0
movq %rax, %rdi
callq 0xb9f0
nopl (%rax)