// File: /workspace/github_c_makefile_star2_O1/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 $0x448, %rsp            # imm = 0x448
movq %rdx, %r14
movq %rdi, %rbx
movzbl 0x955(%rdi), %edx
movzbl 0x954(%rdi), %ecx
leaq 0xa(%rsp), %rsi
movq %r14, %rdi
movl $0x2, %r8d
callq 0x7ec2
testl %eax, %eax
je 0x945d
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x78a2
testl %eax, %eax
je 0x944b
movq %rbx, %rdi
movzwl 0x554(%rbx), %eax
movb 0xa(%rsp), %sil
movzbl 0x13(%rsp), %ebx
movb 0x12(%rsp), %bpl
movzwl 0xc(%rsp), %ecx
movw %cx, 0x8(%rsp)
movzwl 0xe(%rsp), %ecx
movw %cx, 0x4(%rsp)
movzwl 0x10(%rsp), %ecx
movw %cx, 0x6(%rsp)
leaq 0x8(%rdi), %rcx
movq %rcx, 0x38(%rsp)
movl %esi, %r14d
andb $0x8, %r14b
shrb $0x3, %r14b
movl %esi, %r15d
andb $0x4, %r15b
shrb $0x2, %r15b
xorl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movb %sil, 0x3(%rsp)
movl %ebx, 0x14(%rsp)
movb %bpl, 0x2(%rsp)
movb %r14b, 0x1(%rsp)
movb %r15b, (%rsp)
movzwl %ax, %esi
movq 0x18(%rsp), %rdi
xorl %edx, %edx
callq 0x78a2
movq 0x18(%rsp), %rdi
testl %eax, %eax
je 0x944b
movq 0x28(%rdi), %rax
shrq %rax
addq $-0x5, %rax
cmpq $-0x3, %rax
ja 0x942f
movl $0x1, %r8d
movl $0x1, %eax
movzwl 0x554(%rdi,%rax,2), %eax
movl $0x6, %r9d
testl %eax, %eax
je 0x9409
movl %eax, %ecx
shrl $0x8, %ecx
movl %ecx, 0x2c(%rsp)
cmpl %ebx, %ecx
sete %dl
orb %r15b, %dl
cmpb %al, %bpl
sete %cl
cmpb $0x1, %dl
jne 0x9409
orb %r14b, %cl
je 0x9409
movl %r8d, %edx
movzwl 0x556(%rdi,%rdx,2), %ecx
testw %cx, %cx
je 0x93e1
movq %r8, 0x30(%rsp)
movzwl 0x558(%rdi,%rdx,2), %ebp
leaq -0x1(%rbp), %r13
movzbl %al, %eax
movl %eax, 0x28(%rsp)
leal 0x1(%rbp), %eax
movl %eax, 0x20(%rsp)
xorl %r14d, %r14d
movzwl %cx, %esi
movq %rdi, %rbx
leaq 0x40(%rsp), %rdx
callq 0x78a2
movb $0x1, %r12b
testl %eax, %eax
je 0x93e9
movl %eax, 0x24(%rsp)
movq 0x28(%rbx), %rax
shrq %rax
subq %r13, %rax
cmpq $0x2, %rax
movq %rbx, %rdi
movb 0x3(%rsp), %dl
jb 0x9398
movl $0x1, %r12d
movl $0x3, %r15d
movl 0x20(%rsp), %ebx
movzwl 0x40(%rsp,%r12,2), %eax
testw %ax, %ax
jne 0x9302
leal -0x1(%r15), %ecx
cmpw $0x0, 0x40(%rsp,%rcx,2)
jne 0x9302
movl %r15d, %ecx
cmpw $0x0, 0x40(%rsp,%rcx,2)
je 0x937d
testb $0x1, %dl
jne 0x931e
cmpw 0x8(%rsp), %ax
jne 0x937d
leal -0x1(%r15), %eax
movzwl 0x4(%rsp), %ecx
cmpw %cx, 0x40(%rsp,%rax,2)
jne 0x937d
testb $0x2, %dl
jne 0x9332
movl %r15d, %eax
movzwl 0x6(%rsp), %ecx
cmpw %cx, 0x40(%rsp,%rax,2)
jne 0x937d
testl %r14d, %r14d
jne 0x9352
leaq 0x8a69(%rip), %rdi      # 0x11da7
movq 0x38(%rsp), %rsi
movl 0x2c(%rsp), %edx
movl 0x28(%rsp), %ecx
xorl %eax, %eax
callq 0x3160
leaq (%rsp,%r12,2), %rdi
addq $0x40, %rdi
leaq 0xfc67(%rip), %rax      # 0x18fc8
movl (%rax), %esi
shrl $0x5, %esi
andl $0x1, %esi
callq 0x6f3c
movl $0x1, %r14d
movq 0x18(%rsp), %rdi
movb 0x3(%rsp), %dl
movl %ebx, %r12d
movq 0x28(%rdi), %rax
shrq %rax
subq %r13, %rax
addl %ebp, %ebx
addl %ebp, %r15d
cmpq %r12, %rax
ja 0x92e0
movzwl 0x40(%rsp), %ecx
testw %cx, %cx
jne 0x9296
testl %r14d, %r14d
je 0x93ba
movl $0xa, %edi
callq 0x3060
movq 0x18(%rsp), %rdi
cmpl $0x0, 0x24(%rsp)
movl 0x14(%rsp), %ebx
movb 0x2(%rsp), %bpl
movb 0x1(%rsp), %r14b
movb (%rsp), %r15b
movb $0x1, %r12b
movq 0x30(%rsp), %r8
movl $0x1, %r9d
je 0x9409
xorl %r9d, %r9d
movb $0x1, %r12b
jmp 0x9409
movq %rbx, %rdi
movl 0x14(%rsp), %ebx
movb 0x2(%rsp), %bpl
movb 0x1(%rsp), %r14b
movb (%rsp), %r15b
movq 0x30(%rsp), %r8
movl $0x1, %r9d
cmpl $0x6, %r9d
je 0x9414
testl %r9d, %r9d
jne 0x944b
addl $0x4, %r8d
movq 0x28(%rdi), %rcx
shrq %rcx
addq $-0x3, %rcx
movq %r8, %rax
cmpq %r8, %rcx
ja 0x9221
movzwl 0x554(%rdi), %eax
testw %ax, %ax
jne 0x91e5
testb %r12b, %r12b
jne 0x944b
testb $0xc, 0xa(%rsp)
je 0x9489
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xeb8c(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x8914(%rip), %rsi      # 0x11d82
movq %r14, %rdx
xorl %eax, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31d0
leaq 0xa(%rsp), %rdi
callq 0x3b5a
jmp 0x944b