// File: /workspace/github_c_makefile_star2_O1/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 0x4cf2
movq (%r12), %rdi
callq 0x4bc4
movb %al, 0x6(%rsp)
movq (%r12), %rdi
callq 0x4bc4
movb %al, 0x5(%rsp)
movq (%r12), %rdi
movl $0x8, %esi
callq 0x4cfc
movq (%r12), %rdi
callq 0x4b22
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 0x4cf2
movq (%r12), %rdi
callq 0x4bc4
movq %rax, 0x38(%rsp)
movq (%r12), %rdi
callq 0x4bc4
movb %al, 0x4(%rsp)
movq (%r12), %rdi
callq 0x4bc4
movl %eax, %ecx
movq (%r12), %r15
movq 0x8(%r12), %rbx
testq %rbx, %rbx
je 0x3953
movq 0x4683(%rip), %rax      # 0x7fc8
cmpb $0x0, (%rax)
je 0x394f
incl 0x8(%rbx)
jmp 0x3953
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 0x4bc4
movl %eax, %r14d
movzbl %al, %ebp
movl %ebp, %edi
callq 0x31c0
testl %eax, %eax
jne 0x39b1
leal -0x20(%rbp), %eax
cmpl $0x3f, %eax
ja 0x39c4
movabsq $-0x7fffffffffffbfff, %rcx # imm = 0x8000000000004001
btq %rax, %rcx
jae 0x39c4
movsbl %r14b, %esi
movq %r13, %rdi
callq 0x3160
decl %r12d
jne 0x3980
jmp 0x3a02
movq %r13, %rdi
movl $0x78, %esi
callq 0x3160
movl %ebp, %eax
shrl $0x4, %eax
leaq 0x16de(%rip), %rcx      # 0x50bb
movsbl (%rax,%rcx), %esi
movq %r13, %rdi
callq 0x3160
andl $0xf, %ebp
leaq 0x16c8(%rip), %rax      # 0x50bb
movsbl (%rbp,%rax), %esi
movq %r13, %rdi
callq 0x3160
jmp 0x39bd
testq %rbx, %rbx
je 0x3a0f
movq %rbx, %rdi
callq 0x48b4
movq 0xb0(%rsp), %r12
movq (%r12), %rdi
callq 0x4ba2
movl %eax, %ebx
movq 0x38(%rsp), %rax
decl %eax
cmpb $-0x3, %al
ja 0x3d9d
cmpl $0x0, 0x14(%rsp)
js 0x3b83
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x4583(%rip), %rdi      # 0x7fd0
callq 0x31f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3180
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3120
movl $0x6, %edx
movq %rax, %rdi
leaq 0x161e(%rip), %rsi      # 0x50a9
callq 0x31f0
movzwl %bx, %r14d
cmpb $0x10, 0x7(%rsp)
ja 0x3ae8
movl $0xfee8, %eax           # imm = 0xFEE8
movq 0x8(%rsp), %rcx
btq %rcx, %rax
jb 0x3ae8
movl 0x8(%rsp), %eax
movl $0xfee8, %ecx           # imm = 0xFEE8
btq %rax, %rcx
jb 0x3c48
leaq 0x419b(%rip), %rcx      # 0x7c60
movq (%rcx,%rax,8), %rbx
movq %rbx, %rdi
callq 0x30e0
movq 0x44f8(%rip), %rdi      # 0x7fd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x31f0
jmp 0x3c66
movq 0x44e1(%rip), %rdi      # 0x7fd0
movq 0x8(%rsp), %rsi
callq 0x32f0
cmpl $0x4, 0x8(%rsp)
jne 0x3d4c
movq 0x44c5(%rip), %rdi      # 0x7fd0
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 0x1584(%rip), %rsi      # 0x50b0
callq 0x31f0
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x1537(%rip), %rdx      # 0x507e
movq %rdx, %rsi
callq 0x4494
movq (%r12), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%r12), %rax
movq %rax, 0x58(%rsp)
testq %rax, %rax
je 0x3ca1
movq 0x4456(%rip), %rcx      # 0x7fc8
cmpb $0x0, (%rcx)
je 0x3c9d
incl 0x8(%rax)
jmp 0x3ca1
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0x4824
movq (%r12), %rax
movq %rax, 0x80(%rsp)
movq 0x8(%r12), %rax
movq %rax, 0x88(%rsp)
testq %rax, %rax
je 0x3be0
movq 0x43f6(%rip), %rcx      # 0x7fc8
cmpb $0x0, (%rcx)
je 0x3bdc
incl 0x8(%rax)
jmp 0x3be0
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 0x3f64
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3c1a
callq 0x48b4
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x3d9d
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x31b0
jmp 0x3d9d
movq 0x4381(%rip), %rcx      # 0x7fd0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x1, %esi
callq 0x32e0
movq 0x4363(%rip), %rcx      # 0x7fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3180
movsbl %al, %esi
movq 0x4345(%rip), %rdi      # 0x7fd0
callq 0x3040
movq %rax, %rdi
callq 0x3120
jmp 0x3d4c
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 0x3f64
movzwl %ax, %esi
movq 0x4304(%rip), %rdi      # 0x7fd0
callq 0x3110
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x142a(%rip), %rsi      # 0x510d
callq 0x31f0
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 0x3180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3120
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3d30
callq 0x48b4
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3d4c
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x31b0
movl $0x8, %edx
movq 0x4278(%rip), %rdi      # 0x7fd0
leaq 0x1353(%rip), %rsi      # 0x50b2
callq 0x31f0
movq 0x4265(%rip), %rdi      # 0x7fd0
movq %r14, %rsi
callq 0x3110
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3120
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3db9
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31b0
movq 0xc0(%rsp), %rax
incq %rax
cmpq $0x7, %rax
jne 0x38ed
movb 0x6(%rsp), %cl
testb %cl, %cl
je 0x3e28
movq (%r12), %rax
movq %rax, 0x40(%rsp)
movq 0x8(%r12), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x3e03
movq 0x41d3(%rip), %rdx      # 0x7fc8
cmpb $0x0, (%rdx)
je 0x3dff
incl 0x8(%rax)
jmp 0x3e03
lock
incl 0x8(%rax)
movzbl %cl, %edi
movzbl 0x5(%rsp), %esi
leaq 0x40(%rsp), %rdx
movl 0x14(%rsp), %ecx
callq 0x3876
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3e28
callq 0x48b4
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 0x3f00
jmp 0x3f05
jmp 0x3eb6
movq %rax, %r14
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3e67
callq 0x48b4
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x3eb9
movq 0xa0(%rsp), %rsi
jmp 0x3eac
movq %rax, %r14
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3e98
callq 0x48b4
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3eb9
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x31b0
jmp 0x3eb9
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3f05
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31b0
jmp 0x3f05
jmp 0x3ed9
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3ef8
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x31b0
testq %rbx, %rbx
je 0x3f05
movq %rbx, %rdi
callq 0x48b4
movq %r14, %rdi
callq 0x3320