// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r13
leaq 0x2(%rsp), %rsi
movq %rdx, %rdi
movl $0x2, %edx
callq 0x96e0
testl %eax, %eax
je 0xb792
movzbl %r15b, %ecx
shrb $0x3, %r15b
movzbl %r15b, %eax
andl $0x1e, %eax
movzwl 0x52(%r13,%rax), %eax
movl %ecx, 0x14(%rsp)
andl $0xf, %ecx
btl %ecx, %eax
jae 0xb780
testb $0x3, 0x2(%rsp)
je 0xb657
movb $0x5e, 0x20(%rsp)
movl $0x1, %r14d
movq $-0x6, %rbx
movzbl 0x10(%rsp,%rbx), %eax
cmpl $0x25, %eax
je 0xb5a6
cmpl $0x2a, %eax
je 0xb591
cmpl $0x20, %eax
je 0xb5be
movsbq %al, %r15
callq 0x3030
movq (%rax), %rax
movb (%rax,%r15,4), %al
jmp 0xb5a8
leal 0x1(%r14), %ecx
movl %r14d, %eax
movb $0x2e, 0x20(%rsp,%rax)
movb $0x2a, %al
movl $0x2, %edx
jmp 0xb5b0
movb $0x2e, %al
movl $0x1, %edx
movl %r14d, %ecx
addl %edx, %r14d
movl %ecx, %ecx
movb %al, 0x20(%rsp,%rcx)
incq %rbx
jne 0xb56b
leal 0x1(%r14), %eax
movl %r14d, %ecx
movb $0x5c, 0x20(%rsp,%rcx)
addl $0x2, %r14d
movb $0x2e, 0x20(%rsp,%rax)
movq $-0x3, %rbx
movzbl 0x13(%rsp,%rbx), %eax
movl $0x1, %ebp
cmpl $0x25, %eax
je 0xb61a
cmpl $0x2a, %eax
je 0xb605
cmpl $0x20, %eax
je 0xb62d
movsbq %al, %r15
callq 0x3030
movq (%rax), %rax
movb (%rax,%r15,4), %al
jmp 0xb61c
leal 0x1(%r14), %ecx
movl %r14d, %eax
movb $0x2e, 0x20(%rsp,%rax)
movb $0x2a, %al
movl $0x2, %ebp
jmp 0xb61f
movb $0x2e, %al
movl %r14d, %ecx
addl %ebp, %r14d
movl %ecx, %ecx
movb %al, 0x20(%rsp,%rcx)
incq %rbx
jne 0xb5da
movl %r14d, %eax
incl %r14d
movb $0x24, 0x20(%rsp,%rax)
movb $0x0, 0x20(%rsp,%r14)
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x3190
testl %eax, %eax
jne 0xb7af
leaq 0x472(%r13), %r12
leaq 0x47c(%r13), %rax
movq %rax, 0x18(%rsp)
movw $0x1, %ax
movzwl %ax, %edx
movq %r13, %rdi
movl 0x14(%rsp), %esi
callq 0x9d20
testl %eax, %eax
je 0xb76f
movzwl 0x478(%r13), %ecx
movq %r13, %r14
movzwl 0x47c(%r13), %eax
btl $0xb, %eax
setae %dl
cmpl $0x3ea, %ecx            # imm = 0x3EA
setb %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xb75b
shrl %ecx
movl $0x1f9, %ebp            # imm = 0x1F9
subl %ecx, %ebp
movl %ecx, %r13d
addl $0x7, %r13d
movzwl %cx, %ebx
addl $0xc, %ebx
movl $0x5, %ecx
movq 0x18(%rsp), %r15
testl $0x300, %eax            # imm = 0x300
jne 0xb73d
movl %ecx, %eax
movzwl 0x2(%r12,%rax,2), %edx
movzwl 0x4(%r12,%rax,2), %ecx
movzwl 0x6(%r12,%rax,2), %eax
testb $0x3, 0x2(%rsp)
je 0xb711
movzwl %dx, %esi
movzwl %cx, %edx
movzwl %ax, %ecx
leaq 0x68(%rsp), %rdi
callq 0x98c8
testl %eax, %eax
jne 0xb726
jmp 0xb73d
cmpw 0x4(%rsp), %dx
jne 0xb73d
cmpw 0x6(%rsp), %cx
jne 0xb73d
cmpw 0x8(%rsp), %ax
jne 0xb73d
leaq 0xd8ab(%rip), %rax      # 0x18fd8
movl (%rax), %esi
shrl $0x5, %esi
andl $0x1, %esi
movq %r15, %rdi
callq 0x9ebf
movzwl %bx, %ecx
movzwl (%r12,%rcx,2), %eax
btl $0xb, %eax
jb 0xb75b
leal (%rcx,%r13), %ebx
leaq (%r12,%rcx,2), %r15
cmpl %ecx, %ebp
jge 0xb6d6
movq %r14, %r13
movzwl 0x474(%r14), %eax
testw %ax, %ax
jne 0xb66e
testb $0x3, 0x2(%rsp)
je 0xb780
leaq 0x68(%rsp), %rdi
callq 0x3120
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc857(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x65df(%rip), %rsi      # 0x11d82
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
jmp 0xb780
callq 0x42ea
jmp 0xb780