// File: /workspace/github_cpp_makefile_star2_O3/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 0x6ec7
leal -0x8(%rsi), %eax
cmpl $0x1a, %eax
ja 0x70ab
leaq 0x26bd(%rip), %rcx      # 0x94f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rsp, %rdi
callq 0x6bf8
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r15
leaq 0x22d9(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x22f8(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %ebp, %esi
callq 0x3370
movq %rax, %r15
leaq 0x2734(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x22c3(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %r14d, %esi
callq 0x3370
jmp 0x71ee
leal -0x2a(%rsi), %eax
cmpl $0x2, %eax
jb 0x6f94
cmpl $0x10000000, %esi       # imm = 0x10000000
je 0x6ee7
cmpl $0x14000000, %esi       # imm = 0x14000000
jne 0x7249
movq %rsp, %rdi
callq 0x6bf8
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r12
leaq 0x222e(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x224d(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r12, %rdi
callq 0x3250
movq %r12, %rdi
movl %ebp, %esi
callq 0x3370
movq %rax, %r12
leaq 0x2689(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x2218(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r12, %rdi
callq 0x3250
movq %r12, %rdi
movl %r14d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2653(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
movq %r14, %rdi
movl %r15d, %esi
callq 0x3370
jmp 0x71ee
movq %rsp, %rdi
callq 0x6bf8
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r15
leaq 0x2181(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x21a0(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %r12d, %esi
callq 0x3370
movq %rax, %r15
leaq 0x25db(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x216a(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %ebp, %esi
callq 0x3370
movq %rax, %r15
leaq 0x25a6(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x2135(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r15, %rdi
callq 0x3250
movq %r15, %rdi
movl %r14d, %esi
callq 0x3370
jmp 0x71ee
movq %rsp, %rdi
callq 0x6bf8
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r14
leaq 0x20c0(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x20df(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r14, %rdi
callq 0x3250
movq %r14, %rdi
movl %r12d, %esi
callq 0x3370
jmp 0x71ee
cmpl $0x8c000000, %esi       # imm = 0x8C000000
je 0x730a
cmpl $0xac000000, %esi       # imm = 0xAC000000
jne 0x7249
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 0x2038(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x2057(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r13, %rdi
callq 0x3250
movq %r13, %rdi
movl %r14d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2492(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
movq %r14, %rdi
movl %r15d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x2473(%rip), %rsi      # 0x95cd
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1fff(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r14, %rdi
callq 0x3250
movq %r14, %rdi
movl %ebp, %esi
callq 0x3370
leaq 0x1ed2(%rip), %rsi      # 0x905e
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
jmp 0x73e0
movq %rsp, %rdi
callq 0x6bf8
leaq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x3250
movq %rax, %r14
leaq 0x1f77(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1f96(%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 0x7209
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3200
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x3310
movq 0x5d7b(%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 0x237a(%rip), %rsi      # 0x95cf
movl $0x6, %edx
movq %r14, %rdi
callq 0x3250
leaq 0x26c6(%rip), %rsi      # 0x992f
movl $0x2, %edx
movq %r14, %rdi
callq 0x3250
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rcx
leaq (%r14,%rcx), %r15
cmpb $0x0, 0x111(%rsp,%rcx)
jne 0x72a7
movq %r15, %rdi
movl $0x20, %esi
callq 0x31e0
movb $0x1, 0xe1(%r15)
movq 0x30(%rsp), %rax
movb $0x30, 0xe0(%r15)
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 0x7209
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 0x1df1(%rip), %rsi      # 0x913a
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1e10(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r13, %rdi
callq 0x3250
movq %r13, %rdi
movl %r14d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x224b(%rip), %rsi      # 0x95ca
movl $0x2, %edx
movq %rax, %rdi
callq 0x3250
movq %r14, %rdi
movl %r15d, %esi
callq 0x3370
movq %rax, %r14
leaq 0x222c(%rip), %rsi      # 0x95cd
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
leaq 0x1db8(%rip), %rsi      # 0x916d
movl $0x1, %edx
movq %r14, %rdi
callq 0x3250
movq %r14, %rdi
movl %ebp, %esi
callq 0x3370
leaq 0x1c8b(%rip), %rsi      # 0x905e
movl $0x1, %edx
movq %rax, %rdi
callq 0x3250
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x71fc
jmp 0x7209
jmp 0x7412
jmp 0x7412
jmp 0x7412
jmp 0x7412
jmp 0x7412
jmp 0x7419
jmp 0x7400
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x742a
jmp 0x7437
jmp 0x7419
jmp 0x7419
movq %rax, %rbx
jmp 0x7437
jmp 0x7419
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7437
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3200
movq 0x5b5a(%rip), %rsi      # 0xcf98
leaq 0x20(%rsp), %rdi
callq 0x31a0
leaq 0xa0(%rsp), %rdi
callq 0x30a0
movq %rbx, %rdi
callq 0x33a0
nopl (%rax)