// File: /workspace/github_c_makefile_star2_O2/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, %r15
movl %esi, %r12d
movq %rdi, %rbx
leaq 0x2(%rsp), %rsi
pushq $0x2
popq %r14
movq %rdx, %rdi
movl %r14d, %edx
callq 0x82f4
testl %eax, %eax
je 0xa51c
movzbl %r12b, %ecx
shrb $0x3, %r12b
movzbl %r12b, %eax
andl $0x1e, %eax
movzwl 0x52(%rbx,%rax), %eax
movl %ecx, 0x14(%rsp)
andl $0xf, %ecx
btl %ecx, %eax
jae 0xa50a
testb $0x3, 0x2(%rsp)
movq %rbx, 0x18(%rsp)
je 0xa424
movb $0x5e, 0x20(%rsp)
pushq $0x1
popq %rbx
xorl %r12d, %r12d
movl %ebx, %r15d
movl %r15d, %eax
cmpq $0x6, %r12
je 0xa389
movzbl 0xa(%rsp,%r12), %ecx
cmpl $0x25, %ecx
je 0xa374
cmpl $0x2a, %ecx
je 0xa364
cmpl $0x20, %ecx
je 0xa389
movsbq %cl, %r13
callq 0x3030
movq (%rax), %rax
movb (%rax,%r13,4), %al
jmp 0xa376
leal 0x1(%r15), %ecx
movb $0x2e, 0x20(%rsp,%rax)
movb $0x2a, %al
movl %r14d, %edx
jmp 0xa37b
movb $0x2e, %al
movl %ebx, %edx
movl %r15d, %ecx
addl %edx, %r15d
movl %ecx, %ecx
movb %al, 0x20(%rsp,%rcx)
incq %r12
jmp 0xa334
leal 0x1(%r15), %ecx
movb $0x5c, 0x20(%rsp,%rax)
addl $0x2, %r15d
movb $0x2e, 0x20(%rsp,%rcx)
xorl %ebx, %ebx
pushq $0x1
popq %rbp
pushq $0x2
popq %r14
movl %r15d, %eax
cmpq $0x3, %rbx
je 0xa3f8
movzbl 0x10(%rsp,%rbx), %ecx
cmpl $0x25, %ecx
je 0xa3e3
cmpl $0x2a, %ecx
je 0xa3d3
cmpl $0x20, %ecx
je 0xa3f8
movsbq %cl, %r12
callq 0x3030
movq (%rax), %rax
movb (%rax,%r12,4), %al
jmp 0xa3e5
leal 0x1(%r15), %ecx
movb $0x2e, 0x20(%rsp,%rax)
movb $0x2a, %al
movl %r14d, %edx
jmp 0xa3ea
movb $0x2e, %al
movl %ebp, %edx
movl %r15d, %ecx
addl %edx, %r15d
movl %ecx, %ecx
movb %al, 0x20(%rsp,%rcx)
incq %rbx
jmp 0xa3a4
incl %r15d
movb $0x24, 0x20(%rsp,%rax)
movb $0x0, 0x20(%rsp,%r15)
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x3190
testl %eax, %eax
movq 0x18(%rsp), %rbx
jne 0xa539
leaq 0x472(%rbx), %r15
movw $0x1, %ax
leaq 0xdba2(%rip), %r12      # 0x17fd8
leaq 0x68(%rsp), %r14
movzwl %ax, %edx
movq %rbx, %rdi
movl 0x14(%rsp), %esi
callq 0x89c6
testl %eax, %eax
je 0xa4f9
movzwl 0x478(%rbx), %r13d
shrl %r13d
movl $0x1f9, %ebp            # imm = 0x1F9
subl %r13d, %ebp
addl $0x7, %r13d
movw $0x5, %bx
movzwl %bx, %ebx
movzwl (%r15,%rbx,2), %eax
btl $0xb, %eax
jb 0xa4e4
cmpl %ebx, %ebp
jl 0xa4e4
testw $0x300, %ax             # imm = 0x300
jne 0xa4df
movl %ebx, %eax
movzwl 0x2(%r15,%rax,2), %edx
movzwl 0x4(%r15,%rax,2), %ecx
movzwl 0x6(%r15,%rax,2), %eax
testb $0x3, 0x2(%rsp)
je 0xa4b7
movzwl %dx, %esi
movzwl %cx, %edx
movzwl %ax, %ecx
movq %r14, %rdi
callq 0x84be
testl %eax, %eax
jne 0xa4cc
jmp 0xa4df
cmpw 0x4(%rsp), %dx
jne 0xa4df
cmpw 0x6(%rsp), %cx
jne 0xa4df
cmpw 0x8(%rsp), %ax
jne 0xa4df
leaq (%r15,%rbx,2), %rdi
movl (%r12), %esi
shrl $0x5, %esi
andl $0x1, %esi
callq 0x8b4b
addl %r13d, %ebx
jmp 0xa46d
movq 0x18(%rsp), %rbx
movzwl 0x474(%rbx), %eax
testw %ax, %ax
jne 0xa43b
testb $0x3, 0x2(%rsp)
je 0xa50a
leaq 0x68(%rsp), %rdi
callq 0x3120
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xcad5(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x6855(%rip), %rsi      # 0x10d82
movq %r15, %rdx
xorl %eax, %eax
callq 0x31e0
jmp 0xa50a
movq 0xcab8(%rip), %rax      # 0x16ff8
movq (%rax), %rcx
leaq 0x6e8a(%rip), %rdi      # 0x113d4
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
jmp 0xa50a