// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/fsio/os8.c
// Function: os8ParseFilespec
int os8ParseFilespec(
  char *ptr,
  struct os8FileSpec *spec,
  int wildcard
)
{
  int state = P_NAME;
  unsigned int i;

  memset(spec, 0, sizeof(struct os8FileSpec));
  memset(&spec->fname, ' ', sizeof(spec->fname));
  memset(&spec->fext, ' ', sizeof(spec->fext));

  if (wildcard == OS8_M_NONAME)
    if (*ptr == '\0') {
      spec->flags = OS8_WC_NAME | OS8_WC_EXT;
      return 1;
    }

  while (state != P_DONE) {
    i = 0;

    switch (state) {
      case P_NAME:
        while ((*ptr != '\0') &&
               (*ptr != '.') &&
               (i < sizeof(spec->fname))) {
          char ch = toupper(*ptr++);

          if (isalnum(ch)) {
            toSixbit(ch, &spec->name[i >> 1], i & 1);
            spec->fname[i++] = ch;
          } else {
            if (ch == '*')
              if (i == 0) {
                spec->flags |= OS8_WC_NAME;
                break;
              }
            return 0;
          }
        }

        switch (*ptr) {
          case '\0':
            state = P_DONE;
            break;

          case '.':
            state = P_EXT;
            ptr++;
            break;

          default:
            return 0;
        }
        break;

      case P_EXT:
        while ((*ptr != '\0') &&
               (i < sizeof(spec->fext))) {
          char ch = toupper(*ptr++);

          if (isalnum(ch)) {
            toSixbit(ch, &spec->ext, i);
            spec->fext[i++] = ch;
          } else {
            if (ch == '*')
              if (i == 0) {
                spec->flags |= OS8_WC_EXT;
                break;
              }
            return 0;
          }
        }

        if (*ptr != '\0')
          return 0;

        state = P_DONE;
        break;
    }
  }
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rsi)
movw $0x0, 0x10(%rsi)
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0xa(%rsi)
cmpl $0x2, %edx
jne 0xdad8
cmpb $0x0, (%r14)
je 0xdc93
leaq 0x4d51(%rip), %r15      # 0x12830
movl $0x1, %eax
cmpl $0x1, %eax
je 0xdbb5
cmpl $0x2, %eax
jne 0xdc96
xorl %ebp, %ebp
movsbq (%r14), %r12
testq %r12, %r12
je 0xdba4
cmpl $0x1, %ebp
ja 0xdba4
callq 0x3030
movq (%rax), %rax
movl (%rax,%r12,4), %r12d
callq 0x32f0
movq (%rax), %rax
movsbq %r12b, %rcx
testb $0x8, (%rax,%rcx,2)
jne 0xdb4d
shll $0x18, %r12d
xorl $0x2a000000, %r12d      # imm = 0x2A000000
movl $0x1, %eax
orl %ebp, %r12d
jne 0xdb90
orb $0x2, (%rbx)
xorl %ebp, %ebp
movl $0x9, %eax
jmp 0xdb90
movl %ebp, %eax
xorl %edx, %edx
xorl %ecx, %ecx
cmpb %r12b, (%rcx,%r15)
je 0xdb67
incq %rcx
addl $-0x40, %edx
cmpq $0x40, %rcx
jne 0xdb53
jmp 0xdb87
movzwl 0x8(%rbx), %esi
testl %ebp, %ebp
je 0xdb7e
shrl $0x6, %esi
andl $0x3f, %esi
shll $0x6, %esi
addl %esi, %ecx
movl %ecx, %esi
jmp 0xdb83
andl $0x3f, %esi
subl %edx, %esi
movw %si, 0x8(%rbx)
incl %ebp
movb %r12b, 0x10(%rbx,%rax)
xorl %eax, %eax
incq %r14
testl %eax, %eax
je 0xdaf8
cmpl $0x9, %eax
jne 0xdc8f
xorl %eax, %eax
cmpb $0x0, (%r14)
je 0xdae4
jmp 0xdc9b
xorl %ebp, %ebp
movsbq (%r14), %r12
testq %r12, %r12
je 0xdc71
cmpb $0x2e, %r12b
je 0xdc71
cmpl $0x5, %ebp
ja 0xdc71
callq 0x3030
movq (%rax), %rax
movl (%rax,%r12,4), %r12d
callq 0x32f0
movq (%rax), %rax
movsbq %r12b, %rcx
testb $0x8, (%rax,%rcx,2)
jne 0xdc16
shll $0x18, %r12d
xorl $0x2a000000, %r12d      # imm = 0x2A000000
movl $0x1, %eax
orl %ebp, %r12d
jne 0xdc61
orb $0x1, (%rbx)
xorl %ebp, %ebp
movl $0x6, %eax
jmp 0xdc61
movl %ebp, %eax
movl %ebp, %ecx
shrl %ecx
xorl %esi, %esi
xorl %edx, %edx
cmpb %r12b, (%rdx,%r15)
je 0xdc34
incq %rdx
addl $-0x40, %esi
cmpq $0x40, %rdx
jne 0xdc20
jmp 0xdc58
movzwl 0x2(%rbx,%rcx,2), %edi
testb $0x1, %bpl
jne 0xdc46
andl $0x3f, %edi
subl %esi, %edi
jmp 0xdc53
shrl $0x6, %edi
andl $0x3f, %edi
shll $0x6, %edi
addl %edi, %edx
movl %edx, %edi
movw %di, 0x2(%rbx,%rcx,2)
incl %ebp
movb %r12b, 0xa(%rbx,%rax)
xorl %eax, %eax
incq %r14
testl %eax, %eax
je 0xdbb7
cmpl $0x6, %eax
jne 0xdc8f
movzbl (%r14), %eax
testl %eax, %eax
je 0xdae4
cmpl $0x2e, %eax
jne 0xdc8f
incq %r14
movl $0x2, %eax
jmp 0xdae4
xorl %eax, %eax
jmp 0xdc9b
movb $0x3, (%rbx)
movl $0x1, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq