// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/fsio/rt11.c
// Function: rt11Dir
static void rt11Dir(
  struct mountedFS *mount,
  uint8_t unit,
  char *fname
)
{
  struct RT11data *data = &mount->rt11data;
  struct rt11FileSpec spec;

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

  if (RT11_PARTITIONVALID(data, unit)) {
    uint16_t entrysz, dsseg = 1;
    regex_t reg;

    if ((spec.flags & (RT11_WC_NAME | RT11_WC_TYPE)) != 0)
      if (rt11BuildRegex(&spec, &reg) == 0) {
        fprintf(stderr, "dir: regcomp() failed\n");
        return;
      }

    do {
      uint16_t off = RT11_DH_SIZE;

      if (rt11ReadDirSegment(mount, unit, dsseg) == 0) {
        if ((spec.flags & (RT11_WC_NAME | RT11_WC_TYPE)) != 0)
          regfree(&reg);
        return;
      }

      entrysz = RT11_DI_SIZE + (le16toh(data->buf[RT11_DH_EXTRA]) >> 1);

      /*
       * Loop until we see and end-of-segment marker or there is no room for
       * another directory entry.
       */
      while (!RT11EOS(le16toh(data->buf[off + RT11_DI_STATUS])) &&
             ((RT11_DS_SIZE - off) >= entrysz)) {
        uint16_t status = le16toh(data->buf[off + RT11_DI_STATUS]);
        
        if ((status & (RT11_E_TENT | RT11_E_MPTY)) == 0) {
          uint16_t fname1 = le16toh(data->buf[off + RT11_DI_FNAME1]);
          uint16_t fname2 = le16toh(data->buf[off + RT11_DI_FNAME2]);
          uint16_t ftype = le16toh(data->buf[off + RT11_DI_FTYPE]);

          if ((spec.flags & (RT11_WC_NAME | RT11_WC_TYPE)) == 0) {
            if ((fname1 != spec.name[0]) ||
                (fname2 != spec.name[1]) ||
                (ftype != spec.type))
              goto nomatch;
          } else {
            if (rt11MatchRegex(&reg, fname1, fname2, ftype) == 0)
              goto nomatch;
          }

          rt11DisplayDir(&data->buf[off], SWISSET('f'));
        }

      nomatch:
        off += entrysz;
      }

      dsseg = le16toh(data->buf[RT11_DH_NEXT]);
    } while (dsseg != 0);

    if ((spec.flags & (RT11_WC_NAME | RT11_WC_TYPE)) != 0)
      regfree(&reg);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r12
leaq 0xa(%rsp), %rsi
movq %rdx, %rdi
movl $0x2, %edx
callq 0x9a00
testl %eax, %eax
je 0xbb20
movzbl %r15b, %ecx
shrb $0x3, %r15b
movzbl %r15b, %eax
andl $0x1e, %eax
movzwl 0x52(%r12,%rax), %eax
movl %ecx, 0x1c(%rsp)
andl $0xf, %ecx
btl %ecx, %eax
jae 0xbb42
testb $0x3, 0xa(%rsp)
je 0xb9c9
movb $0x5e, 0x30(%rsp)
movl $0x1, %r14d
movq $-0x6, %rbx
movzbl 0x18(%rsp,%rbx), %eax
cmpl $0x25, %eax
je 0xb918
cmpl $0x2a, %eax
je 0xb903
cmpl $0x20, %eax
je 0xb930
movsbq %al, %r15
callq 0x3030
movq (%rax), %rax
movb (%rax,%r15,4), %al
jmp 0xb91a
leal 0x1(%r14), %ecx
movl %r14d, %eax
movb $0x2e, 0x30(%rsp,%rax)
movb $0x2a, %al
movl $0x2, %edx
jmp 0xb922
movb $0x2e, %al
movl $0x1, %edx
movl %r14d, %ecx
addl %edx, %r14d
movl %ecx, %ecx
movb %al, 0x30(%rsp,%rcx)
incq %rbx
jne 0xb8dd
leal 0x1(%r14), %eax
movl %r14d, %ecx
movb $0x5c, 0x30(%rsp,%rcx)
addl $0x2, %r14d
movb $0x2e, 0x30(%rsp,%rax)
movq $-0x3, %rbx
movzbl 0x1b(%rsp,%rbx), %eax
movl $0x1, %ebp
cmpl $0x25, %eax
je 0xb98c
cmpl $0x2a, %eax
je 0xb977
cmpl $0x20, %eax
je 0xb99f
movsbq %al, %r15
callq 0x3030
movq (%rax), %rax
movb (%rax,%r15,4), %al
jmp 0xb98e
leal 0x1(%r14), %ecx
movl %r14d, %eax
movb $0x2e, 0x30(%rsp,%rax)
movb $0x2a, %al
movl $0x2, %ebp
jmp 0xb991
movb $0x2e, %al
movl %r14d, %ecx
addl %ebp, %r14d
movl %ecx, %ecx
movb %al, 0x30(%rsp,%rcx)
incq %rbx
jne 0xb94c
movl %r14d, %eax
incl %r14d
movb $0x24, 0x30(%rsp,%rax)
movb $0x0, 0x30(%rsp,%r14)
leaq 0x78(%rsp), %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x3190
testl %eax, %eax
jne 0xbb3d
leaq 0x472(%r12), %r13
leaq 0x47c(%r12), %rax
movq %rax, 0x20(%rsp)
movw $0x1, %bx
movq %r12, 0x28(%rsp)
movzwl %bx, %edx
movq %r12, %rdi
movl 0x1c(%rsp), %esi
callq 0xa037
movl %eax, %r15d
testl %eax, %eax
je 0xbaee
movzwl 0x478(%r12), %ecx
movzwl 0x47c(%r12), %eax
btl $0xb, %eax
setae %dl
cmpl $0x3ea, %ecx            # imm = 0x3EA
setb %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xbade
shrl %ecx
movl $0x1f9, %ebp            # imm = 0x1F9
subl %ecx, %ebp
movl %ecx, %r14d
addl $0x7, %r14d
movzwl %cx, %ebx
addl $0xc, %ebx
movl $0x5, %ecx
movq 0x20(%rsp), %r12
testl $0x300, %eax            # imm = 0x300
jne 0xbab8
movl %ecx, %eax
movzwl 0x2(%r13,%rax,2), %edx
movzwl 0x4(%r13,%rax,2), %ecx
movzwl 0x6(%r13,%rax,2), %eax
testb $0x3, 0xa(%rsp)
je 0xba8c
movzwl %dx, %esi
movzwl %cx, %edx
movzwl %ax, %ecx
leaq 0x78(%rsp), %rdi
callq 0x9bdf
testl %eax, %eax
jne 0xbaa1
jmp 0xbab8
cmpw 0xc(%rsp), %dx
jne 0xbab8
cmpw 0xe(%rsp), %cx
jne 0xbab8
cmpw 0x10(%rsp), %ax
jne 0xbab8
leaq 0xd520(%rip), %rax      # 0x18fc8
movl (%rax), %esi
shrl $0x5, %esi
andl $0x1, %esi
movq %r12, %rdi
callq 0xa1d6
movzwl %bx, %ecx
movzwl (%r13,%rcx,2), %eax
btl $0xb, %eax
jb 0xbade
leal (%rcx,%r14), %ebx
leaq (,%rcx,2), %r12
addq %r13, %r12
cmpl %ecx, %ebp
jge 0xba51
movq 0x28(%rsp), %r12
movzwl 0x474(%r12), %ebx
jmp 0xbaff
testb $0x3, 0xa(%rsp)
je 0xbaff
leaq 0x78(%rsp), %rdi
callq 0x3120
testl %r15d, %r15d
je 0xbb42
testw %bx, %bx
jne 0xb9e7
testb $0x3, 0xa(%rsp)
je 0xbb42
leaq 0x78(%rsp), %rdi
callq 0x3120
jmp 0xbb42
movq 0xc4c9(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x6251(%rip), %rsi      # 0x11d82
movq %r14, %rdx
xorl %eax, %eax
callq 0x31d0
jmp 0xbb42
callq 0x4245
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq