// File: /workspace/github_c_makefile_star2_O0/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
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 -0x18(%rbp), %rdi
leaq -0x32(%rbp), %rsi
movl $0x2, %edx
callq 0xb930
cmpl $0x0, %eax
jne 0xef7d
movq 0xf095(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0xaf36(%rip), %rsi      # 0x19ea7
movb $0x0, %al
callq 0x31c0
jmp 0xf233
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movzbl -0x9(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x90(%rbp), %rax
movslq %ecx, %rcx
movzwl 0xa(%rax,%rcx,2), %eax
movl %eax, -0x88(%rbp)
movzbl -0x9(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl -0x88(%rbp), %eax
movl %edx, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xf233
movw $0x1, -0x36(%rbp)
movzbl -0x32(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0xf016
leaq -0x32(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xfe30
cmpl $0x0, %eax
jne 0xf014
movq 0xeffa(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0xb45c(%rip), %rsi      # 0x1a464
movb $0x0, %al
callq 0x31c0
jmp 0xf233
jmp 0xf016
jmp 0xf018
movw $0x5, -0x7a(%rbp)
movq -0x8(%rbp), %rdi
movb -0x9(%rbp), %al
movzbl %al, %esi
movzwl -0x36(%rbp), %edx
callq 0xc3e0
cmpl $0x0, %eax
jne 0xf050
movzbl -0x32(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0xf04b
leaq -0x78(%rbp), %rdi
callq 0x3120
jmp 0xf233
movq -0x20(%rbp), %rax
movzwl 0x430(%rax), %edi
callq 0xc6b0
movzwl %ax, %eax
sarl %eax
addl $0x7, %eax
movw %ax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x7a(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movzwl %ax, %ecx
andl $0x800, %ecx            # imm = 0x800
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x91(%rbp)
jne 0xf0b7
movzwl -0x7a(%rbp), %ecx
movl $0x200, %eax            # imm = 0x200
subl %ecx, %eax
movzwl -0x34(%rbp), %ecx
cmpl %ecx, %eax
setge %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0xf0c6
jmp 0xf1fb
movq -0x20(%rbp), %rax
movzwl -0x7a(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movw %ax, -0x7c(%rbp)
movzwl -0x7c(%rbp), %eax
andl $0x300, %eax            # imm = 0x300
cmpl $0x0, %eax
jne 0xf1e6
movq -0x20(%rbp), %rax
movzwl -0x7a(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movw %ax, -0x7e(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x7a(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movw %ax, -0x80(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x7a(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movw %ax, -0x82(%rbp)
movzbl -0x32(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0xf18e
movzwl -0x7e(%rbp), %eax
movzwl -0x30(%rbp), %ecx
cmpl %ecx, %eax
jne 0xf18a
movzwl -0x80(%rbp), %eax
movzwl -0x2e(%rbp), %ecx
cmpl %ecx, %eax
jne 0xf18a
movzwl -0x82(%rbp), %eax
movzwl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
je 0xf18c
jmp 0xf1e8
jmp 0xf1b5
movw -0x7e(%rbp), %cx
movw -0x80(%rbp), %ax
leaq -0x78(%rbp), %rdi
movzwl %cx, %esi
movzwl %ax, %edx
movzwl -0x82(%rbp), %ecx
callq 0xbc50
cmpl $0x0, %eax
jne 0xf1b3
jmp 0xf1e8
jmp 0xf1b5
movq -0x20(%rbp), %rdi
addq $0x42a, %rdi            # imm = 0x42A
movzwl -0x7a(%rbp), %eax
shlq %rax
addq %rax, %rdi
leaq 0x10027(%rip), %rax     # 0x1f1f8
movl (%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %esi
callq 0xc750
jmp 0xf1e8
movzwl -0x34(%rbp), %ecx
movzwl -0x7a(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x7a(%rbp)
jmp 0xf06c
movq -0x20(%rbp), %rax
movzwl 0x42c(%rax), %edi
callq 0xc6b0
movw %ax, -0x36(%rbp)
movzwl -0x36(%rbp), %eax
cmpl $0x0, %eax
jne 0xf018
movzbl -0x32(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0xf231
leaq -0x78(%rbp), %rdi
callq 0x3120
jmp 0xf233
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)