// File: /workspace/github_cpp_makefile_star2_O1/pollow[P]MIPSClide/instruction.cpp
// Function: Instruction::compile()
unsigned int Instruction::compile() {
    unsigned long result = 0;
    if ( !opcode.count(command) ) {
        throw invalid_argument("No such command"); 
    }
    switch ( type ) {
        case 'R':
            result += opcode[command] << 26;
            if (reg_num == 1) {
                if ( !regs.count(reg1) ) {
                    throw invalid_argument("No such register"); 
                }
                if ( command == "mfhi" || command == "mflo" ) {
                    result += regs[reg1] << 11;
                } else {
                    result += regs[reg1] << 21;
                }
            } else if ( reg_num == 2 ) {
                if ( !(regs.count(reg1) && regs.count(reg2)) ) {
                    throw invalid_argument("No such register"); 
                }
                if(has_shamt) {
                    result += (regs[reg1] << 11) + (regs[reg2] << 16);
                    result += shamt << 6;
                } else if ( command == "jarl" ) {
                    result += (regs[reg1] << 21) + (regs[reg2] << 11);
                } else if ( command == "clo" || command == "clz" ) {
                    result += (regs[reg1] << 11) + (regs[reg2] << 21);
                } else {
                    result += (regs[reg1] << 21) + (regs[reg2] << 16);
                }
            } else {
                if ( !(regs.count(reg1) && regs.count(reg2) && regs.count(reg3)) ) {
                    throw invalid_argument("No such register"); 
                }
                result += (regs[reg1] << 11) + (regs[reg2] << 21) + (regs[reg3] << 16);
            }
            result += func[command];
            break;
        case 'I':
            result += opcode[command] << 26;
            if (reg_num == 1) {
                if (command == "lui") result += regs[reg1] << 16;
                else result += regs[reg1] << 21;
            }
            if (reg_num == 2) {
                if (command == "beq" || command == "bne") {
                    result += regs[reg2] << 16;
                    result += regs[reg1] << 21;
                } else {
                    result += regs[reg1] << 16;
                    result += regs[reg2] << 21;
                }
            }
            result += imm;
            break;
        case 'J':
            result += opcode[command] << 26;
            result += imm;
            break;
    }

    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0xecd8(%rip), %rdi      # 0x2b970
movq %rbx, %rsi
callq 0x20196
leaq 0xecd1(%rip), %rcx      # 0x2b978
cmpq %rcx, %rax
je 0x1d0b6
movzbl 0x90(%rbx), %eax
cmpl $0x49, %eax
je 0x1cd91
cmpl $0x4a, %eax
je 0x1cd6f
cmpl $0x52, %eax
jne 0x1cde9
leaq 0xec97(%rip), %rdi      # 0x2b970
movq %rbx, %rsi
callq 0x1f7fc
movl (%rax), %r13d
shll $0x1a, %r13d
movl 0x80(%rbx), %r15d
leaq 0x20(%rbx), %r14
leaq 0xee26(%rip), %rdi      # 0x2bb20
movq %r14, %rsi
callq 0x20196
cmpl $0x2, %r15d
je 0x1cdf0
cmpl $0x1, %r15d
jne 0x1ce6f
leaq 0xee0b(%rip), %rcx      # 0x2bb28
cmpq %rcx, %rax
je 0x1d124
leaq 0x55cd(%rip), %rsi      # 0x222fa
movq %rbx, %rdi
callq 0x50b0
testl %eax, %eax
je 0x1cf03
leaq 0x55bb(%rip), %rsi      # 0x222ff
movq %rbx, %rdi
callq 0x50b0
testl %eax, %eax
je 0x1cf03
leaq 0xedc5(%rip), %rdi      # 0x2bb20
movq %r14, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0x15, %r14d
jmp 0x1cf19
leaq 0xebfa(%rip), %rdi      # 0x2b970
movq %rbx, %rsi
callq 0x1f7fc
movl (%rax), %ecx
shll $0x1a, %ecx
movzwl 0x88(%rbx), %eax
orl %ecx, %eax
jmp 0x1d070
leaq 0xebd8(%rip), %rdi      # 0x2b970
movq %rbx, %rsi
callq 0x1f7fc
movl (%rax), %r12d
shll $0x1a, %r12d
cmpl $0x1, 0x80(%rbx)
jne 0x1cf27
leaq 0x5561(%rip), %rsi      # 0x2231c
movq %rbx, %rdi
callq 0x50b0
movl %eax, %r14d
leaq 0x20(%rbx), %rsi
leaq 0xed4f(%rip), %rdi      # 0x2bb20
callq 0x1f7fc
movl (%rax), %eax
testl %r14d, %r14d
je 0x1cf21
shll $0x15, %eax
jmp 0x1cf24
xorl %eax, %eax
jmp 0x1d070
leaq 0xed31(%rip), %r12      # 0x2bb28
cmpq %r12, %rax
je 0x1d106
leaq 0x40(%rbx), %r15
leaq 0xed15(%rip), %rdi      # 0x2bb20
movq %r15, %rsi
callq 0x20196
cmpq %r12, %rax
je 0x1d106
cmpb $0x1, 0x91(%rbx)
jne 0x1cfbc
leaq 0xecf0(%rip), %r12      # 0x2bb20
movq %r12, %rdi
movq %r14, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0xb, %r14d
movq %r12, %rdi
movq %r15, %rsi
callq 0x1f7fc
movl (%rax), %eax
shll $0x10, %eax
addl %r14d, %eax
addq %r13, %rax
movl 0x86(%rbx), %r14d
andl $0x1f, %r14d
shll $0x6, %r14d
orq %rax, %r14
jmp 0x1d05c
movq %r13, -0x30(%rbp)
leaq 0xecae(%rip), %r13      # 0x2bb28
cmpq %r13, %rax
je 0x1d0e8
leaq 0x40(%rbx), %r15
leaq 0xec92(%rip), %rdi      # 0x2bb20
movq %r15, %rsi
callq 0x20196
cmpq %r13, %rax
je 0x1d0e8
leaq 0x60(%rbx), %r12
leaq 0xec76(%rip), %rdi      # 0x2bb20
movq %r12, %rsi
callq 0x20196
cmpq %r13, %rax
je 0x1d0e8
leaq 0xec5e(%rip), %r13      # 0x2bb20
movq %r13, %rdi
movq %r14, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0xb, %r14d
movq %r13, %rdi
movq %r15, %rsi
callq 0x1f7fc
movl (%rax), %r15d
shll $0x15, %r15d
addl %r14d, %r15d
movq %r13, %rdi
movq %r12, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0x10, %r14d
addl %r15d, %r14d
jmp 0x1d058
leaq 0xec16(%rip), %rdi      # 0x2bb20
movq %r14, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0xb, %r14d
addq %r13, %r14
jmp 0x1d05c
shll $0x10, %eax
addq %rax, %r12
cmpl $0x2, 0x80(%rbx)
jne 0x1cfad
leaq 0x539b(%rip), %rsi      # 0x222d2
movq %rbx, %rdi
callq 0x50b0
testl %eax, %eax
je 0x1cf72
leaq 0x538c(%rip), %rsi      # 0x222d6
movq %rbx, %rdi
callq 0x50b0
xorl %r14d, %r14d
xorl %esi, %esi
testl %eax, %eax
setne %r14b
sete %sil
shll $0x5, %esi
addq $0x20, %rsi
shll $0x5, %r14d
addq $0x20, %r14
jmp 0x1cf7d
movl $0x20, %r14d
movl $0x40, %esi
addq %rbx, %rsi
leaq 0xeb99(%rip), %r15      # 0x2bb20
movq %r15, %rdi
callq 0x1f7fc
movl (%rax), %eax
shll $0x10, %eax
addq %rax, %r12
addq %rbx, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x1f7fc
movl (%rax), %eax
shll $0x15, %eax
addq %rax, %r12
movzwl 0x88(%rbx), %eax
addq %r12, %rax
jmp 0x1d070
leaq 0x53dc(%rip), %rsi      # 0x2239f
movq %rbx, %rdi
callq 0x50b0
testl %eax, %eax
je 0x1d07f
movq %r13, -0x30(%rbp)
leaq 0x532a(%rip), %rsi      # 0x22308
movq %rbx, %rdi
callq 0x50b0
testl %eax, %eax
je 0x1d02a
leaq 0x531b(%rip), %rsi      # 0x2230c
movq %rbx, %rdi
callq 0x50b0
testl %eax, %eax
je 0x1d02a
leaq 0xeb1c(%rip), %r12      # 0x2bb20
movq %r12, %rdi
movq %r14, %rsi
callq 0x1f7fc
movl (%rax), %r13d
shll $0x15, %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0x10, %r14d
jmp 0x1d055
leaq 0xeaef(%rip), %r12      # 0x2bb20
movq %r12, %rdi
movq %r14, %rsi
callq 0x1f7fc
movl (%rax), %r13d
shll $0xb, %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0x15, %r14d
addl %r13d, %r14d
addq -0x30(%rbp), %r14
leaq 0xea8d(%rip), %rdi      # 0x2baf0
movq %rbx, %rsi
callq 0x1f7fc
movl (%rax), %eax
addq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xea9a(%rip), %rdi      # 0x2bb20
movq %r14, %rsi
callq 0x1f7fc
movq %r13, %r12
movl (%rax), %r13d
shll $0x15, %r13d
leaq 0xea81(%rip), %rdi      # 0x2bb20
movq %r15, %rsi
callq 0x1f7fc
movl (%rax), %r14d
shll $0xb, %r14d
addl %r13d, %r14d
addq %r12, %r14
jmp 0x1d05c
movl $0x10, %edi
callq 0x5180
movq %rax, %rbx
leaq 0x52b4(%rip), %rsi      # 0x2237e
movq %rax, %rdi
callq 0x55d0
movq 0xdef7(%rip), %rsi      # 0x2afd0
movq 0xded8(%rip), %rdx      # 0x2afb8
movq %rbx, %rdi
callq 0x5510
movl $0x10, %edi
callq 0x5180
movq %rax, %rbx
leaq 0x5292(%rip), %rsi      # 0x2238e
movq %rax, %rdi
callq 0x55d0
jmp 0x1d0d2
movl $0x10, %edi
callq 0x5180
movq %rax, %rbx
leaq 0x5274(%rip), %rsi      # 0x2238e
movq %rax, %rdi
callq 0x55d0
jmp 0x1d0d2
movl $0x10, %edi
callq 0x5180
movq %rax, %rbx
leaq 0x5256(%rip), %rsi      # 0x2238e
movq %rax, %rdi
callq 0x55d0
jmp 0x1d0d2
jmp 0x1d148
jmp 0x1d148
jmp 0x1d148
movq %rax, %r14
movq %rbx, %rdi
callq 0x5260
movq %r14, %rdi
callq 0x5560
nop