// File: /workspace/github_cpp_makefile_star2_O3/Lupo-CalPoly[P]cpe315-thumbsim/decode.cpp
// Function: decode(SP_Type)
SP_Ops decode (const SP_Type data) {
  if (data.instr.mov.op == 2) {
    if (opts.instrs) { 
      cout << "mov";
      if (data.instr.mov.d) {
        // These two cases handle stack pointer printing
        if (data.instr.mov.rd == 5) {
          cout << " sp, r" << setbase(10) << data.instr.mov.rm << endl;
        }
        else if (data.instr.mov.rm == 13) {
          cout << " r" << setbase(10) << (8+data.instr.mov.rd) << ", sp" << endl;
        }
        // this case is for registers greater than r7 that aren't sp
        else {
          cout << " r" << setbase(10) << (8+data.instr.mov.rd) << ", r" << setbase(10) << data.instr.mov.rm << endl;
        }
      }
      // another stack pointer case
      else if (data.instr.mov.rm == 13) {
        cout << " r" << data.instr.mov.rd << ", sp" << endl;
      }
      else {
        cout << " r" << setbase(10) << data.instr.mov.rd << ", r" << data.instr.mov.rm << endl;
      }
    }
    return SP_MOV;
  }
  else if (data.instr.add.op == 0) {
    // Here you'll need to SP_ADD similar to above
    return SP_ADD;
  }
  else if (data.instr.cmp.op == 1) {
    // Here you'll need to SP_CMP similar to above
    return SP_CMP;
  }
  else {
    cerr << "UNKNOWN SP TYPE -- Exiting" << endl;
    exit(1);
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edi, %ebx
shrl $0x8, %ebx
andl $0x3, %ebx
leaq 0x2d49(%rip), %rax      # 0x6164
movslq (%rax,%rbx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0x1, %ebx
jmp 0x3639
leaq 0x5d9f(%rip), %rax      # 0x91d4
movl $0x2, %ebx
cmpb $0x1, 0x2(%rax)
jne 0x3639
movl %edi, %r14d
movq 0x5b82(%rip), %r15      # 0x8fd0
leaq 0x2dee(%rip), %rsi      # 0x6243
movl $0x3, %edx
movq %r15, %rdi
callq 0x2170
movl %r14d, %r12d
testb %r14b, %r14b
js 0x34c6
shrl $0x3, %r12d
andl $0xf, %r12d
movq 0x5b57(%rip), %r15      # 0x8fd0
leaq 0x2dcb(%rip), %rsi      # 0x624b
movl $0x2, %edx
movq %r15, %rdi
callq 0x2170
cmpw $0xd, %r12w
jne 0x3513
andl $0x7, %r14d
movq 0x5b31(%rip), %rdi      # 0x8fd0
movq %r14, %rsi
callq 0x20c0
movq %rax, %r14
leaq 0x2d9d(%rip), %rsi      # 0x624e
movl $0x4, %edx
movq %rax, %rdi
callq 0x2170
movq (%r14), %rax
jmp 0x3615
andl $0x7, %r12d
cmpw $0x5, %r12w
jne 0x355c
leaq 0x2d6b(%rip), %rsi      # 0x6247
movl $0x6, %edx
movq %r15, %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)
shrl $0x3, %r14d
andl $0xf, %r14d
movq %r15, %rdi
movq %r14, %rsi
jmp 0x360a
movq (%r15), %rax
movq -0x18(%rax), %rax
movl 0x18(%r15,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r15,%rax)
andl $0x7, %r14d
movq %r15, %rdi
movq %r14, %rsi
callq 0x20c0
movq %rax, %r14
leaq 0x2d07(%rip), %rsi      # 0x624a
movl $0x3, %edx
movq %rax, %rdi
callq 0x2170
movzwl %r12w, %esi
movq %r14, %rdi
jmp 0x360a
shrl $0x3, %r14d
andl $0xf, %r14d
leaq 0x2ce0(%rip), %rsi      # 0x624b
movl $0x2, %edx
movq %r15, %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)
movzwl %r12w, %esi
orl $0x8, %esi
movq %r15, %rdi
callq 0x2210
movq %rax, %r15
cmpw $0xd, %r14w
jne 0x35d8
leaq 0x2c9f(%rip), %rsi      # 0x624e
movl $0x4, %edx
movq %r15, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %r15, %rdi
jmp 0x362c
leaq 0x2c6b(%rip), %rsi      # 0x624a
movl $0x3, %edx
movq %r15, %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)
movzwl %r14w, %esi
movq %r15, %rdi
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
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x59a5(%rip), %rdi      # 0x8ff0
leaq 0x2c01(%rip), %rsi      # 0x6253
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2180