// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/os8.c
// Function: os8Dir
static void os8Dir(
  struct mountedFS *mount,
  uint8_t unit,
  char *fname
)
{
  struct OS8data *data = &mount->os8data;
  struct os8FileSpec spec;

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

  if (os8UnitValid(data, unit)) {
    unsigned int dirblk = OS8_DSSTART;

    do {
      uint16_t i, entrysz, entries, extra, off = OS8_DH_SIZE;

      if (os8ReadBlock(mount, unit, dirblk, NULL) == 0)
        return;

      entrysz = OS8_DI_SIZE + (-os8SXT(le16toh(data->buf[OS8_DH_EXTRA])));
      entries = os8Neg(le16toh(data->buf[OS8_DH_ENTRIES]));
      extra = os8Neg(le16toh(data->buf[OS8_DH_EXTRA]));

      for (i = 0; i < entries; i++) {
        char temp1[16], temp2[16];

        if (os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) != 0) {
          if ((spec.flags & OS8_WC_NAME) == 0)
            if ((os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) != spec.name[0]) ||
                (os8Word(le16toh(data->buf[off + OS8_DI_FNAME2])) != spec.name[1]) ||
                (os8Word(le16toh(data->buf[off + OS8_DI_FNAME3])) != spec.name[2])) {
              off += entrysz;
              continue;
            }

          if ((spec.flags & OS8_WC_EXT) == 0)
            if (os8Word(le16toh(data->buf[off + OS8_DI_EXT])) != spec.ext) {
              off += entrysz;
              continue;
            }

          if (SWISSET('f')) {
            uint16_t length, dateval = 0;
            
            length = os8Neg(le16toh(data->buf[off + extra + OS8_DI_LENGTH]));
            if (extra)
              dateval = os8Word(le16toh(data->buf[off + OS8_DI_DATE]));

            printf("%s  %4hu  %s\n",
                   os8FileName(mount, off, temp1), length,
                   os8Date(dateval, temp2));
          } else printf("%s\n", os8FileName(mount, off, temp1));
          off += entrysz;
        } else off += OS8_ED_SIZE;
      }

      dirblk = os8Word(le16toh(data->buf[OS8_DH_NEXT]));
    } while (dirblk != 0);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %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 0x135b0
cmpl $0x0, %eax
jne 0x1643d
movq 0x7bd5(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x3a76(%rip), %rsi      # 0x19ea7
movb $0x0, %al
callq 0x31c0
jmp 0x1673a
movq -0x20(%rbp), %rdi
movzbl -0x9(%rbp), %esi
callq 0x14f20
cmpl $0x0, %eax
je 0x1673a
movl $0x1, -0x38(%rbp)
movw $0x5, -0x42(%rbp)
movq -0x8(%rbp), %rdi
movb -0x9(%rbp), %al
movl -0x38(%rbp), %edx
xorl %ecx, %ecx
movzbl %al, %esi
callq 0x132f0
cmpl $0x0, %eax
jne 0x1647e
jmp 0x1673a
movq -0x20(%rbp), %rax
movzwl 0x1c(%rax), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x148b0
movzwl %ax, %ecx
xorl %eax, %eax
subl %ecx, %eax
addl $0x5, %eax
movw %ax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x14(%rax), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14860
movw %ax, -0x3e(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x1c(%rax), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14860
movw %ax, -0x40(%rbp)
movw $0x0, -0x3a(%rbp)
movzwl -0x3a(%rbp), %eax
movzwl -0x3e(%rbp), %ecx
cmpl %ecx, %eax
jge 0x16713
movq -0x20(%rbp), %rax
movzwl -0x42(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x166f5
movzbl -0x32(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x165bb
movq -0x20(%rbp), %rax
movzwl -0x42(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movzwl %ax, %eax
movzwl -0x30(%rbp), %ecx
cmpl %ecx, %eax
jne 0x165a6
movq -0x20(%rbp), %rax
movzwl -0x42(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movzwl %ax, %eax
movzwl -0x2e(%rbp), %ecx
cmpl %ecx, %eax
jne 0x165a6
movq -0x20(%rbp), %rax
movzwl -0x42(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movzwl %ax, %eax
movzwl -0x2c(%rbp), %ecx
cmpl %ecx, %eax
je 0x165b9
movzwl -0x3c(%rbp), %ecx
movzwl -0x42(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x42(%rbp)
jmp 0x16702
jmp 0x165bb
movzbl -0x32(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x16607
movq -0x20(%rbp), %rax
movzwl -0x42(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movzwl %ax, %eax
movzwl -0x2a(%rbp), %ecx
cmpl %ecx, %eax
je 0x16605
movzwl -0x3c(%rbp), %ecx
movzwl -0x42(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x42(%rbp)
jmp 0x16702
jmp 0x16607
leaq 0x8bea(%rip), %rax      # 0x1f1f8
movl (%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x166c0
movw $0x0, -0x74(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movzwl -0x40(%rbp), %edx
addl %edx, %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14860
movw %ax, -0x72(%rbp)
cmpw $0x0, -0x40(%rbp)
je 0x16677
movq -0x20(%rbp), %rax
movzwl -0x42(%rbp), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movw %ax, -0x74(%rbp)
movq -0x8(%rbp), %rdi
movw -0x42(%rbp), %ax
leaq -0x60(%rbp), %rdx
movzwl %ax, %esi
callq 0x17120
movq %rax, -0x80(%rbp)
movzwl -0x72(%rbp), %eax
movl %eax, -0x78(%rbp)
movw -0x74(%rbp), %ax
leaq -0x70(%rbp), %rsi
movzwl %ax, %edi
callq 0x172d0
movq -0x80(%rbp), %rsi
movl -0x78(%rbp), %edx
movq %rax, %rcx
leaq 0x449e(%rip), %rdi      # 0x1ab55
movb $0x0, %al
callq 0x3160
jmp 0x166e5
movq -0x8(%rbp), %rdi
movw -0x42(%rbp), %ax
leaq -0x60(%rbp), %rdx
movzwl %ax, %esi
callq 0x17120
movq %rax, %rsi
leaq 0x4481(%rip), %rdi      # 0x1ab5f
movb $0x0, %al
callq 0x3160
movzwl -0x3c(%rbp), %ecx
movzwl -0x42(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x42(%rbp)
jmp 0x16700
movzwl -0x42(%rbp), %eax
addl $0x2, %eax
movw %ax, -0x42(%rbp)
jmp 0x16702
movw -0x3a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x3a(%rbp)
jmp 0x164d9
movq -0x20(%rbp), %rax
movzwl 0x18(%rax), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movzwl %ax, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x1645a
jmp 0x1673a
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)