// File: /workspace/github_cpp_makefile_star2_O1/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 0x31c7
movl %r14d, %ecx
shrl $0x9, %ecx
andl $0x1f, %ecx
addl $-0xc, %ecx
cmpl $0x3, %ecx
ja 0x32a2
leaq 0x3003(%rip), %rax      # 0x6144
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x6083(%rip), %rax      # 0x91d4
movl $0x3, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x339c
movq 0x5e69(%rip), %r15      # 0x8fd0
leaq 0x307c(%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 0x30b7(%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 0x3247
xorl %ebx, %ebx
jmp 0x339c
leaq 0x5fff(%rip), %rax      # 0x91d4
movl $0x5, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x339c
movq 0x5de5(%rip), %r15      # 0x8fd0
leaq 0x2ff8(%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 0x3033(%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 0x30a3(%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 0x339c
movl $0x6, %ebx
jmp 0x339c
movl $0x4, %ebx
jmp 0x339c
movzwl %ax, %eax
addl $-0x4, %eax
cmpl $0x3, %eax
ja 0x33a7
leaq 0x2e9c(%rip), %rcx      # 0x6154
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5f0c(%rip), %rax      # 0x91d4
movl $0x7, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x339c
movq 0x5cf2(%rip), %r15      # 0x8fd0
leaq 0x2f12(%rip), %rsi      # 0x61f7
jmp 0x330b
leaq 0x5ee6(%rip), %rax      # 0x91d4
movl $0x9, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x339c
movq 0x5ccc(%rip), %r15      # 0x8fd0
leaq 0x2edf(%rip), %rsi      # 0x61ea
movl $0x6, %edx
jmp 0x3341
movl $0xa, %ebx
jmp 0x339c
leaq 0x5eb1(%rip), %rax      # 0x91d4
movl $0x8, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x339c
movq 0x5c9b(%rip), %r15      # 0x8fd0
leaq 0x2eb5(%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 0x2f7e(%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 0x5c22(%rip), %rdi      # 0x8fd0
leaq 0x2e49(%rip), %rsi      # 0x61fe
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2180