// File: /workspace/github_cpp_makefile_star2_O3/Lupo-CalPoly[P]cpe315-thumbsim/decode.cpp
// Function: decode(ALU_Type)
ALU_Ops decode (const ALU_Type data) {
  if (data.instr.lsli.op == ALU_LSLI_OP) {
    // 315: insert code here to print lsls instruction
    return ALU_LSLI;
  }
  else if (data.instr.addr.op == ALU_ADDR_OP) {
    if (opts.instrs) { 
      cout << "adds r" << data.instr.addr.rd  << ", r" << data.instr.addr.rn << ", r" << data.instr.addr.rm << endl;
    }
    return ALU_ADDR;
  }
  else if (data.instr.subr.op == ALU_SUBR_OP) {
    // 315: insert code here to print subs instruction
    return ALU_SUBR;
  }
  else if (data.instr.add3i.op == ALU_ADD3I_OP) {
    // complete
    if (opts.instrs) { 
      cout << "adds r" << data.instr.add3i.rd << ", r" << data.instr.add3i.rn << ", #" << data.instr.add3i.imm << endl;
    }
    return ALU_ADD3I;
  }
  else if (data.instr.sub3i.op == ALU_SUB3I_OP) {
    // 315: insert code here to print subs instruction
    return ALU_SUB3I;
  }
  else if (data.instr.add8i.op == ALU_ADD8I_OP) {
    // complete
    if (opts.instrs) { 
      cout << "adds r" << data.instr.add8i.rdn << ", #" << setbase(10) << data.instr.add8i.imm << endl;
    }
    return ALU_ADD8I;
  }
  else if (data.instr.sub8i.op == ALU_SUB8I_OP) {
    // 315: insert code here to print subs instruction
    return ALU_SUB8I;
  }
  else if (data.instr.cmp.op == ALU_CMP_OP) { 
    // complete
    if (opts.instrs) { 
      cout << "cmp r" << data.instr.cmp.rdn << ", #" << setbase(10) << data.instr.cmp.imm << endl;
    }
    return ALU_CMP;
  }
  else if (data.instr.mov.op == ALU_MOV_OP) { 
    // complete
    if (opts.instrs) { 
      cout << "movs r" << data.instr.mov.rdn << ", #" << setbase(10) << (data.instr.mov.imm) << endl;
    }
    return ALU_MOV;
  }
  cout << "[ERROR] Unknown Instruction to be decoded" << endl;
  exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edi, %r14d
movzwl %r14w, %eax
shrl $0xb, %eax
andw $0x7, %ax
je 0x31bf
movl %r14d, %ecx
shrl $0x9, %ecx
andl $0x1f, %ecx
addl $-0xc, %ecx
cmpl $0x3, %ecx
ja 0x329a
leaq 0x300b(%rip), %rax      # 0x6144
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x608b(%rip), %rax      # 0x91d4
movl $0x3, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x3394
movq 0x5e71(%rip), %r15      # 0x8fd0
leaq 0x3084(%rip), %rsi      # 0x61ea
movl $0x6, %edx
movq %r15, %rdi
callq 0x2170
movl %r14d, %esi
andl $0x7, %esi
movq %r15, %rdi
callq 0x20c0
movq %rax, %r15
leaq 0x30bf(%rip), %r12      # 0x624a
movl $0x3, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2170
movl %r14d, %esi
shrl $0x3, %esi
andl $0x7, %esi
movq %r15, %rdi
callq 0x20c0
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
movq %r12, %rsi
jmp 0x323f
xorl %ebx, %ebx
jmp 0x3394
leaq 0x6007(%rip), %rax      # 0x91d4
movl $0x5, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x3394
movq 0x5ded(%rip), %r15      # 0x8fd0
leaq 0x3000(%rip), %rsi      # 0x61ea
movl $0x6, %edx
movq %r15, %rdi
callq 0x2170
movl %r14d, %esi
andl $0x7, %esi
movq %r15, %rdi
callq 0x20c0
movq %rax, %r15
leaq 0x303b(%rip), %rsi      # 0x624a
movl $0x3, %edx
movq %rax, %rdi
callq 0x2170
movl %r14d, %esi
shrl $0x3, %esi
andl $0x7, %esi
movq %r15, %rdi
callq 0x20c0
movq %rax, %r15
leaq 0x30ab(%rip), %rsi      # 0x62e2
movl $0x3, %edx
movq %rax, %rdi
callq 0x2170
shrl $0x6, %r14d
andl $0x7, %r14d
movq %r15, %rdi
movq %r14, %rsi
callq 0x20c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
jmp 0x3394
movl $0x6, %ebx
jmp 0x3394
movl $0x4, %ebx
jmp 0x3394
movzwl %ax, %eax
addl $-0x4, %eax
cmpl $0x3, %eax
ja 0x339f
leaq 0x2ea4(%rip), %rcx      # 0x6154
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5f14(%rip), %rax      # 0x91d4
movl $0x7, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x3394
movq 0x5cfa(%rip), %r15      # 0x8fd0
leaq 0x2f1a(%rip), %rsi      # 0x61f7
jmp 0x3303
leaq 0x5eee(%rip), %rax      # 0x91d4
movl $0x9, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x3394
movq 0x5cd4(%rip), %r15      # 0x8fd0
leaq 0x2ee7(%rip), %rsi      # 0x61ea
movl $0x6, %edx
jmp 0x3339
movl $0xa, %ebx
jmp 0x3394
leaq 0x5eb9(%rip), %rax      # 0x91d4
movl $0x8, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x3394
movq 0x5ca3(%rip), %r15      # 0x8fd0
leaq 0x2ebd(%rip), %rsi      # 0x61f1
movl $0x5, %edx
movq %r15, %rdi
callq 0x2170
movl %r14d, %esi
shrl $0x8, %esi
andl $0x7, %esi
movq %r15, %rdi
callq 0x20c0
movq %rax, %r15
leaq 0x2f86(%rip), %rsi      # 0x62e2
movl $0x3, %edx
movq %rax, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rax
movl 0x18(%r15,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r15,%rax)
movzbl %r14b, %esi
movq %r15, %rdi
callq 0x20c0
movq %rax, %rdi
callq 0x2090
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x5c2a(%rip), %rdi      # 0x8fd0
leaq 0x2e51(%rip), %rsi      # 0x61fe
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2180