// File: /workspace/github_cpp_makefile_star2_O2/mikeakohn[P]cloudtari/build/../src/Disassembler.cxx
// Function: Disassembler::disassemble(unsigned char*, int, char*)
int Disassembler::disassemble(uint8_t *code, int pc, char *text)
{
  Opcode &opcode = opcodes[code[0]];

  switch (opcode.type)
  {
    case OP_NONE:
      sprintf(text, "%s", opcode.name);
      return 1;
    case OP_IMMEDIATE:
      sprintf(text, "%s #0x%02x", opcode.name, code[1]);
      return 2;
    case OP_ADDRESS8:
      sprintf(text, "%s 0x%02x", opcode.name, code[1]);
      return 2;
    case OP_ADDRESS16:
      sprintf(text, "%s 0x%04x", opcode.name, code[1] | (code[2] << 8));
      return 3;
    case OP_INDEXED8_X:
      sprintf(text, "%s 0x%02x, x", opcode.name, code[1]);
      return 2;
    case OP_INDEXED8_Y:
      sprintf(text, "%s 0x%02x, y", opcode.name, code[1]);
      return 2;
    case OP_INDEXED16_X:
      sprintf(text, "%s 0x%04x, x", opcode.name, code[1] | (code[2] << 8));
      return 3;
    case OP_INDEXED16_Y:
      sprintf(text, "%s 0x%04x, y", opcode.name, code[1] | (code[2] << 8));
      return 3;
    case OP_INDIRECT16:
      sprintf(text, "%s (0x%04x)", opcode.name, code[1] | (code[2] << 8));
      return 3;
    case OP_X_INDIRECT8:
      sprintf(text, "%s (0x%02x, x)", opcode.name, code[1]);
      return 2;
    case OP_INDIRECT8_Y:
      sprintf(text, "%s (0x%02x), y", opcode.name, code[1]);
      return 2;
    case OP_INDIRECT8:
      sprintf(text, "%s (0x%02x)", opcode.name, code[1]);
      return 2;
    case OP_X_INDIRECT16:
      sprintf(text, "%s (0x%04x,x)", opcode.name, code[1] | (code[2] << 8));
      return 3;
    case OP_RELATIVE:
      sprintf(text, "%s 0x%04x (offset=%d)", opcode.name, pc + 2 + (int8_t)code[1], (int8_t)code[1]);
      return 2;
    case OP_ADDRESS8_RELATIVE:
      sprintf(text, "%s 0x%02x 0x%04x", opcode.name, code[1], pc + 2 + (int8_t)code[2]);
      return 3;
    default:
      sprintf(text, "error");
      return 0;
  }
}

// Assembly:
movzbl (%rdi), %ecx
shll $0x4, %ecx
leaq 0xa8eb(%rip), %rax      # 0xf3f0
movl 0x8(%rcx,%rax), %r8d
cmpq $0xe, %r8
ja 0x4bc6
pushq %rax
addq %rcx, %rax
leaq 0x567d(%rip), %rcx      # 0xa19c
movslq (%rcx,%r8,4), %r8
addq %rcx, %r8
jmpq *%r8
movq (%rax), %rsi
movq %rdx, %rdi
callq 0x41c0
pushq $0x1
jmp 0x4c8c
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
movsbl 0x2(%rdi), %edi
leal (%rsi,%rdi), %r8d
addl $0x2, %r8d
leaq 0x5730(%rip), %rsi      # 0xa285
movq %rdx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4090
jmp 0x4c8a
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
leaq 0x56e0(%rip), %rsi      # 0xa255
jmp 0x4c5e
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
leaq 0x566f(%rip), %rsi      # 0xa1f7
jmp 0x4c5e
movq (%rax), %rax
movzwl 0x1(%rdi), %ecx
leaq 0x56c6(%rip), %rsi      # 0xa261
jmp 0x4c7d
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
leaq 0x5689(%rip), %rsi      # 0xa237
jmp 0x4c5e
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
leaq 0x5622(%rip), %rsi      # 0xa1e3
jmp 0x4c5e
movw $0x72, 0x4(%rdx)
movl $0x6f727265, (%rdx)     # imm = 0x6F727265
xorl %eax, %eax
retq
movq (%rax), %rax
movzwl 0x1(%rdi), %ecx
leaq 0x560a(%rip), %rsi      # 0xa1ed
jmp 0x4c7d
movq (%rax), %rax
movzwl 0x1(%rdi), %ecx
leaq 0x5628(%rip), %rsi      # 0xa21e
jmp 0x4c7d
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
leaq 0x55cf(%rip), %rsi      # 0xa1d8
jmp 0x4c5e
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
leaq 0x55eb(%rip), %rsi      # 0xa204
jmp 0x4c5e
movq (%rax), %rax
movsbl 0x1(%rdi), %r8d
leal (%rsi,%r8), %ecx
addl $0x2, %ecx
leaq 0x563e(%rip), %rsi      # 0xa26f
movq %rdx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4090
jmp 0x4c6b
movq (%rax), %rax
movzwl 0x1(%rdi), %ecx
leaq 0x55c3(%rip), %rsi      # 0xa211
jmp 0x4c7d
movq (%rax), %rax
movzbl 0x1(%rdi), %ecx
leaq 0x55e8(%rip), %rsi      # 0xa246
movq %rdx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4090
pushq $0x2
jmp 0x4c8c
movq (%rax), %rax
movzwl 0x1(%rdi), %ecx
leaq 0x55ae(%rip), %rsi      # 0xa22b
movq %rdx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4090
pushq $0x3
popq %rax
addq $0x8, %rsp
retq
nop