// File: /workspace/github_c_makefile_star2_O3/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 0x4d22(%rip), %rdi      # 0x71d0
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2070
movq 0x4b09(%rip), %rax      # 0x6fc8
movq (%rax), %rax
movq -0x18(%rax), %rbx
callq 0x2240
movq %rax, %r15
movl $0x18, %edi
callq 0x2190
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
callq 0x22d0
leaq 0x4754(%rip), %rax      # 0x6c40
movq %rax, (%r14)
addq 0x4ad2(%rip), %rbx      # 0x6fc8
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x3360
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2090
leaq 0x38(%rsp), %rdi
callq 0x2250
leaq 0x8(%rsp), %rdi
callq 0x2250
movq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x3928
movq (%rbx), %rdi
callq 0x3acc
testb %al, %al
je 0x2629
movq 0x8(%rsp), %rdi
cmpq $0x23000, (%rdi)        # imm = 0x23000
jne 0x265e
movl $0x11001, %esi          # imm = 0x11001
callq 0x3cb6
movq 0x8(%rsp), %rdi
callq 0x3b88
movl %eax, %ebx
movq 0x8(%rsp), %rdi
callq 0x3b88
movl %eax, %ebp
movq 0x8(%rsp), %rdi
movl $0x24, %esi
callq 0x3cc0
movq 0x8(%rsp), %rdi
callq 0x3b88
movl %eax, %r14d
movq 0x8(%rsp), %rdi
movl $0xc, %esi
callq 0x3cc0
movq 0x8(%rsp), %rdi
callq 0x3b88
movl %eax, %r15d
movq 0x8(%rsp), %rdi
callq 0x3b88
cmpb $0xf, %bpl
ja 0x269e
cmpb $0x22, %bl
ja 0x269e
cmpb $0x7a, %r14b
jne 0x269e
cmpb $0x23, %r15b
jne 0x269e
cmpb $0x10, %al
jne 0x269e
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x27c8
movq 0x49a8(%rip), %rcx      # 0x6fc0
cmpb $0x0, (%rcx)
je 0x27c4
incl 0x8(%rax)
jmp 0x27c8
movq 0x49b8(%rip), %r14      # 0x6fe8
leaq 0x1a03(%rip), %rsi      # 0x403a
movl $0xf, %edx
movq %r14, %rdi
callq 0x21f0
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x2684
movq %rbx, %rdi
callq 0x20e0
movq %rax, %rdx
jmp 0x26f5
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x26cb
movq %rbx, %rdi
callq 0x20e0
movq 0x4971(%rip), %rdi      # 0x6fe8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x26e9
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x22e0
jmp 0x2704
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0x2756
movq %rbx, %rdi
callq 0x20e0
movq 0x492d(%rip), %rdi      # 0x6fe8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x2774
movq 0x4916(%rip), %rax      # 0x6fe8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x22e0
movl $0x22, %edx
leaq 0x1955(%rip), %rbx      # 0x404a
movq 0x48ec(%rip), %rdi      # 0x6fe8
movq %rbx, %rsi
callq 0x21f0
movq 0x48dd(%rip), %rdi      # 0x6fe8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq 0x48c2(%rip), %rdi      # 0x6fe8
callq 0x2040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2120
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2747
callq 0x3876
movl %ebx, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x488b(%rip), %rax      # 0x6fe8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x22e0
movq 0x486d(%rip), %rbx      # 0x6fe8
leaq 0x18c8(%rip), %rsi      # 0x404a
movl $0x22, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq 0x483b(%rip), %rdi      # 0x6fe8
callq 0x2040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2120
jmp 0x2738
lock
incl 0x8(%rax)
movzbl 0x20(%rsp), %ecx
xorl $0x1, %ecx
negl %ecx
movzbl %bl, %edi
movzbl %bpl, %esi
leaq 0x28(%rsp), %rdx
callq 0x2856
movq 0x30(%rsp), %rdi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x2738
callq 0x3876
jmp 0x2738
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x283f
callq 0x3876
jmp 0x283f
jmp 0x283c
jmp 0x283c
jmp 0x283c
jmp 0x283c
jmp 0x283c
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2250
jmp 0x284e
movq %rax, %rbx
movl $0x18, %esi
movq %r14, %rdi
callq 0x21b0
jmp 0x284e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x284e
callq 0x3876
movq %rbx, %rdi
callq 0x2320