// File: /workspace/github_c_makefile_star2_O3/mrkite[P]regs/src/dsk.cc
// Function: catalog(unsigned char, unsigned char, std::shared_ptr<TheHandle>, int)
static void catalog(uint8_t track, uint8_t sector, Handle h, int depth) {
  h->seek(track * 16 * 256 + sector * 256 + 1);
  auto nextTrack = h->r8();
  auto nextSector = h->r8();
  h->skip(8);
  auto ofs = h->tell();
  for (auto i = 0; i < 7; i++) {
    h->seek(ofs + i * 35);
    auto ftrack = h->r8();
    auto fsector = h->r8();
    auto type = h->r8() & 0x7f;
    auto name = readFilename(h, 30);
    auto length = h->r16();
    if (ftrack != 0xff && ftrack != 0x00) {
      if (depth < 0) {
        doFile(ftrack, fsector, type, name, length, h);
      } else {
        std::cout << name << std::endl << "Type: ";
        if (type < numTypes && types[type] != nullptr) {
          std::cout << types[type] << std::endl;
        } else {
          std::cout << static_cast<int>(type);
          if (type == 0x04) {  // binary
            std::cout << std::hex << "("
                      << doFile(ftrack, fsector, type, "", length, h)
                      << ")" << std::dec << std::endl;
          }
        }
        std::cout << "Blocks: " << length << std::endl;
      }
    }
  }
  if (nextTrack != 0) {
    catalog(nextTrack, nextSector, h, depth);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %ecx, 0x14(%rsp)
movq %rdx, %r12
movq (%rdx), %rax
shll $0xc, %edi
shll $0x8, %esi
addq %rdi, %rsi
incq %rsi
movq %rax, %rdi
callq 0x3cb6
movq (%r12), %rdi
callq 0x3b88
movb %al, 0x6(%rsp)
movq (%r12), %rdi
callq 0x3b88
movb %al, 0x5(%rsp)
movq (%r12), %rdi
movl $0x8, %esi
callq 0x3cc0
movq (%r12), %rdi
callq 0x3ae6
movq %rax, 0xb8(%rsp)
xorl %eax, %eax
leaq 0x18(%rsp), %r13
movq %r12, 0xb0(%rsp)
movq (%r12), %rdi
movq %rax, 0xc0(%rsp)
imulq $0x23, %rax, %rsi
addq 0xb8(%rsp), %rsi
callq 0x3cb6
movq (%r12), %rdi
callq 0x3b88
movq %rax, 0x38(%rsp)
movq (%r12), %rdi
callq 0x3b88
movb %al, 0x4(%rsp)
movq (%r12), %rdi
callq 0x3b88
movl %eax, %ecx
movq (%r12), %r15
movq 0x8(%r12), %rbx
testq %rbx, %rbx
je 0x2933
movq 0x469b(%rip), %rax      # 0x6fc0
cmpb $0x0, (%rax)
je 0x292f
incl 0x8(%rbx)
jmp 0x2933
lock
incl 0x8(%rbx)
andb $0x7f, %cl
movb %cl, 0x7(%rsp)
movzbl %cl, %eax
movq %rax, 0x8(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movl $0x1e, %r12d
movq %r15, %rdi
callq 0x3b88
movl %eax, %r14d
movzbl %al, %ebp
movl %ebp, %edi
callq 0x21c0
testl %eax, %eax
jne 0x2991
leal -0x20(%rbp), %eax
cmpl $0x3f, %eax
ja 0x29a4
movabsq $-0x7fffffffffffbfff, %rcx # imm = 0x8000000000004001
btq %rax, %rcx
jae 0x29a4
movsbl %r14b, %esi
movq %r13, %rdi
callq 0x2160
decl %r12d
jne 0x2960
jmp 0x29e2
movq %r13, %rdi
movl $0x78, %esi
callq 0x2160
movl %ebp, %eax
shrl $0x4, %eax
leaq 0x16fe(%rip), %rcx      # 0x40bb
movsbl (%rax,%rcx), %esi
movq %r13, %rdi
callq 0x2160
andl $0xf, %ebp
leaq 0x16e8(%rip), %rax      # 0x40bb
movsbl (%rbp,%rax), %esi
movq %r13, %rdi
callq 0x2160
jmp 0x299d
testq %rbx, %rbx
je 0x29ef
movq %rbx, %rdi
callq 0x3876
movq 0xb0(%rsp), %r12
movq (%r12), %rdi
callq 0x3b66
movl %eax, %ebx
movq 0x38(%rsp), %rax
decl %eax
cmpb $-0x3, %al
ja 0x2d4b
cmpl $0x0, 0x14(%rsp)
js 0x2b86
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x459b(%rip), %rdi      # 0x6fc8
callq 0x21f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
movl $0x6, %edx
movq %rax, %rdi
leaq 0x163e(%rip), %rsi      # 0x40a9
callq 0x21f0
movzwl %bx, %r14d
cmpb $0x10, 0x7(%rsp)
ja 0x2aeb
movl $0xfee8, %eax           # imm = 0xFEE8
movq 0x8(%rsp), %rcx
btq %rcx, %rax
jb 0x2aeb
movl 0x8(%rsp), %eax
leaq 0x41fa(%rip), %rcx      # 0x6c90
movq (%rcx,%rax,8), %rbx
movq %rbx, %rdi
callq 0x20e0
movq 0x451f(%rip), %rdi      # 0x6fc8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21f0
movq 0x450d(%rip), %rcx      # 0x6fc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq 0x44ef(%rip), %rdi      # 0x6fc8
callq 0x2040
movq %rax, %rdi
callq 0x2120
jmp 0x2cfa
movq 0x44d6(%rip), %rdi      # 0x6fc8
movq 0x8(%rsp), %rsi
callq 0x22f0
cmpl $0x4, 0x8(%rsp)
jne 0x2cfa
movq 0x44ba(%rip), %rdi      # 0x6fc8
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl 0x18(%rdi,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rdi,%rax)
movl $0x1, %edx
leaq 0x1581(%rip), %rsi      # 0x40b0
callq 0x21f0
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x1534(%rip), %rdx      # 0x407e
movq %rdx, %rsi
callq 0x3452
movq (%r12), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%r12), %rax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x2c4f
movq 0x444b(%rip), %rcx      # 0x6fc0
cmpb $0x0, (%rcx)
je 0x2c4b
incl 0x8(%rax)
jmp 0x2c4f
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0x37e0
movq (%r12), %rax
movq %rax, 0x80(%rsp)
movq 0x8(%r12), %rax
movq %rax, 0x88(%rsp)
testq %rax, %rax
je 0x2be3
movq 0x43eb(%rip), %rcx      # 0x6fc0
cmpb $0x0, (%rcx)
je 0x2bdf
incl 0x8(%rax)
jmp 0x2be3
lock
incl 0x8(%rax)
movzbl 0x38(%rsp), %edi
movzbl 0x4(%rsp), %esi
movzwl %bx, %r8d
movq 0x8(%rsp), %rdx
leaq 0x90(%rsp), %rcx
leaq 0x80(%rsp), %r9
callq 0x2f12
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2c1d
callq 0x3876
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d4b
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x2d4b
lock
incl 0x8(%rax)
movzbl 0x38(%rsp), %edi
movzbl 0x4(%rsp), %esi
movl $0x4, %edx
leaq 0x60(%rsp), %rcx
movl %r14d, %r8d
leaq 0x50(%rsp), %r9
callq 0x2f12
movzwl %ax, %esi
movq 0x434e(%rip), %rdi      # 0x6fc8
callq 0x2110
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x147c(%rip), %rsi      # 0x410d
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2cde
callq 0x3876
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x2cfa
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21b0
movl $0x8, %edx
movq 0x42c2(%rip), %rdi      # 0x6fc8
leaq 0x13a5(%rip), %rsi      # 0x40b2
callq 0x21f0
movq 0x42af(%rip), %rdi      # 0x6fc8
movq %r14, %rsi
callq 0x2110
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2d67
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq 0xc0(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x28cd
movb 0x6(%rsp), %cl
testb %cl, %cl
je 0x2dd6
movq (%r12), %rax
movq %rax, 0x40(%rsp)
movq 0x8(%r12), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x2db1
movq 0x421d(%rip), %rdx      # 0x6fc0
cmpb $0x0, (%rdx)
je 0x2dad
incl 0x8(%rax)
jmp 0x2db1
lock
incl 0x8(%rax)
movzbl %cl, %edi
movzbl 0x5(%rsp), %esi
leaq 0x40(%rsp), %rdx
movl 0x14(%rsp), %ecx
callq 0x2856
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2dd6
callq 0x3876
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
jne 0x2eae
jmp 0x2eb3
jmp 0x2e64
movq %rax, %r14
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2e15
callq 0x3876
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e67
movq 0xa0(%rsp), %rsi
jmp 0x2e5a
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2e46
callq 0x3876
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x2e67
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x2e67
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2eb3
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
jmp 0x2eb3
jmp 0x2e87
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2ea6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
testq %rbx, %rbx
je 0x2eb3
movq %rbx, %rdi
callq 0x3876
movq %r14, %rdi
callq 0x2320