// File: /workspace/github_c_makefile_star2_O3/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 0x7d13(%rip), %rdi      # 0xd1f0
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5070
movq 0x7ada(%rip), %rax      # 0xcfc8
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 0x6055(%rip), %rax      # 0xb570
movq %rax, (%r14)
addq 0x7aa3(%rip), %rbx      # 0xcfc8
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6db6
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 0x7090
movq (%rbx), %rdi
callq 0x7234
testb %al, %al
je 0x55af
movq (%rsp), %rsi
cmpq $0x3f, (%rsi)
jg 0x55e8
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x5732
movq %rbx, %rdi
callq 0x50e0
movq 0x7a49(%rip), %rdi      # 0xcfe8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5200
jmp 0x5750
movq 0x7a32(%rip), %r14      # 0xcfe8
leaq 0x2a61(%rip), %rsi      # 0x801e
movl $0xf, %edx
movq %r14, %rdi
callq 0x5200
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0x5718
movq %rbx, %rdi
callq 0x50e0
movq %rax, %rdx
jmp 0x575c
leaq 0x10(%rsp), %rdi
movl $0x4, %edx
callq 0x737a
leaq 0x2a52(%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 0x5627
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x51c0
movq (%rsp), %rdi
testl %ebx, %ebx
jne 0x56e8
movl $0xc, %esi
callq 0x741e
movq (%rsp), %rdi
callq 0x7258
cmpl $0x1, %eax
jne 0x57ec
movq (%rsp), %rdi
movl $0x14, %esi
callq 0x741e
movq (%rsp), %rdi
callq 0x7258
movl %eax, %ebx
movq (%rsp), %rdi
callq 0x7258
movq (%rsp), %rdi
movl %eax, %esi
callq 0x741e
shll $0x9, %ebx
movq (%rsp), %rsi
leaq 0x10(%rsp), %rdi
movl %ebx, %edx
callq 0x73e8
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x70e6
movaps 0x50(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x50(%rsp)
movq 0x8(%rsp), %rdi
movaps %xmm0, (%rsp)
testq %rdi, %rdi
je 0x56cd
callq 0x6f48
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x56cd
callq 0x6f48
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x56e4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x51c0
movq (%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x57c0
movq 0x78b9(%rip), %rcx      # 0xcfc0
cmpb $0x0, (%rcx)
je 0x57bc
incl 0x8(%rax)
jmp 0x57c0
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x5300
jmp 0x576b
movq 0x78af(%rip), %rax      # 0xcfe8
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 0x28d2(%rip), %rbx      # 0x802e
movq 0x7885(%rip), %rdi      # 0xcfe8
movq %rbx, %rsi
callq 0x5200
movq 0x7876(%rip), %rdi      # 0xcfe8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x5180
movsbl %al, %esi
movq 0x785b(%rip), %rdi      # 0xcfe8
callq 0x5040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x5120
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x57ae
callq 0x6f48
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
lock
incl 0x8(%rax)
movzbl 0x48(%rsp), %edx
xorl $0x1, %edx
negl %edx
leaq 0x30(%rsp), %rsi
movl $0x2, %edi
callq 0x5870
movq 0x38(%rsp), %rdi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x579f
callq 0x6f48
jmp 0x579f
movl $0x17, %edx
leaq 0x285d(%rip), %rbx      # 0x8055
jmp 0x575c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5859
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x51c0
jmp 0x5859
jmp 0x5856
jmp 0x5856
jmp 0x5856
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5859
callq 0x6f48
jmp 0x5859
jmp 0x5856
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5260
jmp 0x5868
movq %rax, %rbx
movl $0x18, %esi
movq %r14, %rdi
callq 0x51c0
jmp 0x5868
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5868
callq 0x6f48
movq %rbx, %rdi
callq 0x5340