// File: /workspace/github_c_makefile_star2_O1/mrkite[P]regs/src/dsk.cc
// Function: main
int main(int argc, char **argv) {
  struct arguments arguments;
  arguments.list = false;

  argp_parse(&argp, argc, argv, 0, 0, &arguments);

  std::cout.imbue(std::locale(std::locale::classic(), new MyPunct));

  auto h = TheHandle::createFromFile(arguments.diskimage);
  if (!h->isOpen()) {
    std::cerr << "Failed to open " << arguments.diskimage << std::endl;
    return -1;
  }
  if (h->length != 143360) {
    std::cerr << arguments.diskimage << " is not a valid DOS 3.3 disk image"
              << std::endl;
    return -1;
  }
  h->seek(17 * 16 * 256 + 1);
  auto catTrack = h->r8();
  auto catSector = h->r8();
  h->skip(0x24);
  auto pairs = h->r8();
  h->skip(0xc);
  auto numTracks = h->r8();
  auto numSectors = h->r8();
  if (pairs != 0x7a || numTracks != 35 || numSectors != 16 ||
      catTrack >= numTracks || catSector >= numSectors) {
    std::cerr << arguments.diskimage << " is not a valid DOS 3.3 disk image"
              << std::endl;
    return -1;
  }
  catalog(catTrack, catSector, h, arguments.list ? 0 : -1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rsi, %rdx
movl %edi, %esi
leaq 0x18(%rsp), %r9
movb $0x0, 0x8(%r9)
leaq 0x4d02(%rip), %rdi      # 0x81d0
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3070
movq 0x4af1(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq -0x18(%rax), %rbx
callq 0x3240
movq %rax, %r15
movl $0x18, %edi
callq 0x3190
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x32d0
leaq 0x4704(%rip), %rax      # 0x7c10
movq %rax, (%r14)
addq 0x4aba(%rip), %rbx      # 0x7fd0
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x43a2
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3090
leaq 0x38(%rsp), %rdi
callq 0x3250
leaq 0x8(%rsp), %rdi
callq 0x3250
movq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4964
movq (%rbx), %rdi
callq 0x4b08
testb %al, %al
je 0x3649
movq 0x8(%rsp), %rdi
cmpq $0x23000, (%rdi)        # imm = 0x23000
jne 0x367e
movl $0x11001, %esi          # imm = 0x11001
callq 0x4cf2
movq 0x8(%rsp), %rdi
callq 0x4bc4
movl %eax, %ebx
movq 0x8(%rsp), %rdi
callq 0x4bc4
movl %eax, %ebp
movq 0x8(%rsp), %rdi
movl $0x24, %esi
callq 0x4cfc
movq 0x8(%rsp), %rdi
callq 0x4bc4
movl %eax, %r14d
movq 0x8(%rsp), %rdi
movl $0xc, %esi
callq 0x4cfc
movq 0x8(%rsp), %rdi
callq 0x4bc4
movl %eax, %r15d
movq 0x8(%rsp), %rdi
callq 0x4bc4
cmpb $0xf, %bpl
ja 0x36be
cmpb $0x22, %bl
ja 0x36be
cmpb $0x7a, %r14b
jne 0x36be
cmpb $0x23, %r15b
jne 0x36be
cmpb $0x10, %al
jne 0x36be
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x37e8
movq 0x4990(%rip), %rcx      # 0x7fc8
cmpb $0x0, (%rcx)
je 0x37e4
incl 0x8(%rax)
jmp 0x37e8
movq 0x49a0(%rip), %r14      # 0x7ff0
leaq 0x19e3(%rip), %rsi      # 0x503a
movl $0xf, %edx
movq %r14, %rdi
callq 0x31f0
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x36a4
movq %rbx, %rdi
callq 0x30e0
movq %rax, %rdx
jmp 0x3715
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x36eb
movq %rbx, %rdi
callq 0x30e0
movq 0x4959(%rip), %rdi      # 0x7ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x31f0
jmp 0x3709
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x32e0
jmp 0x3724
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x3776
movq %rbx, %rdi
callq 0x30e0
movq 0x4915(%rip), %rdi      # 0x7ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x31f0
jmp 0x3794
movq 0x48fe(%rip), %rax      # 0x7ff0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x32e0
movl $0x22, %edx
leaq 0x1935(%rip), %rbx      # 0x504a
movq 0x48d4(%rip), %rdi      # 0x7ff0
movq %rbx, %rsi
callq 0x31f0
movq 0x48c5(%rip), %rdi      # 0x7ff0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3180
movsbl %al, %esi
movq 0x48aa(%rip), %rdi      # 0x7ff0
callq 0x3040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x3120
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3767
callq 0x48b4
movl %ebx, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x4873(%rip), %rax      # 0x7ff0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x32e0
movq 0x4855(%rip), %rbx      # 0x7ff0
leaq 0x18a8(%rip), %rsi      # 0x504a
movl $0x22, %edx
movq %rbx, %rdi
callq 0x31f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3180
movsbl %al, %esi
movq 0x4823(%rip), %rdi      # 0x7ff0
callq 0x3040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x3120
jmp 0x3758
lock
incl 0x8(%rax)
movzbl 0x20(%rsp), %ecx
xorl $0x1, %ecx
negl %ecx
movzbl %bl, %edi
movzbl %bpl, %esi
leaq 0x28(%rsp), %rdx
callq 0x3876
movq 0x30(%rsp), %rdi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x3758
callq 0x48b4
jmp 0x3758
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x385f
callq 0x48b4
jmp 0x385f
jmp 0x385c
jmp 0x385c
jmp 0x385c
jmp 0x385c
jmp 0x385c
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3250
jmp 0x386e
movq %rax, %rbx
movl $0x18, %esi
movq %r14, %rdi
callq 0x31b0
jmp 0x386e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x386e
callq 0x48b4
movq %rbx, %rdi
callq 0x3320