// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
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 -0x20(%rbp), %rax
movb 0x90d(%rax), %al
movb %al, -0x21(%rbp)
movq -0x20(%rbp), %rax
movb 0x90c(%rax), %al
movb %al, -0x22(%rbp)
movb $0x0, -0x441(%rbp)
movq -0x18(%rbp), %rdi
movb -0x21(%rbp), %al
leaq -0x2c(%rbp), %rsi
movl $0x2, %r8d
movzbl %al, %edx
movzbl -0x22(%rbp), %ecx
callq 0x8300
cmpl $0x0, %eax
jne 0xa4e9
movq 0x13b29(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0xf9ca(%rip), %rsi      # 0x19ea7
movb $0x0, %al
callq 0x31c0
jmp 0xa8c7
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x7380
cmpl $0x0, %eax
jne 0xa505
jmp 0xa8c7
movq -0x20(%rbp), %rax
movzwl 0x50c(%rax), %edi
callq 0x6c50
movzwl %ax, %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x7380
cmpl $0x0, %eax
jne 0xa535
jmp 0xa8c7
movl $0x1, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
shrq %rcx
subq $0x3, %rcx
cmpq %rcx, %rax
jae 0xa82d
movq -0x20(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movzwl 0x50c(%rax,%rcx,2), %edi
callq 0x6c50
movw %ax, -0x444(%rbp)
movq -0x20(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzwl 0x50c(%rax,%rcx,2), %edi
callq 0x6c50
movw %ax, -0x446(%rbp)
movzwl -0x444(%rbp), %eax
cmpl $0x0, %eax
jne 0xa5a8
jmp 0xa81f
movzbl -0x2c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0xa5d3
movzbl -0x23(%rbp), %eax
movzwl -0x444(%rbp), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
je 0xa5d1
jmp 0xa81f
jmp 0xa5d3
movzbl -0x2c(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0xa5fb
movzbl -0x24(%rbp), %eax
movzwl -0x444(%rbp), %ecx
andl $0xff, %ecx
cmpl %ecx, %eax
je 0xa5f9
jmp 0xa81f
jmp 0xa5fb
movb $0x1, -0x441(%rbp)
movq -0x20(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzwl 0x50c(%rax,%rcx,2), %edi
callq 0x6c50
movzwl %ax, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0xa81d
movl $0x0, -0x44c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x440(%rbp), %rdx
callq 0x7380
cmpl $0x0, %eax
jne 0xa651
jmp 0xa8c7
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
shrq %rcx
movzwl -0x446(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jae 0xa7e8
movl -0x3c(%rbp), %eax
addl $0x0, %eax
movl %eax, %eax
movzwl -0x440(%rbp,%rax,2), %edi
callq 0x6c50
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0xa6de
movl -0x3c(%rbp), %eax
addl $0x0, %eax
addl $0x1, %eax
movl %eax, %eax
movzwl -0x440(%rbp,%rax,2), %edi
callq 0x6c50
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0xa6de
movl -0x3c(%rbp), %eax
addl $0x2, %eax
movl %eax, %eax
movzwl -0x440(%rbp,%rax,2), %edi
callq 0x6c50
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0xa6de
jmp 0xa7d6
movzbl -0x2c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xa734
movl -0x3c(%rbp), %eax
addl $0x0, %eax
movl %eax, %eax
movzwl -0x440(%rbp,%rax,2), %edi
callq 0x6c50
movzwl %ax, %eax
movzwl -0x2a(%rbp), %ecx
cmpl %ecx, %eax
jne 0xa72d
movl -0x3c(%rbp), %eax
addl $0x0, %eax
addl $0x1, %eax
movl %eax, %eax
movzwl -0x440(%rbp,%rax,2), %edi
callq 0x6c50
movzwl %ax, %eax
movzwl -0x28(%rbp), %ecx
cmpl %ecx, %eax
je 0xa732
jmp 0xa7d6
jmp 0xa734
movzbl -0x2c(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xa764
movl -0x3c(%rbp), %eax
addl $0x2, %eax
movl %eax, %eax
movzwl -0x440(%rbp,%rax,2), %edi
callq 0x6c50
movzwl %ax, %eax
movzwl -0x26(%rbp), %ecx
cmpl %ecx, %eax
je 0xa762
jmp 0xa7d6
jmp 0xa764
cmpl $0x0, -0x44c(%rbp)
jne 0xa7aa
movq -0x8(%rbp), %rsi
addq $0x8, %rsi
movzwl -0x444(%rbp), %edx
sarl $0x8, %edx
andl $0xff, %edx
movzwl -0x444(%rbp), %ecx
andl $0xff, %ecx
leaq 0xf733(%rip), %rdi      # 0x19ecc
movb $0x0, %al
callq 0x3160
movl $0x1, -0x44c(%rbp)
movl -0x3c(%rbp), %eax
leaq -0x440(%rbp), %rdi
shlq %rax
addq %rax, %rdi
leaq 0x14a37(%rip), %rax     # 0x1f1f8
movl (%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %esi
callq 0x6af0
movzwl -0x446(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0xa658
movzwl -0x440(%rbp), %edi
callq 0x6c50
movzwl %ax, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0xa634
cmpl $0x0, -0x44c(%rbp)
je 0xa81b
leaq 0x1018b(%rip), %rdi     # 0x1a99f
movb $0x0, %al
callq 0x3160
jmp 0xa81d
jmp 0xa81f
movl -0x38(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x38(%rbp)
jmp 0xa53c
movq -0x20(%rbp), %rax
movzwl 0x50c(%rax), %edi
callq 0x6c50
movzwl %ax, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0xa51b
cmpb $0x0, -0x441(%rbp)
jne 0xa8c7
movzbl -0x2c(%rbp), %eax
andl $0xc, %eax
cmpl $0x0, %eax
jne 0xa8c7
movq 0x1378f(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movzbl -0x23(%rbp), %edx
movzbl -0x24(%rbp), %ecx
leaq 0xf65f(%rip), %rsi      # 0x19eda
movb $0x0, %al
callq 0x31c0
leaq 0x1495f(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xa8c5
leaq 0x14952(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x13720(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xa8c5
leaq 0x1493c(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movzbl -0x23(%rbp), %edx
movzbl -0x24(%rbp), %ecx
leaq 0xf61c(%rip), %rsi      # 0x19eda
movb $0x0, %al
callq 0x31c0
jmp 0xa8c7
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq