// File: /workspace/github_cpp_makefile_star2_O1/daniel5151[P]mips241/src/disasm.cc
// Function: MIPS::disasm[abi:cxx11](unsigned int)
std::string MIPS::disasm(uint32_t word) {
  std::stringstream instr_ss;

  uint8_t  $s, $t, $d;

  int32_t imm;
  uint16_t imm_u;

  $s = (word >> 21) & 0x1F;
  $t = (word >> 16) & 0x1F;
  $d = (word >> 11) & 0x1F;

  imm_u = (word & 0xFFFF);

  bool isNeg = imm_u & 0x8000;
  if (isNeg) {
    imm_u -= 1;
    imm_u = ~imm_u;
    imm = - ((int32_t)imm_u);
  } else {
    imm = imm_u;
  }

  bool hasImmediateValue = (word >> 26) != 0;
  uint32_t opcode = (hasImmediateValue)
    ? word & 0xFC000000   // Mask off all register identifiers + immediate bits
    : word & 0x0000003F;  // Mask off all register identifiers

  switch (opcode) {
      case OP_MULT:
      case OP_MULTU:
      case OP_DIV:
      case OP_DIVU:
        // 2 src
        instr_ss
          << opcode2str(opcode) << " "
          << "$" << (int)$s
          << ", "
          << "$" << (int)$t;
        break;
      case OP_BEQ:
      case OP_BNE:
        // 2 src + immediate
        instr_ss
          << opcode2str(opcode) << " "
          << "$" << (int)$s
          << ", "
          << "$" << (int)$t
          << ", "
          << imm;
        break;

      case OP_LW:
        // 1 source + immediate + 1 dst
        instr_ss
          << opcode2str(opcode) << " "
          << "$" << (int)$t
          << ", "
          << imm
          << "("
          << "$" << (int)$s
          << ")";
        break;
      case OP_SW:
        // 2 source + immediate
        instr_ss
          << opcode2str(opcode) << " "
          << "$" << (int)$t
          << ", "
          << imm
          << "("
          << "$" << (int)$s
          << ")";
        break;

      case OP_ADD:
      case OP_SUB:
      case OP_SLT:
      case OP_SLTU:
        // 2 sources, 1 dst
        instr_ss
          << opcode2str(opcode) << " "
          << "$" << (int)$d
          << ", "
          << "$" << (int)$s
          << ", "
          << "$" << (int)$t;
        break;

      case OP_MFHI:
      case OP_MFLO:
      case OP_LIS:
        // 1 dst
        instr_ss
          << opcode2str(opcode) << " "
          << "$" << (int)$d;
        break;
      case OP_JALR:
      case OP_JR:
        // 1 src
        instr_ss
          << opcode2str(opcode) << " "
          << "$" << (int)$s;
        break;
      default:
        instr_ss
          << ".word "
          << COUTHEX( word );
  }

  return instr_ss.str();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl %esi, %r13d
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3180
movl %r13d, %ebp
shrl $0x15, %ebp
andl $0x1f, %ebp
movl %r13d, %r14d
shrl $0x10, %r14d
andl $0x1f, %r14d
movl %r13d, %r12d
shrl $0xb, %r12d
andl $0x1f, %r12d
movl %r13d, %eax
negl %eax
movzwl %ax, %eax
negl %eax
movl %r13d, %r15d
andl $0x7fff, %r15d          # imm = 0x7FFF
testw %r13w, %r13w
cmovsl %eax, %r15d
cmpl $0x4000000, %r13d       # imm = 0x4000000
movl $0x3f, %eax
movl $0xfc000000, %esi       # imm = 0xFC000000
cmovbl %eax, %esi
andl %r13d, %esi
cmpl $0x29, %esi
jg 0x6ee7
leal -0x8(%rsi), %eax
cmpl $0x1a, %eax
ja 0x70cb
leaq 0x269d(%rip), %rcx      # 0x94f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rsp, %rdi
callq 0x6c18
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r15
leaq 0x22b9(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x22d8(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %ebp, %esi
callq 0x3370
movq %rax, %r15
leaq 0x2714(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x22a3(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %r14d, %esi
callq 0x3370
jmp 0x720e
leal -0x2a(%rsi), %eax
cmpl $0x2, %eax
jb 0x6fb4
cmpl $0x10000000, %esi       # imm = 0x10000000
je 0x6f07
cmpl $0x14000000, %esi       # imm = 0x14000000
jne 0x7269
movq %rsp, %rdi
callq 0x6c18
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r12
leaq 0x220e(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x222d(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r12, %rdi
callq 0x3250
movq %r12, %rdi
movl %ebp, %esi
callq 0x3370
movq %rax, %r12
leaq 0x2669(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x21f8(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r12, %rdi
callq 0x3250
movq %r12, %rdi
movl %r14d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2633(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
movq %r14, %rdi
movl %r15d, %esi
callq 0x3370
jmp 0x720e
movq %rsp, %rdi
callq 0x6c18
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r15
leaq 0x2161(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x2180(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %r12d, %esi
callq 0x3370
movq %rax, %r15
leaq 0x25bb(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x214a(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %ebp, %esi
callq 0x3370
movq %rax, %r15
leaq 0x2586(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x2115(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %r14d, %esi
callq 0x3370
jmp 0x720e
movq %rsp, %rdi
callq 0x6c18
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r14
leaq 0x20a0(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x20bf(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r14, %rdi
callq 0x3250
movq %r14, %rdi
movl %r12d, %esi
callq 0x3370
jmp 0x720e
cmpl $0x8c000000, %esi       # imm = 0x8C000000
je 0x7331
cmpl $0xac000000, %esi       # imm = 0xAC000000
jne 0x7269
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movl $0x20207773, (%r12)     # imm = 0x20207773
movw $0x20, 0x4(%r12)
movq $0x5, -0x8(%r12)
leaq 0x30(%rsp), %rdi
movl $0x5, %edx
movq %r12, %rsi
callq 0x3250
movq %rax, %r13
leaq 0x2018(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x2037(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r13, %rdi
callq 0x3250
movq %r13, %rdi
movl %r14d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2472(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
movq %r14, %rdi
movl %r15d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2453(%rip), %rsi      # 0x95cd
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1fdf(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r14, %rdi
callq 0x3250
movq %r14, %rdi
movl %ebp, %esi
callq 0x3370
leaq 0x1eb2(%rip), %rsi      # 0x905e
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
jmp 0x7407
movq %rsp, %rdi
callq 0x6c18
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r14
leaq 0x1f57(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1f76(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r14, %rdi
callq 0x3250
movq %r14, %rdi
movl %ebp, %esi
callq 0x3370
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7229
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3200
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x3310
movq 0x5d5b(%rip), %rsi      # 0xcf98
leaq 0x20(%rsp), %rdi
callq 0x31a0
leaq 0xa0(%rsp), %rdi
callq 0x30a0
movq %rbx, %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rsp), %r14
leaq 0x235a(%rip), %rsi      # 0x95cf
movl $0x6, %edx
movq %r14, %rdi
callq 0x3250
leaq 0x2691(%rip), %rsi      # 0x991a
movl $0x2, %edx
movq %r14, %rdi
callq 0x3250
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0x111(%rsp,%rax)
jne 0x72c9
movq %r15, %rdi
movl $0x20, %esi
callq 0x31e0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x30, 0xe0(%r15)
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rcx
movq $0x8, 0x40(%rsp,%rcx)
movq -0x18(%rax), %rcx
movl $0xffffff4f, %edx       # imm = 0xFFFFFF4F
andl 0x48(%rsp,%rcx), %edx
orl $0x80, %edx
movl %edx, 0x48(%rsp,%rcx)
movq -0x18(%rax), %rax
movl 0x48(%rsp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x48(%rsp,%rax)
movl %r13d, %esi
movq %r14, %rdi
callq 0x3150
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
jmp 0x7229
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movl $0x2020776c, (%r12)     # imm = 0x2020776C
movw $0x20, 0x4(%r12)
movq $0x5, -0x8(%r12)
leaq 0x30(%rsp), %rdi
movl $0x5, %edx
movq %r12, %rsi
callq 0x3250
movq %rax, %r13
leaq 0x1dca(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1de9(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r13, %rdi
callq 0x3250
movq %r13, %rdi
movl %r14d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2224(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
movq %r14, %rdi
movl %r15d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2205(%rip), %rsi      # 0x95cd
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1d91(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r14, %rdi
callq 0x3250
movq %r14, %rdi
movl %ebp, %esi
callq 0x3370
leaq 0x1c64(%rip), %rsi      # 0x905e
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x721c
jmp 0x7229
jmp 0x7439
jmp 0x7439
jmp 0x7439
jmp 0x7439
jmp 0x7439
jmp 0x7440
jmp 0x7427
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x7451
jmp 0x745e
jmp 0x7440
jmp 0x7440
movq %rax, %rbx
jmp 0x745e
jmp 0x7440
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x745e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3200
movq 0x5b33(%rip), %rsi      # 0xcf98
leaq 0x20(%rsp), %rdi
callq 0x31a0
leaq 0xa0(%rsp), %rdi
callq 0x30a0
movq %rbx, %rdi
callq 0x33a0