// File: Lupo-CalPoly[P]cpe315-thumbsim/decode.cpp
// Function: decode(ALL_Types)
Thumb_Types decode (const ALL_Types data) {
  if (data.type.alu.instr.class_type.type_check == ALU_TYPE) {
    return ALU;
  }
  else if (data.type.dp.instr.class_type.type_check == DP_TYPE) {
    return DP;
  }
  else if (data.type.sp.instr.class_type.type_check == SP_TYPE) {
    return SPECIAL;
  }
  else if (data.type.uncond.instr.class_type.type_check == UNCOND_TYPE) {
    return UNCOND;
  }
  else if (data.type.bl.instr.class_type.type_check == BL_TYPE) {
    return BL;
  }
  else if (data.type.misc.instr.class_type.type_check == MISC_TYPE) {
    return MISC;
  }
  else if (data.type.cond.instr.class_type.type_check == COND_TYPE) {
    return COND;
  }
  else if (data.type.ldm.instr.class_type.type_check == LDM_TYPE) {
    return LDM;
  }
  else if (data.type.stm.instr.class_type.type_check == STM_TYPE) {
    return STM;
  }
  else if (data.type.ldrl.instr.class_type.type_check == LDRL_TYPE) {
    return LDRL;
  }
  else if (data.type.addsp.instr.class_type.type_check == ADD_SP_TYPE) {
    return ADD_SP;
  }
  else {
    if (data.type.ld_st.instr.class_type.opA == LD_ST_REG_OPA) {
    }
    else if (data.type.ld_st.instr.class_type.opA == LD_ST_IMM_OPA) {
    }
    else if (data.type.ld_st.instr.class_type.opA == LD_ST_IMMB_OPA) {
    }
    else if (data.type.ld_st.instr.class_type.opA == LD_ST_IMMH_OPA) {
    }
    else if (data.type.ld_st.instr.class_type.opA == LD_ST_IMMSP_OPA) {
    }
    else {
      cout << "NO TYPE FOUND" << endl;
      return ERROR_TYPE;
    }
    return LD_ST;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movw %di, %ax
movw %ax, -0x6(%rbp)
movw -0x6(%rbp), %ax
shrw $0xe, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x659b
movl $0x0, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xa, %ax
movzwl %ax, %eax
cmpl $0x10, %eax
jne 0x65b7
movl $0x1, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xa, %ax
movzwl %ax, %eax
cmpl $0x11, %eax
jne 0x65d3
movl $0x2, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xb, %ax
movzwl %ax, %eax
cmpl $0x1c, %eax
jne 0x65ef
movl $0x6, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xb, %ax
movzwl %ax, %eax
cmpl $0x1e, %eax
jne 0x660b
movl $0xb, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0xb, %eax
jne 0x6627
movl $0x4, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0xd, %eax
jne 0x6643
movl $0x5, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xb, %ax
movzwl %ax, %eax
cmpl $0x19, %eax
jne 0x665f
movl $0x7, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xb, %ax
movzwl %ax, %eax
cmpl $0x18, %eax
jne 0x667b
movl $0x8, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xb, %ax
movzwl %ax, %eax
cmpl $0x9, %eax
jne 0x6697
movl $0x9, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xb, %ax
movzwl %ax, %eax
cmpl $0x15, %eax
jne 0x66b3
movl $0xa, -0x4(%rbp)
jmp 0x6747
movw -0x6(%rbp), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0x5, %eax
jne 0x66c5
jmp 0x6740
movw -0x6(%rbp), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0x6, %eax
jne 0x66d7
jmp 0x673e
movw -0x6(%rbp), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0x7, %eax
jne 0x66e9
jmp 0x673c
movw -0x6(%rbp), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0x8, %eax
jne 0x66fb
jmp 0x673a
movw -0x6(%rbp), %ax
shrw $0xc, %ax
movzwl %ax, %eax
cmpl $0x9, %eax
jne 0x670d
jmp 0x6738
movq 0xe8b4(%rip), %rdi      # 0x14fc8
leaq 0x7a7d(%rip), %rsi      # 0xe198
callq 0x21d0
movq %rax, %rdi
movq 0xe886(%rip), %rsi      # 0x14fb0
callq 0x2200
movl $0xc, -0x4(%rbp)
jmp 0x6747
jmp 0x673a
jmp 0x673c
jmp 0x673e
jmp 0x6740
movl $0x3, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq