// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rdx
movl %edi, %esi
leaq 0x40(%rsp), %r9
movb $0x0, 0x8(%r9)
leaq 0x7cf3(%rip), %rdi      # 0xd1f0
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5070
movq 0x7ac2(%rip), %rax      # 0xcfd0
movq (%rax), %rax
movq -0x18(%rax), %rbx
callq 0x5250
movq %rax, %r15
movl $0x18, %edi
callq 0x51a0
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x52f0
leaq 0x6005(%rip), %rax      # 0xb540
movq %rax, (%r14)
addq 0x7a8b(%rip), %rbx      # 0xcfd0
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6e18
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x5090
leaq 0x60(%rsp), %rdi
callq 0x5260
leaq 0x10(%rsp), %rdi
callq 0x5260
movq 0x40(%rsp), %rsi
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x70e8
movq (%rbx), %rdi
callq 0x728c
testb %al, %al
je 0x55cf
movq (%rsp), %rsi
cmpq $0x3f, (%rsi)
jg 0x5608
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x569d
movq %rbx, %rdi
callq 0x50e0
movq 0x7a31(%rip), %rdi      # 0xcff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5200
jmp 0x56bb
movq 0x7a1a(%rip), %r14      # 0xcff0
leaq 0x2a41(%rip), %rsi      # 0x801e
movl $0xf, %edx
movq %r14, %rdi
callq 0x5200
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x5683
movq %rbx, %rdi
callq 0x50e0
movq %rax, %rdx
jmp 0x56c7
leaq 0x10(%rsp), %rdi
movl $0x4, %edx
callq 0x73d2
leaq 0x2a32(%rip), %rsi      # 0x8050
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x50b0
movl %eax, %ebx
movq (%r14), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x5647
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x51c0
testl %ebx, %ebx
je 0x5727
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x30(%rsp)
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x57e9
movq 0x7956(%rip), %rcx      # 0xcfc8
cmpb $0x0, (%rcx)
je 0x57e5
incl 0x8(%rax)
jmp 0x57e9
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x5300
jmp 0x56d6
movq 0x794c(%rip), %rax      # 0xcff0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x5300
movl $0x21, %edx
leaq 0x2967(%rip), %rbx      # 0x802e
movq 0x7922(%rip), %rdi      # 0xcff0
movq %rbx, %rsi
callq 0x5200
movq 0x7913(%rip), %rdi      # 0xcff0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x5180
movsbl %al, %esi
movq 0x78f8(%rip), %rdi      # 0xcff0
callq 0x5040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x5120
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5719
callq 0x6fa6
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq (%rsp), %rdi
movl $0xc, %esi
callq 0x7476
movq (%rsp), %rdi
callq 0x72b0
cmpl $0x1, %eax
jne 0x581c
movq (%rsp), %rdi
movl $0x14, %esi
callq 0x7476
movq (%rsp), %rdi
callq 0x72b0
movl %eax, %ebx
movq (%rsp), %rdi
callq 0x72b0
movq (%rsp), %rdi
movl %eax, %esi
callq 0x7476
shll $0x9, %ebx
movq (%rsp), %rsi
leaq 0x10(%rsp), %rdi
movl %ebx, %edx
callq 0x7440
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x713e
movaps 0x50(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x50(%rsp)
movq 0x8(%rsp), %rdi
movups %xmm0, (%rsp)
testq %rdi, %rdi
je 0x57b6
callq 0x6fa6
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x57c5
callq 0x6fa6
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x564f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x51c0
jmp 0x564f
lock
incl 0x8(%rax)
movzbl 0x48(%rsp), %edx
xorl $0x1, %edx
negl %edx
leaq 0x30(%rsp), %rsi
movl $0x2, %edi
callq 0x58a0
movq 0x38(%rsp), %rdi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x570a
callq 0x6fa6
jmp 0x570a
movl $0x17, %edx
leaq 0x282d(%rip), %rbx      # 0x8055
jmp 0x56c7
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5889
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x51c0
jmp 0x5889
jmp 0x5886
jmp 0x5886
jmp 0x5886
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5889
callq 0x6fa6
jmp 0x5889
jmp 0x5886
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5260
jmp 0x5898
movq %rax, %rbx
movl $0x18, %esi
movq %r14, %rdi
callq 0x51c0
jmp 0x5898
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5898
callq 0x6fa6
movq %rbx, %rdi
callq 0x5340