// File: /workspace/github_c_makefile_star2_O2/mrkite[P]regs/src/2mg.cc
// Function: main
int main(int argc, char **argv) {
  struct arguments arguments;
  arguments.list = false;

  argp_parse(&argp, argc, argv, 0, 0, &arguments);

  std::cout.imbue(std::locale(std::locale::classic(), new MyPunct));

  auto h = TheHandle::createFromFile(arguments.diskimage);
  if (!h->isOpen()) {
    std::cerr << "Failed to open " << arguments.diskimage << std::endl;
    return -1;
  }
  if (h->length < 64) {
    std::cerr << arguments.diskimage << " is not a valid prodos disk image"
              << std::endl;
    return -1;
  }
  if (h->read(4) == "2IMG") {
    h->seek(0xc);
    if (h->r32() != 1) {
      std::cerr << "Not a ProDOS disk image" << std::endl;
      return -1;
    }
    h->seek(0x14);
    auto disklen = h->r32() * 512;
    auto diskofs = h->r32();
    h->seek(diskofs);
    h = TheHandle::createFromArray(h->readBytes(disklen));
  }
  doDirectory(2, h, arguments.list ? 0 : -1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq %rsi, %rdx
movl %edi, %esi
leaq 0x18(%rsp), %r9
movb $0x0, 0x8(%r9)
leaq 0x6d02(%rip), %rdi      # 0xc1f0
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5060
movq 0x6ad1(%rip), %rax      # 0xbfd0
movq (%rax), %rax
movq -0x18(%rax), %rbx
callq 0x5240
movq %rax, %r15
pushq $0x18
popq %rdi
callq 0x51a0
movq %rax, %r14
movq %rax, %rdi
callq 0x6616
addq 0x6aa8(%rip), %rbx      # 0xbfd0
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x662e
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x5080
leaq 0x48(%rsp), %rdi
callq 0x5260
leaq 0x28(%rsp), %rdi
callq 0x5260
movq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6944
movq (%rbx), %rdi
callq 0x6ad2
testb %al, %al
je 0x55aa
movq 0x8(%rsp), %rsi
cmpq $0x3f, (%rsi)
jg 0x55ee
movq 0x18(%rsp), %rsi
movq 0x6a5c(%rip), %rdi      # 0xbff0
callq 0x5180
movq %rax, %rdi
leaq 0x1a8b(%rip), %rsi      # 0x702e
callq 0x5180
jmp 0x55ca
movq 0x6a3f(%rip), %rdi      # 0xbff0
leaq 0x1a66(%rip), %rsi      # 0x701e
callq 0x5180
movq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x5180
movq %rax, %rdi
callq 0x5100
pushq $-0x1
popq %rbx
leaq 0x10(%rsp), %rdi
callq 0x67fc
movl %ebx, %eax
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x6c00
leaq 0x1a4e(%rip), %rsi      # 0x7050
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x66d6
movl %eax, %ebp
movq %rbx, %rdi
callq 0x50e0
testb %bpl, %bpl
je 0x56b7
movq 0x8(%rsp), %rdi
pushq $0xc
popq %rsi
callq 0x6c90
movq 0x8(%rsp), %rdi
callq 0x6af6
cmpl $0x1, %eax
jne 0x56ef
movq 0x8(%rsp), %rdi
pushq $0x14
popq %rsi
callq 0x6c90
movq 0x8(%rsp), %rdi
callq 0x6af6
movl %eax, %ebx
movq 0x8(%rsp), %rdi
callq 0x6af6
movq 0x8(%rsp), %rdi
movl %eax, %esi
callq 0x6c90
shll $0x9, %ebx
movq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdi
movl %ebx, %edx
callq 0x6c5a
leaq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x6990
leaq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x6914
leaq 0x68(%rsp), %rdi
callq 0x67fc
leaq 0x28(%rsp), %rdi
callq 0x68e8
leaq 0x50(%rsp), %rbx
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x6878
movzbl 0x20(%rsp), %edx
xorl $0x1, %edx
negl %edx
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x575c
leaq 0x58(%rsp), %rdi
callq 0x67fc
xorl %ebx, %ebx
jmp 0x55d5
leaq 0x195f(%rip), %rsi      # 0x7055
movq 0x68f3(%rip), %rdi      # 0xbff0
jmp 0x55a3
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x68e8
jmp 0x574a
jmp 0x5747
jmp 0x5747
jmp 0x5747
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x67fc
jmp 0x574a
jmp 0x5747
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5260
jmp 0x5754
movq %rax, %rbx
pushq $0x18
popq %rsi
movq %r14, %rdi
callq 0x51c0
jmp 0x5754
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x67fc
movq %rbx, %rdi
callq 0x5350