// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x18(%rbp)
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0xac65(%rip), %rdi      # 0x11270
xorl %ecx, %ecx
movl %ecx, %r8d
leaq -0x20(%rbp), %r9
callq 0x6060
movq 0xa9b0(%rip), %rax      # 0x10fd0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
callq 0x6320
movq %rax, -0xc8(%rbp)
movl $0x18, %edi
callq 0x6200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
callq 0x8400
jmp 0x665b
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x8440
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x6080
jmp 0x6692
leaq -0x28(%rbp), %rdi
callq 0x6340
leaq -0x30(%rbp), %rdi
callq 0x6340
movq -0x20(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x9380
movq -0xe8(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x9710
movb %al, -0xd9(%rbp)
jmp 0x66d4
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x678e
jmp 0x66e4
movq 0xa905(%rip), %rdi      # 0x10ff0
leaq 0x492c(%rip), %rsi      # 0xb01e
callq 0x61e0
movq %rax, -0xf0(%rbp)
jmp 0x6700
movq -0xf0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x61e0
movq %rax, -0xf8(%rbp)
jmp 0x6719
movq -0xf8(%rbp), %rdi
movq 0xa889(%rip), %rsi      # 0x10fb0
callq 0x6240
jmp 0x672e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x54(%rbp)
jmp 0x6a13
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x18, %esi
callq 0x6220
jmp 0x6a49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x6340
jmp 0x6a49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6a40
leaq -0x50(%rbp), %rdi
callq 0x8550
cmpq $0x40, (%rax)
jge 0x67fa
movq -0x20(%rbp), %rsi
movq 0xa848(%rip), %rdi      # 0x10ff0
callq 0x61e0
movq %rax, -0x100(%rbp)
jmp 0x67b6
movq -0x100(%rbp), %rdi
leaq 0x486a(%rip), %rsi      # 0xb02e
callq 0x61e0
movq %rax, -0x108(%rbp)
jmp 0x67d2
movq -0x108(%rbp), %rdi
movq 0xa7d0(%rip), %rsi      # 0x10fb0
callq 0x6240
jmp 0x67e7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x54(%rbp)
jmp 0x6a13
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rsi
leaq -0x78(%rbp), %rdi
movl $0x4, %edx
callq 0x9990
jmp 0x6816
leaq 0x4833(%rip), %rsi      # 0xb050
leaq -0x78(%rbp), %rdi
callq 0x8570
movb %al, -0x109(%rbp)
jmp 0x682e
leaq -0x78(%rbp), %rdi
callq 0x6130
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x6846
jmp 0x69cd
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
movl $0xc, %esi
callq 0x9b00
jmp 0x685e
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x9780
movl %eax, -0x110(%rbp)
jmp 0x6877
movl -0x110(%rbp), %eax
cmpl $0x1, %eax
je 0x68e0
movq 0xa767(%rip), %rdi      # 0x10ff0
leaq 0x47c5(%rip), %rsi      # 0xb055
callq 0x61e0
movq %rax, -0x118(%rbp)
jmp 0x689e
movq -0x118(%rbp), %rdi
movq 0xa704(%rip), %rsi      # 0x10fb0
callq 0x6240
jmp 0x68b3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x54(%rbp)
jmp 0x6a13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x6130
jmp 0x6a40
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
movl $0x14, %esi
callq 0x9b00
jmp 0x68f8
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x9780
movl %eax, -0x11c(%rbp)
jmp 0x6911
movl -0x11c(%rbp), %eax
shll $0x9, %eax
movl %eax, -0x7c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x9780
movl %eax, -0x120(%rbp)
jmp 0x6936
movl -0x120(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
movl -0x80(%rbp), %eax
movl %eax, %esi
callq 0x9b00
jmp 0x6957
leaq -0x50(%rbp), %rdi
callq 0x8550
movq %rax, %rsi
movl -0x7c(%rbp), %edx
leaq -0xa8(%rbp), %rdi
callq 0x9a40
jmp 0x6974
leaq -0x90(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x9400
jmp 0x6989
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x85a0
leaq -0x90(%rbp), %rdi
callq 0x85d0
leaq -0xa8(%rbp), %rdi
callq 0x85f0
jmp 0x69cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x85f0
jmp 0x6a40
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x128(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x8650
movq -0x128(%rbp), %rsi
movzbl -0x18(%rbp), %edx
andl $0x1, %edx
decl %edx
movl $0x2, %edi
callq 0x6a60
jmp 0x6a00
leaq -0xb8(%rbp), %rdi
callq 0x85d0
movl $0x0, -0x54(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x85d0
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x85d0
leaq -0x50(%rbp), %rdi
callq 0x85d0
movq -0x38(%rbp), %rdi
callq 0x6440
nopw %cs:(%rax,%rax)