// File: /workspace/github_cpp_makefile_star2_O3/Lupo-CalPoly[P]cpe315-thumbsim/decode.cpp
// Function: decode(MISC_Type)
MISC_Ops decode (const MISC_Type data) {
  if (data.instr.push.op == MISC_PUSH_OP) {
    // Push is complete
    if (opts.instrs) { 
      bool multiple = FALSE;
      cout << "push ";
      cout << "{";
      if (data.instr.push.reg_list & 1) {
        cout << "r0";
        multiple = TRUE;
      }
      if (data.instr.push.reg_list & 2) {
        if (multiple)
          cout << ", ";
        cout << "r1";
        multiple = TRUE;
      }
      if (data.instr.push.reg_list & 4) {
        if (multiple)
          cout << ", ";
        cout << "r2";
        multiple = TRUE;
      }
      if (data.instr.push.reg_list & 8) {
        if (multiple)
          cout << ", ";
        cout << "r3";
        multiple = TRUE;
      }
      if (data.instr.push.reg_list & 16) {
        if (multiple)
          cout << ", ";
        cout << "r4";
        multiple = TRUE;
      }
      if (data.instr.push.reg_list & 32) {
        if (multiple)
          cout << ", ";
        cout << "r5";
        multiple = TRUE;
      }
      if (data.instr.push.reg_list & 64) {
        if (multiple)
          cout << ", ";
        cout << "r6";
        multiple = TRUE;
      }
      if (data.instr.push.reg_list & 128) {
        if (multiple)
          cout << ", ";
        cout << "r7";
        multiple = TRUE;
      }
      if (data.instr.push.m) {
        if (multiple)
          cout << ", ";
        cout << "lr";
      }
      cout << "}" << endl;
    }
    return MISC_PUSH;
  }
  else if (data.instr.pop.op == MISC_POP_OP) {
    // Pop is complete
    if (opts.instrs) { 
      bool multiple = FALSE;
      cout << "pop ";
      cout << "{";
      if (data.instr.pop.reg_list & 1) {
        cout << "r0";
        multiple = TRUE;
      }
      if (data.instr.pop.reg_list & 2) {
        if (multiple)
          cout << ", ";
        cout << "r1";
        multiple = TRUE;
      }
      if (data.instr.pop.reg_list & 4) {
        if (multiple)
          cout << ", ";
        cout << "r2";
        multiple = TRUE;
      }
      if (data.instr.pop.reg_list & 8) {
        if (multiple)
          cout << ", ";
        cout << "r3";
        multiple = TRUE;
      }
      if (data.instr.pop.reg_list & 16) {
        if (multiple)
          cout << ", ";
        cout << "r4";
        multiple = TRUE;
      }
      if (data.instr.pop.reg_list & 32) {
        if (multiple)
          cout << ", ";
        cout << "r5";
        multiple = TRUE;
      }
      if (data.instr.pop.reg_list & 64) {
        if (multiple)
          cout << ", ";
        cout << "r6";
        multiple = TRUE;
      }
      if (data.instr.pop.reg_list & 128) {
        if (multiple)
          cout << ", ";
        cout << "r7";
        multiple = TRUE;
      }
      if (data.instr.pop.m) {
        if (multiple)
          cout << ", ";
        cout << "pc";
      }
      cout << "}" << endl;
    }
    return MISC_POP;
  }
  else if (data.instr.sub.op == MISC_SUB_OP) {
    // complete
    if (opts.instrs) { 
      cout << "sub sp, #";
      cout << setbase(10) << (static_cast<unsigned int>(data.instr.sub.imm)<< 2) << endl;
    } 
    return MISC_SUB;
  }
  else if (data.instr.add.op == MISC_ADD_OP) {
    // complete
    if (opts.instrs) { 
      cout << "add sp, #";
      cout << setbase(10) << (static_cast<unsigned int>(data.instr.add.imm)<< 2) << endl;
    } 
    return MISC_ADD;
  }
  else if (data.instr.class_type.type_check == ADD_SP8I_TYPE) {
    // complete
    if (opts.instrs) { 
      cout << "add sp, #" << setbase(10) << (data.instr.add.imm<<2)<< endl;
    }
    return MISC_ADD;
  }
  cout << "[ERROR] Unknown Instruction to be decoded" << endl;
  exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %r14d
movl %edi, %eax
shrl $0x9, %eax
andl $0x7, %eax
cmpw $0x6, %ax
je 0x3a43
cmpl $0x2, %eax
jne 0x3a9a
leaq 0x57e1(%rip), %rax      # 0x91d4
movl $0x6, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fd2
movq 0x55c6(%rip), %rbx      # 0x8fd0
leaq 0x2879(%rip), %rsi      # 0x628a
movl $0x5, %edx
movq %rbx, %rdi
callq 0x2170
leaq 0x286b(%rip), %rsi      # 0x6290
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2170
testb $0x1, %r14b
jne 0x3b72
xorl %eax, %eax
jmp 0x3b8c
leaq 0x578a(%rip), %rax      # 0x91d4
movl $0xb, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fd2
movq 0x556f(%rip), %rbx      # 0x8fd0
leaq 0x2847(%rip), %rsi      # 0x62af
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2170
leaq 0x2814(%rip), %rsi      # 0x6290
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2170
testb $0x1, %r14b
jne 0x3d91
xorl %eax, %eax
jmp 0x3dab
movl %r14d, %eax
shrl $0x7, %eax
andl $0x1f, %eax
je 0x3b10
cmpl $0x1, %eax
jne 0x3fe0
leaq 0x571f(%rip), %rax      # 0x91d4
movl $0x1, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fd2
movq 0x5504(%rip), %rbx      # 0x8fd0
leaq 0x27e4(%rip), %rsi      # 0x62b7
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2170
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%rbx,%rax)
andl $0x7f, %r14d
shll $0x2, %r14d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20c0
movq %rax, %rbx
jmp 0x3fab
leaq 0x56bd(%rip), %rax      # 0x91d4
xorl %r15d, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fd2
movq 0x54a5(%rip), %rbx      # 0x8fd0
leaq 0x278f(%rip), %rsi      # 0x62c1
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2170
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%rbx,%rax)
andl $0x7f, %r14d
shll $0x2, %r14d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20c0
movq %rax, %rbx
xorl %r15d, %r15d
jmp 0x3fab
movq 0x5457(%rip), %rdi      # 0x8fd0
leaq 0x2712(%rip), %rsi      # 0x6292
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x2, %r14b
je 0x3bc8
testb %al, %al
je 0x3bae
movq 0x5433(%rip), %rdi      # 0x8fd0
leaq 0x2584(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x541b(%rip), %rdi      # 0x8fd0
leaq 0x26d9(%rip), %rsi      # 0x6295
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x4, %r14b
je 0x3c04
testb %al, %al
je 0x3bea
movq 0x53f7(%rip), %rdi      # 0x8fd0
leaq 0x2548(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x53df(%rip), %rdi      # 0x8fd0
leaq 0x26a0(%rip), %rsi      # 0x6298
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x8, %r14b
je 0x3c40
testb %al, %al
je 0x3c26
movq 0x53bb(%rip), %rdi      # 0x8fd0
leaq 0x250c(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x53a3(%rip), %rdi      # 0x8fd0
leaq 0x2667(%rip), %rsi      # 0x629b
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x10, %r14b
je 0x3c7c
testb %al, %al
je 0x3c62
movq 0x537f(%rip), %rdi      # 0x8fd0
leaq 0x24d0(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5367(%rip), %rdi      # 0x8fd0
leaq 0x262e(%rip), %rsi      # 0x629e
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x20, %r14b
je 0x3cb8
testb %al, %al
je 0x3c9e
movq 0x5343(%rip), %rdi      # 0x8fd0
leaq 0x2494(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x532b(%rip), %rdi      # 0x8fd0
leaq 0x25f5(%rip), %rsi      # 0x62a1
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
movzbl %r14b, %r15d
testb $0x40, %r14b
je 0x3cf8
testb %al, %al
je 0x3cde
movq 0x5303(%rip), %rdi      # 0x8fd0
leaq 0x2454(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x52eb(%rip), %rdi      # 0x8fd0
leaq 0x25b8(%rip), %rsi      # 0x62a4
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
cmpl $0x80, %r15d
jb 0x3d37
testb %al, %al
je 0x3d1d
movq 0x52c4(%rip), %rdi      # 0x8fd0
leaq 0x2415(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x52ac(%rip), %rdi      # 0x8fd0
leaq 0x257c(%rip), %rsi      # 0x62a7
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
btl $0x8, %r14d
jae 0x3d72
testb %al, %al
je 0x3d5a
movq 0x5287(%rip), %rdi      # 0x8fd0
leaq 0x23d8(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x526f(%rip), %rdi      # 0x8fd0
leaq 0x2542(%rip), %rsi      # 0x62aa
movl $0x2, %edx
callq 0x2170
leaq 0x2534(%rip), %rsi      # 0x62ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2170
movl $0x6, %r15d
jmp 0x3fab
movq 0x5238(%rip), %rdi      # 0x8fd0
leaq 0x24f3(%rip), %rsi      # 0x6292
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x2, %r14b
je 0x3de7
testb %al, %al
je 0x3dcd
movq 0x5214(%rip), %rdi      # 0x8fd0
leaq 0x2365(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x51fc(%rip), %rdi      # 0x8fd0
leaq 0x24ba(%rip), %rsi      # 0x6295
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x4, %r14b
je 0x3e23
testb %al, %al
je 0x3e09
movq 0x51d8(%rip), %rdi      # 0x8fd0
leaq 0x2329(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x51c0(%rip), %rdi      # 0x8fd0
leaq 0x2481(%rip), %rsi      # 0x6298
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x8, %r14b
je 0x3e5f
testb %al, %al
je 0x3e45
movq 0x519c(%rip), %rdi      # 0x8fd0
leaq 0x22ed(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5184(%rip), %rdi      # 0x8fd0
leaq 0x2448(%rip), %rsi      # 0x629b
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x10, %r14b
je 0x3e9b
testb %al, %al
je 0x3e81
movq 0x5160(%rip), %rdi      # 0x8fd0
leaq 0x22b1(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5148(%rip), %rdi      # 0x8fd0
leaq 0x240f(%rip), %rsi      # 0x629e
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x20, %r14b
je 0x3ed7
testb %al, %al
je 0x3ebd
movq 0x5124(%rip), %rdi      # 0x8fd0
leaq 0x2275(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x510c(%rip), %rdi      # 0x8fd0
leaq 0x23d6(%rip), %rsi      # 0x62a1
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
movzbl %r14b, %r15d
testb $0x40, %r14b
je 0x3f17
testb %al, %al
je 0x3efd
movq 0x50e4(%rip), %rdi      # 0x8fd0
leaq 0x2235(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x50cc(%rip), %rdi      # 0x8fd0
leaq 0x2399(%rip), %rsi      # 0x62a4
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
cmpl $0x80, %r15d
jb 0x3f56
testb %al, %al
je 0x3f3c
movq 0x50a5(%rip), %rdi      # 0x8fd0
leaq 0x21f6(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x508d(%rip), %rdi      # 0x8fd0
leaq 0x235d(%rip), %rsi      # 0x62a7
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
btl $0x8, %r14d
jae 0x3f91
testb %al, %al
je 0x3f79
movq 0x5068(%rip), %rdi      # 0x8fd0
leaq 0x21b9(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5050(%rip), %rdi      # 0x8fd0
leaq 0x232d(%rip), %rsi      # 0x62b4
movl $0x2, %edx
callq 0x2170
leaq 0x2315(%rip), %rsi      # 0x62ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2170
movl $0xb, %r15d
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x4fe9(%rip), %rdi      # 0x8fd0
leaq 0x2210(%rip), %rsi      # 0x61fe
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2180