// File: /workspace/github_c_makefile_star2_O2/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 $0xd8, %rsp
movl %ecx, 0x24(%rsp)
movq %rdx, %r14
movq (%rdx), %rax
shll $0xc, %edi
shll $0x8, %esi
addq %rdi, %rsi
incq %rsi
movq %rax, %rdi
callq 0x385c
movq (%r14), %rdi
callq 0x375a
movb %al, 0xd(%rsp)
movq (%r14), %rdi
callq 0x375a
movb %al, 0xc(%rsp)
movq (%r14), %rdi
pushq $0x8
popq %rsi
callq 0x3866
movq (%r14), %rdi
callq 0x36b8
movq %rax, 0x28(%rsp)
xorl %eax, %eax
leaq 0x58(%rsp), %r15
cmpq $0x7, %rax
je 0x2a4e
movq (%r14), %rdi
movq %rax, 0x30(%rsp)
imulq $0x23, %rax, %rsi
addq 0x28(%rsp), %rsi
callq 0x385c
movq (%r14), %rdi
callq 0x375a
movq %rax, 0x18(%rsp)
movq (%r14), %rdi
callq 0x375a
movb %al, 0xe(%rsp)
movq (%r14), %rdi
callq 0x375a
movl %eax, %r13d
andb $0x7f, %r13b
movzbl %r13b, %eax
movq %rax, 0x10(%rsp)
leaq 0x48(%rsp), %rdi
movq %r14, %rbp
movq %r14, %rsi
callq 0x3422
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
andq $0x0, 0x60(%rsp)
movb $0x0, 0x68(%rsp)
pushq $0x1e
popq %r14
subl $0x1, %r14d
jb 0x283d
movq 0x48(%rsp), %rdi
callq 0x375a
movl %eax, %r12d
movzbl %al, %ebx
movl %ebx, %edi
callq 0x21a0
testl %eax, %eax
jne 0x27f1
leal -0x20(%rbx), %eax
cmpl $0x3f, %eax
ja 0x27ff
movabsq $-0x7fffffffffffbfff, %rcx # imm = 0x8000000000004001
btq %rax, %rcx
jae 0x27ff
movsbl %r12b, %esi
movq %r15, %rdi
callq 0x2130
jmp 0x27b8
movq %r15, %rdi
pushq $0x78
popq %rsi
callq 0x2130
movl %ebx, %eax
shrl $0x4, %eax
leaq 0x18a5(%rip), %rcx      # 0x40bb
movsbl (%rax,%rcx), %esi
movq %r15, %rdi
callq 0x2130
andl $0xf, %ebx
leaq 0x188f(%rip), %rax      # 0x40bb
movsbl (%rbx,%rax), %esi
movq %r15, %rdi
callq 0x2130
jmp 0x27b8
leaq 0x50(%rsp), %rdi
callq 0x3456
movq %rbp, %r14
movq (%rbp), %rdi
callq 0x3738
movq 0x18(%rsp), %rdx
leal -0x1(%rdx), %ecx
cmpb $-0x3, %cl
ja 0x2a39
movzbl %dl, %ebp
movzbl 0xe(%rsp), %r12d
movzwl %ax, %eax
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x24(%rsp)
js 0x29df
movq 0x474a(%rip), %rdi      # 0x6fd0
movq %r15, %rsi
callq 0x2150
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
leaq 0x1809(%rip), %rsi      # 0x40a9
callq 0x2160
cmpb $0x10, %r13b
ja 0x28e3
movl $0xfee8, %eax           # imm = 0xFEE8
movq 0x10(%rsp), %rcx
btq %rcx, %rax
jb 0x28e3
movl 0x10(%rsp), %eax
leaq 0x43da(%rip), %rcx      # 0x6ca0
movq (%rcx,%rax,8), %rsi
movq 0x46ff(%rip), %rdi      # 0x6fd0
callq 0x2160
movq %rax, %rdi
callq 0x20e0
jmp 0x29b6
movq 0x46e6(%rip), %rdi      # 0x6fd0
movq 0x10(%rsp), %rsi
callq 0x22d0
cmpl $0x4, 0x10(%rsp)
jne 0x29b6
movq 0x46ca(%rip), %rdi      # 0x6fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl 0x18(%rdi,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rdi,%rax)
leaq 0x178e(%rip), %rsi      # 0x40b0
callq 0x2160
movq %rax, %rbx
leaq 0xb8(%rsp), %r13
movq %r13, %rdi
leaq 0x1742(%rip), %rsi      # 0x407e
leaq 0xf(%rsp), %rdx
callq 0x2fa6
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x3422
movl %ebp, %edi
movl %r12d, %esi
pushq $0x4
popq %rdx
movq %r13, %rcx
movl 0x18(%rsp), %r8d
leaq 0x38(%rsp), %r9
callq 0x2b68
movzwl %ax, %esi
movq %rbx, %rdi
callq 0x22c0
movq %rax, %rdi
leaq 0x178b(%rip), %rsi      # 0x410d
callq 0x2160
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
callq 0x20e0
leaq 0x40(%rsp), %rdi
callq 0x3456
movq %r13, %rdi
callq 0x20d0
movq 0x4613(%rip), %rdi      # 0x6fd0
leaq 0x16ee(%rip), %rsi      # 0x40b2
callq 0x2160
movq %rax, %rdi
movl 0x18(%rsp), %esi
callq 0x22c0
movq %rax, %rdi
callq 0x20e0
jmp 0x2a39
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x2220
leaq 0x88(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x3422
movl %ebp, %edi
movl %r12d, %esi
movq 0x10(%rsp), %rdx
leaq 0x98(%rsp), %rbx
movq %rbx, %rcx
movl 0x18(%rsp), %r8d
movq %r13, %r9
callq 0x2b68
leaq 0x90(%rsp), %rdi
callq 0x3456
movq %rbx, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x20d0
movq 0x30(%rsp), %rax
incq %rax
jmp 0x273e
movb 0xd(%rsp), %bpl
testb %bpl, %bpl
je 0x2a8a
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3422
movzbl %bpl, %edi
movzbl 0xc(%rsp), %esi
movq %rbx, %rdx
movl 0x24(%rsp), %ecx
callq 0x26d8
leaq 0x80(%rsp), %rdi
callq 0x3456
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x2b04
jmp 0x2ae1
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x3456
leaq 0x98(%rsp), %rdi
jmp 0x2ada
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3456
leaq 0xb8(%rsp), %rdi
callq 0x20d0
jmp 0x2ae4
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x20d0
jmp 0x2b09
jmp 0x2af2
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x20d0
leaq 0x50(%rsp), %rdi
callq 0x3456
movq %rbx, %rdi
callq 0x2300