// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/fsio/dos11.c
// Function: dos11Dir
static void dos11Dir(
  struct mountedFS *mount,
  uint8_t UNUSED(unit),
  char *fname
)
{
  struct DOS11data *data = &mount->dos11data;
  uint8_t user = data->user;
  uint8_t group = data->group;
  struct dos11FileSpec spec;
  unsigned int mfdblk, ufdblk, i, j;
  uint16_t buf[512];
  uint8_t found = 0;

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

  if (dos11ReadBlock(mount, MFD1_BLOCK, NULL) == 0)
    return;

  /*
   * Search the MFD for matching UIC entries.
   */
  mfdblk = le16toh(data->buf[MFD1_MFD2BLOCK]);
  do {
    if (dos11ReadBlock(mount, mfdblk, NULL) == 0)
      return;

    for (i = MFD2_HEADER; i < EODIR(mount, MFD2_SIZE); i += MFD2_SIZE) {
      uint16_t uic = le16toh(data->buf[i + MFD2_UFDUIC]);
      uint16_t entrysz = le16toh(data->buf[i + MFD2_UFDSIZE]);

      if (uic == 0)
        continue;

      if ((spec.flags & DOS11_WC_GROUP) == 0)
        if (spec.group != ((uic >> 8) & 0377))
          continue;

      if ((spec.flags & DOS11_WC_USER) == 0)
        if (spec.user != (uic & 0377))
          continue;

      found = 1;

      if ((ufdblk = le16toh(data->buf[i + MFD2_UFDSTART])) != 0) {
        unsigned int header = 0;

        do {
          if (dos11ReadBlock(mount, ufdblk, buf) == 0)
            return;

          for (j = UFD_HEADER; j < EODIR(mount, entrysz); j += entrysz) {
            if ((le16toh(buf[j + UFD_FILENAME]) == 0) &&
                (le16toh(buf[j + UFD_FILENAME + 1]) == 0) &&
                (le16toh(buf[j + UFD_EXTENSION]) == 0))
              continue;

            if ((spec.flags & DOS11_WC_NAME) == 0)
              if ((le16toh(buf[j + UFD_FILENAME]) != spec.name[0]) ||
                  (le16toh(buf[j + UFD_FILENAME + 1]) != spec.name[1]))
                continue;

            if ((spec.flags & DOS11_WC_EXT) == 0)
              if (le16toh(buf[j + UFD_EXTENSION]) != spec.ext)
                  continue;

            if (!header) {
              printf("%s:[%u, %u]\n\n",
                     mount->name, (uic >> 8) & 0377, uic & 0377);
              header = 1;
            }

            dos11DisplayDir(&buf[j], SWISSET('f'));
          }
          ufdblk = le16toh(buf[UFD_LINK]);
        } while (ufdblk != 0);

        if (header)
          printf("\n");
      }
    }
    mfdblk = le16toh(data->buf[MFD2_LINK]);
  } while (mfdblk != 0);

  if (!found && ((spec.flags & (DOS11_WC_GROUP | DOS11_WC_USER)) == 0))
    ERROR("dir: Directory [%o,%o] not found\n", spec.group, spec.user);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rdx, %rbx
movq %rdi, %r14
movzbl 0x955(%rdi), %edx
movzbl 0x954(%rdi), %ecx
leaq 0x26(%rsp), %rsi
pushq $0x2
popq %r8
movq %rbx, %rdi
callq 0x66c1
testl %eax, %eax
je 0x7c1d
pushq $0x1
popq %rsi
movq %r14, 0x18(%rsp)
movq %r14, %rdi
xorl %edx, %edx
callq 0x5ffa
testl %eax, %eax
je 0x7c0b
movq 0x18(%rsp), %rdi
movzwl 0x554(%rdi), %eax
movb 0x26(%rsp), %bl
movzbl 0x2f(%rsp), %ecx
movl %ecx, 0xc(%rsp)
movzbl 0x2e(%rsp), %ecx
movl %ecx, 0x8(%rsp)
movzwl 0x28(%rsp), %ecx
movw %cx, 0x16(%rsp)
movzwl 0x2a(%rsp), %ecx
movw %cx, 0x12(%rsp)
movzwl 0x2c(%rsp), %ecx
movw %cx, 0x14(%rsp)
leaq 0x8(%rdi), %rcx
movq %rcx, 0x48(%rsp)
movl %ebx, %ebp
andb $0x8, %bpl
shrb $0x3, %bpl
movl %ebx, %esi
andb $0x4, %sil
shrb $0x2, %sil
movq $0x0, 0x40(%rsp)
movb %bpl, 0x7(%rsp)
movb %sil, 0x6(%rsp)
movzwl %ax, %esi
xorl %edx, %edx
callq 0x5ffa
testl %eax, %eax
je 0x7c0b
pushq $0x1
popq %rax
movl %eax, %r8d
movq 0x18(%rsp), %rdi
movb 0x7(%rsp), %bpl
movb 0x6(%rsp), %sil
movl %r8d, %r8d
movq 0x28(%rdi), %rax
shrq %rax
addq $-0x3, %rax
cmpq %r8, %rax
jbe 0x7bef
movzwl 0x554(%rdi,%r8,2), %eax
testl %eax, %eax
je 0x7be6
movl %eax, %ecx
shrl $0x8, %ecx
movl %ecx, 0x34(%rsp)
cmpl 0xc(%rsp), %ecx
sete %dl
orb %sil, %dl
cmpb %al, 0x8(%rsp)
sete %cl
cmpb $0x1, %dl
jne 0x7be6
orb %bpl, %cl
je 0x7be6
movzwl 0x556(%rdi,%r8,2), %ecx
movb $0x1, %dl
movq %rdx, 0x40(%rsp)
testw %cx, %cx
je 0x7be6
movq %r8, 0x38(%rsp)
movzwl 0x558(%rdi,%r8,2), %ebp
leaq -0x1(%rbp), %r15
movzbl %al, %eax
movl %eax, 0x30(%rsp)
xorl %r13d, %r13d
movzwl %cx, %esi
leaq 0x50(%rsp), %rdx
callq 0x5ffa
testl %eax, %eax
je 0x7c0b
pushq $0x3
popq %rax
movl %eax, %r12d
movq 0x18(%rsp), %rdi
leal -0x2(%r12), %r14d
movq 0x28(%rdi), %rax
shrq %rax
subq %r15, %rax
cmpq %r14, %rax
jbe 0x7bb7
movzwl 0x50(%rsp,%r14,2), %ecx
movl %r12d, %eax
testw %cx, %cx
jne 0x7b3c
leal -0x1(%r12), %edx
cmpw $0x0, 0x50(%rsp,%rdx,2)
jne 0x7b3c
cmpw $0x0, 0x50(%rsp,%rax,2)
je 0x7baf
testb $0x1, %bl
jne 0x7b59
cmpw 0x16(%rsp), %cx
jne 0x7baf
leal -0x1(%r12), %ecx
movzwl 0x12(%rsp), %edx
cmpw %dx, 0x50(%rsp,%rcx,2)
jne 0x7baf
testb $0x2, %bl
jne 0x7b6a
movzwl 0x14(%rsp), %ecx
cmpw %cx, 0x50(%rsp,%rax,2)
jne 0x7baf
testl %r13d, %r13d
jne 0x7b8a
leaq 0x9231(%rip), %rdi      # 0x10da7
movq 0x48(%rsp), %rsi
movl 0x34(%rsp), %edx
movl 0x30(%rsp), %ecx
xorl %eax, %eax
callq 0x3160
leaq (%rsp,%r14,2), %rdi
addq $0x50, %rdi
leaq 0x1043f(%rip), %rax     # 0x17fd8
movl (%rax), %esi
shrl $0x5, %esi
andl $0x1, %esi
callq 0x58ec
pushq $0x1
popq %r13
movq 0x18(%rsp), %rdi
addl %ebp, %r12d
jmp 0x7b01
movzwl 0x50(%rsp), %ecx
testw %cx, %cx
jne 0x7ae1
testl %r13d, %r13d
movb 0x7(%rsp), %bpl
je 0x7bdc
pushq $0xa
popq %rdi
callq 0x3060
movq 0x18(%rsp), %rdi
movb 0x6(%rsp), %sil
movq 0x38(%rsp), %r8
addl $0x4, %r8d
jmp 0x7a58
movzwl 0x554(%rdi), %eax
testw %ax, %ax
jne 0x7a31
andb $0xc, %bl
movq 0x40(%rsp), %rax
orb %bl, %al
je 0x7c49
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf3d4(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x9154(%rip), %rsi      # 0x10d82
movq %rbx, %rdx
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31e0
movq 0xf3a8(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x915b(%rip), %rsi      # 0x10db5
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0x31e0
leaq 0x10358(%rip), %rax     # 0x17fc8
movq (%rax), %rdi
testq %rdi, %rdi
je 0x7c0b
movq 0xf341(%rip), %rax      # 0x16fc0
cmpq (%rax), %rdi
je 0x7c0b
leaq 0x912a(%rip), %rsi      # 0x10db5
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0x31e0
jmp 0x7c0b