// File: /workspace/github_c_makefile_star2_O0/mrdudz[P]run6502/run6502.c
// Function: doDisassemble
static int doDisassemble(int argc, char **argv, M6502 *mpu)
{
  unsigned addr= 0, last= 0;
  if (argc < 3) usage(1);
  addr= htol(argv[1]);
  last= ('+' == *argv[2]) ? addr + htol(1 + argv[2]) : htol(argv[2]);
  while (addr < last)
    {
      char insn[64];
      int  i= 0, size= M6502_disassemble(mpu, addr, insn);
      printf("%04X ", addr);
      while (i++ < size)  printf("%02X", mpu->memory[addr + i - 1]);
      while (i++ < 4)     printf("  ");
      putchar(' ');
      i= 0;
      while (i++ < size)  putchar(isgraph(mpu->memory[addr + i - 1]) ? mpu->memory[addr + i - 1] : ' ');
      while (i++ < 4)     putchar(' ');
      printf(" %s\n", insn);
      addr += size;
    }
  return 2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x3, -0x4(%rbp)
jge 0x2294
movl $0x1, %edi
callq 0x29b0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2c00
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %ecx
movl $0x2b, %eax
cmpl %ecx, %eax
jne 0x22e0
movl -0x1c(%rbp), %eax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x1, %rdi
callq 0x2c00
movq %rax, %rcx
movq -0x78(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x70(%rbp)
jmp 0x22f1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2c00
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x244a
movl $0x0, -0x64(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
leaq -0x60(%rbp), %rdx
movzwl %ax, %esi
callq 0x2f80
movl %eax, -0x68(%rbp)
movl -0x1c(%rbp), %esi
leaq 0x12d42(%rip), %rdi     # 0x1506d
movb $0x0, %al
callq 0x10a0
movl -0x64(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x64(%rbp)
cmpl -0x68(%rbp), %eax
jge 0x2369
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
addl -0x64(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %esi
leaq 0x13986(%rip), %rdi     # 0x15ce6
movb $0x0, %al
callq 0x10a0
jmp 0x2332
jmp 0x236b
movl -0x64(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x64(%rbp)
cmpl $0x4, %eax
jge 0x238b
leaq 0x13afd(%rip), %rdi     # 0x15e7f
movb $0x0, %al
callq 0x10a0
jmp 0x236b
movl $0x20, %edi
callq 0x1040
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x64(%rbp)
cmpl -0x68(%rbp), %eax
jge 0x240c
callq 0x11c0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x1c(%rbp), %edx
addl -0x64(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x23f8
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
addl -0x64(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x7c(%rbp)
jmp 0x2402
movl $0x20, %eax
movl %eax, -0x7c(%rbp)
jmp 0x2402
movl -0x7c(%rbp), %edi
callq 0x1040
jmp 0x239c
jmp 0x240e
movl -0x64(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x64(%rbp)
cmpl $0x4, %eax
jge 0x242a
movl $0x20, %edi
callq 0x1040
jmp 0x240e
leaq -0x60(%rbp), %rsi
leaq 0x12cd6(%rip), %rdi     # 0x1510b
movb $0x0, %al
callq 0x10a0
movl -0x68(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x22f8
movl $0x2, %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)