// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rsi, -0x88(%rbp)
movl %edi, %eax
movq -0x88(%rbp), %rdi
movw %ax, -0x2(%rbp)
movq %rdi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movzwl -0x2(%rbp), %eax
shll $0x9, %eax
addl $0x4, %eax
movl %eax, -0x18(%rbp)
callq 0x8550
movq %rax, %rdi
movl -0x18(%rbp), %eax
movl %eax, %esi
callq 0x9b00
movq -0x88(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x98b0
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
andl $0xf0, %eax
cmpl $0xf0, %eax
je 0x6b03
movzbl -0x19(%rbp), %eax
andl $0xf0, %eax
cmpl $0xe0, %eax
je 0x6b03
movq 0xa50d(%rip), %rdi      # 0x10ff0
leaq 0x45ba(%rip), %rsi      # 0xb0a4
callq 0x61e0
movq %rax, %rdi
movq 0xa4b7(%rip), %rsi      # 0x10fb0
callq 0x6240
jmp 0x6dfc
movq -0x88(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x8650
movq -0x90(%rbp), %rsi
movzbl -0x19(%rbp), %edx
andl $0xf, %edx
leaq -0x40(%rbp), %rdi
callq 0x6ec0
jmp 0x6b33
leaq -0x50(%rbp), %rdi
callq 0x85d0
cmpl $0x0, -0x14(%rbp)
jge 0x6b88
leaq -0x40(%rbp), %rdi
callq 0x60e0
movq %rax, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x6110
leaq -0x40(%rbp), %rdi
callq 0x60e0
movq %rax, %rdi
callq 0x6370
jmp 0x6bef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x85d0
jmp 0x6e0e
movl -0x14(%rbp), %edi
callq 0x7000
jmp 0x6b92
movq 0xa437(%rip), %rdi      # 0x10fd0
leaq -0x40(%rbp), %rsi
callq 0x61c0
movq %rax, -0x98(%rbp)
jmp 0x6bab
movq -0x98(%rbp), %rdi
leaq 0x44ff(%rip), %rsi      # 0xb0b8
callq 0x61e0
movq %rax, -0xa0(%rbp)
jmp 0x6bc7
movq -0xa0(%rbp), %rdi
movq 0xa3db(%rip), %rsi      # 0x10fb0
callq 0x6240
jmp 0x6bdc
jmp 0x6bef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x6e05
movq -0x88(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
movl -0x18(%rbp), %eax
addl $0x1f, %eax
movl %eax, %esi
callq 0x9b00
jmp 0x6c0d
movq -0x88(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x98b0
movb %al, -0xa1(%rbp)
jmp 0x6c29
movq -0x88(%rbp), %rdi
movb -0xa1(%rbp), %al
movb %al, -0x5d(%rbp)
callq 0x8550
movq %rax, %rdi
callq 0x98b0
movb %al, -0xa2(%rbp)
jmp 0x6c4e
movq -0x88(%rbp), %rdi
movb -0xa2(%rbp), %al
movb %al, -0x5e(%rbp)
callq 0x8550
movq %rax, %rdi
callq 0x9860
movw %ax, -0xa4(%rbp)
jmp 0x6c74
movw -0xa4(%rbp), %ax
movw %ax, -0x60(%rbp)
movb $0x1, -0x61(%rbp)
movw $0x0, -0x64(%rbp)
movzwl -0x64(%rbp), %eax
movzwl -0x60(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6de1
movq -0x88(%rbp), %rdi
movl -0x18(%rbp), %eax
movzbl -0x61(%rbp), %ecx
movzbl -0x5d(%rbp), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x68(%rbp)
callq 0x8550
movq %rax, %rdi
movl -0x68(%rbp), %eax
movl %eax, %esi
callq 0x9b00
jmp 0x6cc7
movq -0x88(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x98b0
movb %al, -0xa5(%rbp)
jmp 0x6ce3
movb -0xa5(%rbp), %al
movb %al, -0x69(%rbp)
cmpb $0x0, -0x69(%rbp)
je 0x6d76
movq -0x88(%rbp), %rsi
movl -0x68(%rbp), %eax
movl %eax, -0xac(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x8650
cmpl $0x0, -0x14(%rbp)
jge 0x6d22
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xb0(%rbp)
jmp 0x6d2e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
movl -0xac(%rbp), %edi
movl -0xb0(%rbp), %edx
leaq -0x80(%rbp), %rsi
callq 0x7040
jmp 0x6d45
leaq -0x80(%rbp), %rdi
callq 0x85d0
movw -0x64(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x64(%rbp)
jmp 0x6d76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x85d0
jmp 0x6e05
movb -0x61(%rbp), %al
addb $0x1, %al
movb %al, -0x61(%rbp)
movzbl -0x61(%rbp), %eax
movzbl -0x5e(%rbp), %ecx
cmpl %ecx, %eax
jne 0x6ddc
movq -0x88(%rbp), %rdi
movb $0x0, -0x61(%rbp)
callq 0x8550
movq %rax, %rdi
movl -0x18(%rbp), %eax
addl $-0x2, %eax
movl %eax, %esi
callq 0x9b00
jmp 0x6dac
movq -0x88(%rbp), %rdi
callq 0x8550
movq %rax, %rdi
callq 0x9860
movw %ax, -0xb2(%rbp)
jmp 0x6dc9
movw -0xb2(%rbp), %ax
movzwl %ax, %eax
shll $0x9, %eax
addl $0x4, %eax
movl %eax, -0x18(%rbp)
jmp 0x6c89
cmpl $0x0, -0x14(%rbp)
jge 0x6df3
leaq 0x42d1(%rip), %rdi      # 0xb0bf
callq 0x6370
leaq -0x40(%rbp), %rdi
callq 0x6130
addq $0xc0, %rsp
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x6130
movq -0x58(%rbp), %rdi
callq 0x6440
nopw (%rax,%rax)