// File: /workspace/github_cpp_makefile_star2_O1/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 0x3a4b
cmpl $0x2, %eax
jne 0x3aa2
leaq 0x57d9(%rip), %rax      # 0x91d4
movl $0x6, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fda
movq 0x55be(%rip), %rbx      # 0x8fd0
leaq 0x2871(%rip), %rsi      # 0x628a
movl $0x5, %edx
movq %rbx, %rdi
callq 0x2170
leaq 0x2863(%rip), %rsi      # 0x6290
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2170
testb $0x1, %r14b
jne 0x3b7a
xorl %eax, %eax
jmp 0x3b94
leaq 0x5782(%rip), %rax      # 0x91d4
movl $0xb, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fda
movq 0x5567(%rip), %rbx      # 0x8fd0
leaq 0x283f(%rip), %rsi      # 0x62af
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2170
leaq 0x280c(%rip), %rsi      # 0x6290
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2170
testb $0x1, %r14b
jne 0x3d99
xorl %eax, %eax
jmp 0x3db3
movl %r14d, %eax
shrl $0x7, %eax
andl $0x1f, %eax
je 0x3b18
cmpl $0x1, %eax
jne 0x3fe8
leaq 0x5717(%rip), %rax      # 0x91d4
movl $0x1, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fda
movq 0x54fc(%rip), %rbx      # 0x8fd0
leaq 0x27dc(%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 0x3fb3
leaq 0x56b5(%rip), %rax      # 0x91d4
xorl %r15d, %r15d
cmpb $0x1, 0x2(%rax)
jne 0x3fda
movq 0x549d(%rip), %rbx      # 0x8fd0
leaq 0x2787(%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 0x3fb3
movq 0x544f(%rip), %rdi      # 0x8fd0
leaq 0x270a(%rip), %rsi      # 0x6292
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x2, %r14b
je 0x3bd0
testb %al, %al
je 0x3bb6
movq 0x542b(%rip), %rdi      # 0x8fd0
leaq 0x257c(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5413(%rip), %rdi      # 0x8fd0
leaq 0x26d1(%rip), %rsi      # 0x6295
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x4, %r14b
je 0x3c0c
testb %al, %al
je 0x3bf2
movq 0x53ef(%rip), %rdi      # 0x8fd0
leaq 0x2540(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x53d7(%rip), %rdi      # 0x8fd0
leaq 0x2698(%rip), %rsi      # 0x6298
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x8, %r14b
je 0x3c48
testb %al, %al
je 0x3c2e
movq 0x53b3(%rip), %rdi      # 0x8fd0
leaq 0x2504(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x539b(%rip), %rdi      # 0x8fd0
leaq 0x265f(%rip), %rsi      # 0x629b
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x10, %r14b
je 0x3c84
testb %al, %al
je 0x3c6a
movq 0x5377(%rip), %rdi      # 0x8fd0
leaq 0x24c8(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x535f(%rip), %rdi      # 0x8fd0
leaq 0x2626(%rip), %rsi      # 0x629e
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x20, %r14b
je 0x3cc0
testb %al, %al
je 0x3ca6
movq 0x533b(%rip), %rdi      # 0x8fd0
leaq 0x248c(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5323(%rip), %rdi      # 0x8fd0
leaq 0x25ed(%rip), %rsi      # 0x62a1
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
movzbl %r14b, %r15d
testb $0x40, %r14b
je 0x3d00
testb %al, %al
je 0x3ce6
movq 0x52fb(%rip), %rdi      # 0x8fd0
leaq 0x244c(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x52e3(%rip), %rdi      # 0x8fd0
leaq 0x25b0(%rip), %rsi      # 0x62a4
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
cmpl $0x80, %r15d
jb 0x3d3f
testb %al, %al
je 0x3d25
movq 0x52bc(%rip), %rdi      # 0x8fd0
leaq 0x240d(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x52a4(%rip), %rdi      # 0x8fd0
leaq 0x2574(%rip), %rsi      # 0x62a7
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
btl $0x8, %r14d
jae 0x3d7a
testb %al, %al
je 0x3d62
movq 0x527f(%rip), %rdi      # 0x8fd0
leaq 0x23d0(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5267(%rip), %rdi      # 0x8fd0
leaq 0x253a(%rip), %rsi      # 0x62aa
movl $0x2, %edx
callq 0x2170
leaq 0x252c(%rip), %rsi      # 0x62ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2170
movl $0x6, %r15d
jmp 0x3fb3
movq 0x5230(%rip), %rdi      # 0x8fd0
leaq 0x24eb(%rip), %rsi      # 0x6292
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x2, %r14b
je 0x3def
testb %al, %al
je 0x3dd5
movq 0x520c(%rip), %rdi      # 0x8fd0
leaq 0x235d(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x51f4(%rip), %rdi      # 0x8fd0
leaq 0x24b2(%rip), %rsi      # 0x6295
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x4, %r14b
je 0x3e2b
testb %al, %al
je 0x3e11
movq 0x51d0(%rip), %rdi      # 0x8fd0
leaq 0x2321(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x51b8(%rip), %rdi      # 0x8fd0
leaq 0x2479(%rip), %rsi      # 0x6298
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x8, %r14b
je 0x3e67
testb %al, %al
je 0x3e4d
movq 0x5194(%rip), %rdi      # 0x8fd0
leaq 0x22e5(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x517c(%rip), %rdi      # 0x8fd0
leaq 0x2440(%rip), %rsi      # 0x629b
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x10, %r14b
je 0x3ea3
testb %al, %al
je 0x3e89
movq 0x5158(%rip), %rdi      # 0x8fd0
leaq 0x22a9(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5140(%rip), %rdi      # 0x8fd0
leaq 0x2407(%rip), %rsi      # 0x629e
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
testb $0x20, %r14b
je 0x3edf
testb %al, %al
je 0x3ec5
movq 0x511c(%rip), %rdi      # 0x8fd0
leaq 0x226d(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5104(%rip), %rdi      # 0x8fd0
leaq 0x23ce(%rip), %rsi      # 0x62a1
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
movzbl %r14b, %r15d
testb $0x40, %r14b
je 0x3f1f
testb %al, %al
je 0x3f05
movq 0x50dc(%rip), %rdi      # 0x8fd0
leaq 0x222d(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x50c4(%rip), %rdi      # 0x8fd0
leaq 0x2391(%rip), %rsi      # 0x62a4
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
cmpl $0x80, %r15d
jb 0x3f5e
testb %al, %al
je 0x3f44
movq 0x509d(%rip), %rdi      # 0x8fd0
leaq 0x21ee(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5085(%rip), %rdi      # 0x8fd0
leaq 0x2355(%rip), %rsi      # 0x62a7
movl $0x2, %edx
callq 0x2170
movb $0x1, %al
btl $0x8, %r14d
jae 0x3f99
testb %al, %al
je 0x3f81
movq 0x5060(%rip), %rdi      # 0x8fd0
leaq 0x21b1(%rip), %rsi      # 0x6128
movl $0x2, %edx
callq 0x2170
movq 0x5048(%rip), %rdi      # 0x8fd0
leaq 0x2325(%rip), %rsi      # 0x62b4
movl $0x2, %edx
callq 0x2170
leaq 0x230d(%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 0x4fe1(%rip), %rdi      # 0x8fd0
leaq 0x2208(%rip), %rsi      # 0x61fe
callq 0x2130
movq %rax, %rdi
callq 0x2090
movl $0x1, %edi
callq 0x2180