// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
movl %edi, %ebx
movl %edi, %eax
shrl $0x9, %eax
andl $0x7, %eax
cmpw $0x6, %ax
je 0x3b08
cmpl $0x2, %eax
jne 0x3b4e
leaq 0x5723(%rip), %rax      # 0x91ec
cmpb $0x1, 0x2(%rax)
jne 0x3bb7
movq 0x54f6(%rip), %r14      # 0x8fd0
leaq 0x278d(%rip), %rsi      # 0x626e
movq %r14, %rdi
callq 0x2150
leaq 0x2784(%rip), %rsi      # 0x6274
movq %r14, %rdi
callq 0x2150
testb $0x1, %bl
jne 0x3c1f
xorl %eax, %eax
jmp 0x3c34
leaq 0x56dd(%rip), %rax      # 0x91ec
cmpb $0x1, 0x2(%rax)
jne 0x3bbe
movq 0x54b0(%rip), %r14      # 0x8fd0
leaq 0x276c(%rip), %rsi      # 0x6293
movq %r14, %rdi
callq 0x2150
leaq 0x273e(%rip), %rsi      # 0x6274
movq %r14, %rdi
callq 0x2150
testb $0x1, %bl
jne 0x3ddc
xorl %eax, %eax
jmp 0x3df1
movl %ebx, %eax
shrl $0x7, %eax
andl $0x1f, %eax
je 0x3bc5
cmpl $0x1, %eax
jne 0x3fac
leaq 0x5684(%rip), %rax      # 0x91ec
cmpb $0x1, 0x2(%rax)
jne 0x3fa0
movq 0x5457(%rip), %r14      # 0x8fd0
leaq 0x271b(%rip), %rsi      # 0x629b
movq %r14, %rdi
callq 0x2150
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r14,%rax)
andl $0x7f, %ebx
shll $0x2, %ebx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20e0
pushq $0x1
jmp 0x3f94
pushq $0x6
jmp 0x3fa2
pushq $0xb
jmp 0x3fa2
leaq 0x5620(%rip), %rax      # 0x91ec
xorl %r14d, %r14d
cmpb $0x1, 0x2(%rax)
jne 0x3fa4
movq 0x53f0(%rip), %r14      # 0x8fd0
leaq 0x26be(%rip), %rsi      # 0x62a5
movq %r14, %rdi
callq 0x2150
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r14,%rax)
andl $0x7f, %ebx
shll $0x2, %ebx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20e0
xorl %r14d, %r14d
jmp 0x3f96
movq 0x53aa(%rip), %rdi      # 0x8fd0
leaq 0x2649(%rip), %rsi      # 0x6276
callq 0x2150
movb $0x1, %al
testb $0x2, %bl
je 0x3c65
testb %al, %al
je 0x3c50
movq 0x538c(%rip), %rdi      # 0x8fd0
leaq 0x24c1(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x5379(%rip), %rdi      # 0x8fd0
leaq 0x261b(%rip), %rsi      # 0x6279
callq 0x2150
movb $0x1, %al
testb $0x4, %bl
je 0x3c96
testb %al, %al
je 0x3c81
movq 0x535b(%rip), %rdi      # 0x8fd0
leaq 0x2490(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x5348(%rip), %rdi      # 0x8fd0
leaq 0x25ed(%rip), %rsi      # 0x627c
callq 0x2150
movb $0x1, %al
testb $0x8, %bl
je 0x3cc7
testb %al, %al
je 0x3cb2
movq 0x532a(%rip), %rdi      # 0x8fd0
leaq 0x245f(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x5317(%rip), %rdi      # 0x8fd0
leaq 0x25bf(%rip), %rsi      # 0x627f
callq 0x2150
movb $0x1, %al
testb $0x10, %bl
je 0x3cf8
testb %al, %al
je 0x3ce3
movq 0x52f9(%rip), %rdi      # 0x8fd0
leaq 0x242e(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x52e6(%rip), %rdi      # 0x8fd0
leaq 0x2591(%rip), %rsi      # 0x6282
callq 0x2150
movb $0x1, %al
testb $0x20, %bl
je 0x3d29
testb %al, %al
je 0x3d14
movq 0x52c8(%rip), %rdi      # 0x8fd0
leaq 0x23fd(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x52b5(%rip), %rdi      # 0x8fd0
leaq 0x2563(%rip), %rsi      # 0x6285
callq 0x2150
movb $0x1, %al
movzbl %bl, %r14d
testb $0x40, %bl
je 0x3d5e
testb %al, %al
je 0x3d49
movq 0x5293(%rip), %rdi      # 0x8fd0
leaq 0x23c8(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x5280(%rip), %rdi      # 0x8fd0
leaq 0x2531(%rip), %rsi      # 0x6288
callq 0x2150
movb $0x1, %al
cmpw $0x80, %r14w
jb 0x3d92
testb %al, %al
je 0x3d7d
movq 0x525f(%rip), %rdi      # 0x8fd0
leaq 0x2394(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x524c(%rip), %rdi      # 0x8fd0
leaq 0x2500(%rip), %rsi      # 0x628b
callq 0x2150
movb $0x1, %al
btl $0x8, %ebx
jae 0x3dc2
testb %al, %al
je 0x3daf
movq 0x522d(%rip), %rdi      # 0x8fd0
leaq 0x2362(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x521a(%rip), %rdi      # 0x8fd0
leaq 0x24d1(%rip), %rsi      # 0x628e
callq 0x2150
movq 0x5207(%rip), %rdi      # 0x8fd0
leaq 0x24c1(%rip), %rsi      # 0x6291
callq 0x2150
pushq $0x6
jmp 0x3f94
movq 0x51ed(%rip), %rdi      # 0x8fd0
leaq 0x248c(%rip), %rsi      # 0x6276
callq 0x2150
movb $0x1, %al
testb $0x2, %bl
je 0x3e22
testb %al, %al
je 0x3e0d
movq 0x51cf(%rip), %rdi      # 0x8fd0
leaq 0x2304(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x51bc(%rip), %rdi      # 0x8fd0
leaq 0x245e(%rip), %rsi      # 0x6279
callq 0x2150
movb $0x1, %al
testb $0x4, %bl
je 0x3e53
testb %al, %al
je 0x3e3e
movq 0x519e(%rip), %rdi      # 0x8fd0
leaq 0x22d3(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x518b(%rip), %rdi      # 0x8fd0
leaq 0x2430(%rip), %rsi      # 0x627c
callq 0x2150
movb $0x1, %al
testb $0x8, %bl
je 0x3e84
testb %al, %al
je 0x3e6f
movq 0x516d(%rip), %rdi      # 0x8fd0
leaq 0x22a2(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x515a(%rip), %rdi      # 0x8fd0
leaq 0x2402(%rip), %rsi      # 0x627f
callq 0x2150
movb $0x1, %al
testb $0x10, %bl
je 0x3eb5
testb %al, %al
je 0x3ea0
movq 0x513c(%rip), %rdi      # 0x8fd0
leaq 0x2271(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x5129(%rip), %rdi      # 0x8fd0
leaq 0x23d4(%rip), %rsi      # 0x6282
callq 0x2150
movb $0x1, %al
testb $0x20, %bl
je 0x3ee6
testb %al, %al
je 0x3ed1
movq 0x510b(%rip), %rdi      # 0x8fd0
leaq 0x2240(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x50f8(%rip), %rdi      # 0x8fd0
leaq 0x23a6(%rip), %rsi      # 0x6285
callq 0x2150
movb $0x1, %al
movzbl %bl, %r14d
testb $0x40, %bl
je 0x3f1b
testb %al, %al
je 0x3f06
movq 0x50d6(%rip), %rdi      # 0x8fd0
leaq 0x220b(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x50c3(%rip), %rdi      # 0x8fd0
leaq 0x2374(%rip), %rsi      # 0x6288
callq 0x2150
movb $0x1, %al
cmpw $0x80, %r14w
jb 0x3f4f
testb %al, %al
je 0x3f3a
movq 0x50a2(%rip), %rdi      # 0x8fd0
leaq 0x21d7(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x508f(%rip), %rdi      # 0x8fd0
leaq 0x2343(%rip), %rsi      # 0x628b
callq 0x2150
movb $0x1, %al
btl $0x8, %ebx
jae 0x3f7f
testb %al, %al
je 0x3f6c
movq 0x5070(%rip), %rdi      # 0x8fd0
leaq 0x21a5(%rip), %rsi      # 0x610c
callq 0x2150
movq 0x505d(%rip), %rdi      # 0x8fd0
leaq 0x231e(%rip), %rsi      # 0x6298
callq 0x2150
movq 0x504a(%rip), %rdi      # 0x8fd0
leaq 0x2304(%rip), %rsi      # 0x6291
callq 0x2150
pushq $0xb
popq %r14
movq %rax, %rdi
callq 0x20c0
jmp 0x3fa4
pushq $0x1
popq %r14
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
movq 0x501d(%rip), %rdi      # 0x8fd0
leaq 0x2228(%rip), %rsi      # 0x61e2
callq 0x2150
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x2190