// File: /workspace/github_c_makefile_star2_O2/mrkite[P]regs/src/2mg.cc
// Function: doDirectory(unsigned short, std::shared_ptr<TheHandle>, int)
static void doDirectory(uint16_t key, Handle h, int depth) {
  uint32_t block = key * 512 + 4;
  h->seek(block);
  auto type = h->r8();
  if ((type & 0xf0) != 0xf0 && (type & 0xf0) != 0xe0) {
    std::cerr << "Invalid ProDOS disk" << std::endl;
    return;
  }
  std::string dirname = readFilename(h, type & 0xf);
  if (depth < 0) {
    mkdir(dirname.c_str(), 0777);
    chdir(dirname.c_str());
  } else {
    indent(depth);
    std::cout << dirname << " <dir>" << std::endl;
  }
  h->seek(block + 0x1f);
  auto entryLength = h->r8();
  auto entriesPerBlock = h->r8();
  auto fileCount = h->r16();
  uint8_t curEntry = 1;
  uint16_t curFile = 0;

  while (curFile < fileCount) {
    auto entry = block + curEntry * entryLength;
    h->seek(entry);
    auto type = h->r8();
    if (type) {
      doEntry(entry, h, depth < 0 ? -1 : depth + 1);
      curFile++;
    }
    curEntry++;
    if (curEntry == entriesPerBlock) {
      curEntry = 0;
      h->seek(block - 2);
      block = h->r16() * 512 + 4;
    }
  }
  if (depth < 0) {
    chdir("..");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movl %edx, %r15d
movq %rsi, %r12
movl %edi, %ebx
shll $0x9, %ebx
leal 0x4(%rbx), %esi
movq (%r12), %rdi
movq %rsi, 0x48(%rsp)
callq 0x6c90
movq (%r12), %rdi
callq 0x6b8e
movl %eax, %ebp
andb $-0x20, %al
movzbl %al, %eax
orl $0x10, %eax
cmpl $0xf0, %eax
jne 0x5817
leaq 0x78(%rsp), %r14
movq %r14, %rdi
movq %r12, 0x40(%rsp)
movq %r12, %rsi
callq 0x6878
andb $0xf, %bpl
movzbl %bpl, %edx
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x60ec
leaq 0x80(%rsp), %rdi
callq 0x67fc
testl %r15d, %r15d
js 0x5843
movl %r15d, %edi
callq 0x61c3
movq 0x67df(%rip), %rdi      # 0xbfd0
leaq 0x88(%rsp), %rsi
callq 0x5170
leaq 0x18b3(%rip), %rsi      # 0x70b8
movq %rax, %rdi
callq 0x5180
movq %rax, %rdi
callq 0x5100
jmp 0x5862
movq 0x67d2(%rip), %rdi      # 0xbff0
leaq 0x187f(%rip), %rsi      # 0x70a4
callq 0x5180
movq %rax, %rdi
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5100
movq 0x88(%rsp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x50f0
movq 0x88(%rsp), %rdi
callq 0x5290
movq 0x40(%rsp), %rax
movq (%rax), %rdi
orl $0x23, %ebx
movq %rbx, %rsi
callq 0x6c90
movq 0x40(%rsp), %r14
movq (%r14), %rdi
callq 0x6b8e
movl %eax, %ebx
movq (%r14), %rdi
callq 0x6b8e
movb %al, 0xf(%rsp)
movq (%r14), %rdi
callq 0x6b6c
movw %ax, 0x26(%rsp)
leal 0x1(%r15), %r14d
movq %r15, 0x60(%rsp)
testl %r15d, %r15d
pushq $-0x1
popq %rax
cmovsl %eax, %r14d
movzbl %bl, %ecx
movl %ecx, 0x54(%rsp)
leal 0x1(%r14), %ecx
testl %r14d, %r14d
cmovsl %eax, %ecx
movl %ecx, 0x50(%rsp)
movb $0x1, %r15b
xorl %eax, %eax
movq %r14, 0x38(%rsp)
cmpw 0x26(%rsp), %ax
jae 0x5f42
movq %rax, 0x58(%rsp)
movzbl %r15b, %ebx
imull 0x54(%rsp), %ebx
addl 0x48(%rsp), %ebx
movq 0x40(%rsp), %r14
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x6c90
movq (%r14), %rdi
callq 0x6b8e
testb %al, %al
je 0x5be3
leaq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x6878
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x6c90
movq 0x10(%rsp), %rdi
callq 0x6b8e
movl %eax, %ebp
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x6878
movzbl %bpl, %r12d
movl %r12d, %edx
andl $0xf, %edx
leaq 0xf8(%rsp), %rdi
movq %r14, %rsi
callq 0x60ec
leaq 0xf0(%rsp), %rdi
callq 0x67fc
movq 0x10(%rsp), %rdi
addl $0x10, %ebx
movq %rbx, %rsi
callq 0x6c90
movq 0x10(%rsp), %rdi
callq 0x6b8e
movl %eax, %ebx
movq 0x10(%rsp), %rdi
callq 0x6b6c
movl %eax, %r14d
movq 0x10(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x6c9a
movq 0x10(%rsp), %rdi
callq 0x6b3a
movl %eax, %r13d
addb $0x30, %bpl
shrb $0x4, %bpl
movzbl %bpl, %eax
leal -0x4(%rax), %ecx
movzwl %r14w, %ebp
cmpl $0x3, %ecx
jae 0x5bed
cmpl $0x0, 0x38(%rsp)
js 0x5d9f
movq 0x10(%rsp), %rdi
callq 0x6b6c
movl %eax, %ebp
movq 0x10(%rsp), %rdi
callq 0x6b6c
movl %eax, %r14d
movq 0x10(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x6c9a
movq 0x10(%rsp), %rdi
callq 0x6b6c
movw %ax, 0x22(%rsp)
movq 0x10(%rsp), %rdi
callq 0x6b6c
movw %ax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
callq 0x6b6c
movl %eax, %r12d
movq 0x38(%rsp), %rdi
callq 0x61c3
movq 0x6594(%rip), %rdi      # 0xbfd0
leaq 0xf8(%rsp), %rsi
callq 0x5170
movq %rax, %rdi
callq 0x5100
movq 0x38(%rsp), %rdi
callq 0x61c3
movq 0x656e(%rip), %rdi      # 0xbfd0
leaq 0x166d(%rip), %rsi      # 0x70d6
callq 0x5180
movl %r13d, %esi
movq %rax, %rdi
callq 0x5120
movq 0x6550(%rip), %rdi      # 0xbfd0
leaq 0x1658(%rip), %rsi      # 0x70df
callq 0x5180
movzwl %bp, %edi
movzwl %r14w, %esi
callq 0x6437
movq 0x6531(%rip), %rdi      # 0xbfd0
leaq 0x1644(%rip), %rsi      # 0x70ea
callq 0x5180
movzwl 0x24(%rsp), %edi
movzwl %r12w, %esi
callq 0x6437
movq 0x6510(%rip), %rdi      # 0xbfd0
callq 0x5100
movq 0x38(%rsp), %rdi
callq 0x61c3
movq 0x64fa(%rip), %rdi      # 0xbfd0
leaq 0x1619(%rip), %rsi      # 0x70f6
callq 0x5180
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movl 0x18(%rax,%rdx), %esi
andl $-0x4b, %esi
orl $0x8, %esi
movl %esi, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq $0x2, 0x10(%rax,%rcx)
movq %rax, %rdi
pushq $0x30
popq %rsi
callq 0x52d0
movzbl %bl, %ebx
movq %rax, %rdi
movl %ebx, %esi
callq 0x5320
movq %rax, %rdi
leaq 0x15da(%rip), %rsi      # 0x7100
callq 0x5180
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x4, 0x10(%rax,%rcx)
movzwl 0x22(%rsp), %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0x5310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
leaq 0x156b(%rip), %rsi      # 0x70d4
callq 0x5180
shll $0x8, %ebp
orl %ebx, %ebp
xorl %eax, %eax
leaq 0x18(%rax), %rbx
cmpq $0x1770, %rbx           # imm = 0x1770
je 0x5bd2
leaq 0x4a47(%rip), %rdx      # 0xa5d0
movl (%rax,%rdx), %ecx
andl %ebp, %ecx
cmpl 0x4(%rax,%rdx), %ecx
movq %rbx, %rax
jne 0x5b75
leaq 0x4a32(%rip), %rax      # 0xa5d0
movq -0x10(%rbx,%rax), %rsi
movq 0x6426(%rip), %rdi      # 0xbfd0
callq 0x5180
movq %rax, %rdi
leaq 0x154f(%rip), %rsi      # 0x7108
callq 0x5180
leaq 0x4a0b(%rip), %rcx      # 0xa5d0
movq -0x8(%rbx,%rcx), %rsi
movq %rax, %rdi
callq 0x5180
movq 0x63f7(%rip), %rdi      # 0xbfd0
callq 0x5100
jmp 0x5edd
movq 0x58(%rsp), %rax
jmp 0x5efb
testl %eax, %eax
je 0x5dfd
cmpl $0x8, %eax
jne 0x5e32
leaq 0xb8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x5250
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x6878
movq 0x28(%rsp), %rdi
shll $0x9, %ebp
movq %rbp, %rsi
callq 0x6c90
leaq 0x148(%rsp), %r13
movq 0x28(%rsp), %rdi
callq 0x6b8e
movl %eax, %r14d
movq 0x28(%rsp), %rdi
callq 0x6b6c
movl %eax, %r12d
movq 0x28(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x6c9a
movq 0x28(%rsp), %rdi
callq 0x6b3a
movl %eax, %ebx
cmpl $0x0, 0x38(%rsp)
jns 0x5cbc
movq %r13, %rdi
leaq 0xb8(%rsp), %rsi
callq 0x5250
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x6878
movzbl %r14b, %r8d
movzwl %r12w, %edi
movl %ebx, %esi
movq %r13, %rdx
leaq 0x68(%rsp), %rcx
callq 0x61f3
leaq 0x70(%rsp), %rdi
callq 0x67fc
movq %r13, %rdi
callq 0x50e0
leaq 0x128(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x5250
leaq 0x128(%rsp), %rdi
leaq 0x2647(%rip), %rsi      # 0x8327
callq 0x5380
movq 0x28(%rsp), %rdi
orl $0x100, %ebp            # imm = 0x100
movq %rbp, %rsi
callq 0x6c90
movq 0x28(%rsp), %rdi
callq 0x6b8e
movl %eax, %r14d
movq 0x28(%rsp), %rdi
callq 0x6b6c
movl %eax, %r12d
movq 0x28(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x6c9a
movq 0x28(%rsp), %rdi
callq 0x6b3a
movl %eax, %ebp
movq 0x38(%rsp), %rdi
testl %edi, %edi
js 0x5e5d
callq 0x61c3
movq 0x628c(%rip), %rdi      # 0xbfd0
leaq 0xb8(%rsp), %rsi
callq 0x5170
movq %rax, %rdi
leaq 0x1378(%rip), %rsi      # 0x70d3
callq 0x5180
movl %ebx, %esi
movq %rax, %rdi
callq 0x5120
movq %rax, %rdi
leaq 0x25b8(%rip), %rsi      # 0x832c
callq 0x5180
movl %ebp, %esi
movq %rax, %rdi
callq 0x5120
movq %rax, %rdi
leaq 0x25b2(%rip), %rsi      # 0x833f
callq 0x5180
movq %rax, %rdi
callq 0x5100
jmp 0x5eb9
leaq 0x148(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x5250
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x6878
shrl $0x4, %r12d
movl %ebp, %edi
movl %r13d, %esi
leaq 0x148(%rsp), %rbx
movq %rbx, %rdx
movq %r14, %rcx
movl %r12d, %r8d
callq 0x61f3
leaq 0xe0(%rsp), %rdi
callq 0x67fc
movq %rbx, %rdi
jmp 0x5ed8
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x6878
movl %ebp, %edi
movq %rbx, %rsi
movl 0x50(%rsp), %edx
callq 0x575c
leaq 0xb0(%rsp), %rdi
callq 0x67fc
jmp 0x5edd
movq 0x61b7(%rip), %rdi      # 0xbff0
leaq 0x12ca(%rip), %rsi      # 0x710a
callq 0x5180
movq %rax, %rdi
movl %r12d, %esi
callq 0x5320
movq %rax, %rdi
callq 0x5100
jmp 0x5edd
leaq 0x168(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x5250
leaq 0x118(%rsp), %r13
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0x6878
movzbl %r14b, %r8d
movzwl %r12w, %edi
movl %ebp, %esi
leaq 0x168(%rsp), %rbx
movq %rbx, %rdx
movq %r13, %rcx
callq 0x61f3
leaq 0x120(%rsp), %rdi
callq 0x67fc
movq %rbx, %rdi
callq 0x50e0
leaq 0x128(%rsp), %rdi
callq 0x50e0
leaq 0x30(%rsp), %rdi
callq 0x67fc
leaq 0xb8(%rsp), %rdi
callq 0x50e0
leaq 0xf8(%rsp), %rdi
callq 0x50e0
leaq 0x18(%rsp), %rdi
callq 0x67fc
movq 0x58(%rsp), %rax
incl %eax
incb %r15b
cmpb 0xf(%rsp), %r15b
jne 0x58cf
movq %rax, %r12
movq 0x40(%rsp), %rbx
movq (%rbx), %rdi
movq 0x48(%rsp), %rsi
addl $-0x2, %esi
callq 0x6c90
movq (%rbx), %rdi
callq 0x6b6c
movzwl %ax, %eax
shll $0x9, %eax
orl $0x4, %eax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
movq %r12, %rax
jmp 0x58cf
cmpl $0x0, 0x60(%rsp)
jns 0x5f55
leaq 0x116f(%rip), %rdi      # 0x70bf
callq 0x5290
leaq 0x88(%rsp), %rdi
callq 0x50e0
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6058
jmp 0x6058
jmp 0x6058
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x67fc
jmp 0x608d
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x67fc
leaq 0x168(%rsp), %rdi
callq 0x50e0
jmp 0x602b
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x67fc
leaq 0x148(%rsp), %rdi
jmp 0x6033
jmp 0x6058
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x67fc
jmp 0x6069
jmp 0x6058
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x67fc
leaq 0x148(%rsp), %rdi
jmp 0x604f
jmp 0x6066
jmp 0x6066
jmp 0x6066
jmp 0x6066
jmp 0x6066
jmp 0x6066
jmp 0x6028
jmp 0x6066
jmp 0x6066
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x67fc
jmp 0x6076
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x50e0
jmp 0x603d
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x67fc
leaq 0xb8(%rsp), %rdi
callq 0x50e0
jmp 0x6069
jmp 0x6058
movq %rax, %rbx
jmp 0x6080
jmp 0x6066
jmp 0x6066
movq %rax, %rbx
jmp 0x6076
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x50e0
leaq 0x18(%rsp), %rdi
callq 0x67fc
leaq 0x88(%rsp), %rdi
callq 0x50e0
movq %rbx, %rdi
callq 0x5350