// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/dosmt.c
// Function: dosmtDir
static void dosmtDir(
  struct mountedFS *mount,
  uint8_t UNUSED(unit),
  char *fname
)
{
  struct DOSMTdata *data = &mount->dosmtdata;
  struct dosmtFileSpec spec;
  uint32_t status;

  if (dosmtParseFilespec(mount, fname, &spec, DOSMT_M_NONAME) == 0) {
    fprintf(stderr, "dir: syntax error in file spec \"%s\"\n", fname);
    return;
  }

  /*
   * Position to beginning-of-tape unless the '-n' switch is specified.
   */
  if (!SWISSET('n'))
    tapeRewind(mount->container);

  do {
    switch (status = tapeReadRecord(mount->container, data->buf, DOSMTRCLNT)) {
      case ST_FAIL:
        return;

      case ST_EOM:
        break;

      case ST_TM:
        /* Second tape mark in a row - treat as end-of-media */
        status = ST_EOM;
        break;

      default:
        if ((status & ST_ERROR) == 0) {
          if (status == sizeof(struct dosmthdr)) {
            char filename[14], sdate[12];
            struct dosmthdr *hdr = (struct dosmthdr *)data->buf;
            uint16_t blocks = 0;
            uint32_t length;

            /*
             * Compute the number of blocks in this file.
             */
            do {
              switch (length = tapeReadRecordLength(mount->container)) {
                case ST_FAIL:
                  return;

                case ST_EOM:
                case ST_TM:
                  break;

                default:
                  if ((length & ST_ERROR) == 0)
                    blocks++;
                  break;
              }
            } while ((length != ST_EOM) && (length != ST_TM));

            /*
             * Determine if this file matches the filespec.
             */
            if ((spec.flags & DOSMT_WC_PROJ) == 0)
              if (spec.proj != hdr->proj)
                continue;

            if ((spec.flags & DOSMT_WC_PROG) == 0)
              if (spec.prog != hdr->prog)
                continue;

            if ((spec.flags & DOSMT_WC_NAME) == 0) {
              if ((spec.name[0] != le16toh(hdr->fname[0])) ||
                  (spec.name[1] != le16toh(hdr->fname[1])))
                continue;

              if ((mount->flags & FS_DOSMTEXT) != 0)
                if (spec.name[2] != le16toh(hdr->fname3))
                  continue;
            }

            if ((spec.flags & DOSMT_WC_EXT) == 0)
              if (spec.ext != le16toh(hdr->ext))
                continue;
              
            memset(filename, ' ', sizeof(filename));
            filename[13] = '\0';

            r50Asc(le16toh(hdr->fname[0]), &filename[0]);
            r50Asc(le16toh(hdr->fname[1]), &filename[3]);
            if ((mount->flags & FS_DOSMTEXT) != 0)
              r50Asc(le16toh(hdr->fname3), &filename[6]);
            filename[9] = '.';
            r50Asc(le16toh(hdr->ext), &filename[10]);

            if (SWISSET('f')) {
              dos11Date(le16toh(hdr->date), sdate);

              printf("%s %5d. %s <%03o> [%3o,%3o]\n",
                     filename, blocks, sdate,
                     le16toh(hdr->prot), hdr->proj, hdr->prog);
            } else printf("%s [%3o,%3o]\n", filename, hdr->proj, hdr->prog);
          } else fprintf(stderr, "   *** Unexpected record size\n");
        } else fprintf(stderr, "  *** Directory entry contains error\n");
    }
  } while (status != ST_EOM);

  tapeRewind(mount->container);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
movl $0x2, %ecx
callq 0x10380
cmpl $0x0, %eax
jne 0x11451
movq 0xcbc1(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x8a62(%rip), %rsi      # 0x19ea7
movb $0x0, %al
callq 0x31c0
jmp 0x11809
leaq 0xdda0(%rip), %rax      # 0x1f1f8
movl (%rax), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x11471
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x68d0
jmp 0x11473
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x64d0
movl %eax, -0x30(%rbp)
movl %eax, %ecx
movl %ecx, -0x64(%rbp)
subl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0x114ad
jmp 0x1149a
movl -0x64(%rbp), %eax
subl $-0x1, %eax
je 0x114b2
jmp 0x114a4
movl -0x64(%rbp), %eax
testl %eax, %eax
je 0x114b7
jmp 0x114c3
jmp 0x11809
jmp 0x117f0
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x117f0
movl -0x30(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x117d6
movl -0x30(%rbp), %eax
cmpq $0xe, %rax
jne 0x117bc
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movw $0x0, -0x5a(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6290
movl %eax, -0x60(%rbp)
movl %eax, %ecx
movl %ecx, -0x68(%rbp)
subl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0x11519
jmp 0x1150d
movl -0x68(%rbp), %eax
incl %eax
subl $0x2, %eax
jb 0x1151e
jmp 0x11520
jmp 0x11809
jmp 0x1153b
movl -0x60(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x11539
movw -0x5a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x5a(%rbp)
jmp 0x1153b
jmp 0x1153d
xorl %eax, %eax
cmpl $-0x1, -0x60(%rbp)
movb %al, -0x69(%rbp)
je 0x11552
cmpl $0x0, -0x60(%rbp)
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x114ef
movzbl -0x2c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x1157c
movzbl -0x22(%rbp), %eax
movq -0x58(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
cmpl %ecx, %eax
je 0x1157a
jmp 0x117f2
jmp 0x1157c
movzbl -0x2c(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x1159f
movzbl -0x21(%rbp), %eax
movq -0x58(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
cmpl %ecx, %eax
je 0x1159d
jmp 0x117f2
jmp 0x1159f
movzbl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x11631
movzwl -0x2a(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x58(%rbp), %rax
movzwl (%rax), %edi
callq 0x10b80
movw %ax, %cx
movl -0x70(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
jne 0x115f0
movzwl -0x28(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x58(%rbp), %rax
movzwl 0x2(%rax), %edi
callq 0x10b80
movw %ax, %cx
movl -0x74(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
je 0x115f5
jmp 0x117f2
movq -0x8(%rbp), %rax
movzwl 0x30(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x1162f
movzwl -0x26(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movzwl 0xc(%rax), %edi
callq 0x10b80
movw %ax, %cx
movl -0x78(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
je 0x1162d
jmp 0x117f2
jmp 0x1162f
jmp 0x11631
movzbl -0x2c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x11665
movzwl -0x24(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x58(%rbp), %rax
movzwl 0x4(%rax), %edi
callq 0x10b80
movw %ax, %cx
movl -0x7c(%rbp), %eax
movzwl %cx, %ecx
cmpl %ecx, %eax
je 0x11663
jmp 0x117f2
jmp 0x11665
leaq -0x3e(%rbp), %rdi
movl $0x20, %esi
movl $0xe, %edx
callq 0x3170
movb $0x0, -0x31(%rbp)
movq -0x58(%rbp), %rax
movzwl (%rax), %edi
callq 0x10b80
leaq -0x3e(%rbp), %rsi
movzwl %ax, %edi
callq 0x5bf0
movq -0x58(%rbp), %rax
movzwl 0x2(%rax), %edi
callq 0x10b80
leaq -0x3e(%rbp), %rsi
addq $0x3, %rsi
movzwl %ax, %edi
callq 0x5bf0
movq -0x8(%rbp), %rax
movzwl 0x30(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x116e0
movq -0x58(%rbp), %rax
movzwl 0xc(%rax), %edi
callq 0x10b80
leaq -0x3e(%rbp), %rsi
addq $0x6, %rsi
movzwl %ax, %edi
callq 0x5bf0
movb $0x2e, -0x35(%rbp)
movq -0x58(%rbp), %rax
movzwl 0x4(%rax), %edi
callq 0x10b80
leaq -0x3e(%rbp), %rsi
addq $0xa, %rsi
movzwl %ax, %edi
callq 0x5bf0
leaq 0xdaf0(%rip), %rax      # 0x1f1f8
movl (%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x11798
movq -0x58(%rbp), %rax
movzwl 0xa(%rax), %edi
callq 0x10b80
leaq -0x4a(%rbp), %rsi
movzwl %ax, %edi
callq 0x5e90
leaq -0x3e(%rbp), %rax
movq %rax, -0x98(%rbp)
movzwl -0x5a(%rbp), %eax
movl %eax, -0x8c(%rbp)
leaq -0x4a(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %rax
movzwl 0x8(%rax), %edi
callq 0x10b80
movq -0x98(%rbp), %rsi
movl -0x8c(%rbp), %edx
movq -0x88(%rbp), %rcx
movzwl %ax, %r8d
movq -0x58(%rbp), %rax
movzbl 0x7(%rax), %r9d
movq -0x58(%rbp), %rax
movzbl 0x6(%rax), %eax
leaq 0x8e9d(%rip), %rdi      # 0x1a629
movl %eax, (%rsp)
movb $0x0, %al
callq 0x3160
jmp 0x117ba
leaq -0x3e(%rbp), %rsi
movq -0x58(%rbp), %rax
movzbl 0x7(%rax), %edx
movq -0x58(%rbp), %rax
movzbl 0x6(%rax), %ecx
leaq 0x8e93(%rip), %rdi      # 0x1a646
movb $0x0, %al
callq 0x3160
jmp 0x117d4
movq 0xc835(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0x8e87(%rip), %rsi      # 0x1a654
movb $0x0, %al
callq 0x31c0
jmp 0x117ee
movq 0xc81b(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0x8e8c(%rip), %rsi      # 0x1a673
movb $0x0, %al
callq 0x31c0
jmp 0x117f0
jmp 0x117f2
cmpl $-0x1, -0x30(%rbp)
jne 0x11473
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x68d0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)