// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movw $0x0, 0x8(%rsi)
movq $0x0, (%rsi)
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0xa(%rsi)
cmpl $0x2, %edx
jne 0xd86a
cmpb $0x0, (%r14)
je 0xda4b
movl $0x1, %eax
movq $0x0, (%rsp)
leaq 0x4fd2(%rip), %r13      # 0x12850
cmpl $0x1, %eax
je 0xd92e
cmpl $0x2, %eax
jne 0xda4e
movb (%r14), %r12b
xorl %eax, %eax
testb %r12b, %r12b
je 0xd87e
callq 0x3030
movq %rax, %r15
movb $0x1, %bpl
callq 0x3300
xorl %ecx, %ecx
movq (%r15), %rdx
incq %r14
movsbq %r12b, %rsi
movl (%rdx,%rsi,4), %edx
movq (%rax), %rsi
movsbq %dl, %rdi
testb $0x8, (%rsi,%rdi,2)
je 0xd9d8
xorl %edi, %edi
xorl %esi, %esi
cmpb %dl, (%rsi,%r13)
je 0xd8e2
incq %rsi
addl $-0x40, %edi
cmpq $0x40, %rsi
jne 0xd8ce
jmp 0xd90d
movzwl 0x8(%rbx), %r8d
testb $0x1, %bpl
je 0xd8f6
andl $0x3f, %r8d
subl %edi, %r8d
jmp 0xd908
shrl $0x6, %r8d
andl $0x3f, %r8d
shll $0x6, %r8d
addl %r8d, %esi
movl %esi, %r8d
movw %r8w, 0x8(%rbx)
movb %dl, 0x10(%rbx,%rcx)
movb (%r14), %r12b
testb %r12b, %r12b
setne %dl
movl $0x1, %ecx
testb %bpl, %dl
movl $0x0, %ebp
jne 0xd8ac
jmp 0xd9ff
movb (%r14), %bpl
xorl %eax, %eax
testb %bpl, %bpl
je 0xd87e
xorl %r15d, %r15d
cmpb $0x2e, %bpl
je 0xda2d
cmpq $0x5, %r15
ja 0xda2d
callq 0x3030
movq (%rax), %rax
incq %r14
movsbq %bpl, %rcx
movl (%rax,%rcx,4), %ebp
callq 0x3300
movq (%rax), %rax
movsbq %bpl, %rcx
testb $0x8, (%rax,%rcx,2)
je 0xda0c
movq %r15, %rax
shrq %rax
xorl %edx, %edx
xorl %ecx, %ecx
cmpb %bpl, (%rcx,%r13)
je 0xd999
incq %rcx
addl $-0x40, %edx
cmpq $0x40, %rcx
jne 0xd985
jmp 0xd9bd
movzwl 0x2(%rbx,%rax,2), %esi
testb $0x1, %r15b
jne 0xd9ab
andl $0x3f, %esi
subl %edx, %esi
jmp 0xd9b8
shrl $0x6, %esi
andl $0x3f, %esi
shll $0x6, %esi
addl %esi, %ecx
movl %ecx, %esi
movw %si, 0x2(%rbx,%rax,2)
movb %bpl, 0xa(%rbx,%r15)
incq %r15
movb (%r14), %bpl
testb %bpl, %bpl
jne 0xd93f
xorl %eax, %eax
jmp 0xd87e
shll $0x18, %edx
cmpl $0x2a000000, %edx       # imm = 0x2A000000
setne %al
notb %bpl
orb %al, %bpl
testb $0x1, %bpl
jne 0xda62
movq (%rsp), %rax
orb $0x2, %al
movq %rax, (%rsp)
movb %al, (%rbx)
movb (%r14), %r12b
xorl %eax, %eax
testb %r12b, %r12b
je 0xd87e
jmp 0xda53
shll $0x18, %ebp
xorl %eax, %eax
cmpl $0x2a000000, %ebp       # imm = 0x2A000000
jne 0xda53
testq %r15, %r15
jne 0xda53
movq (%rsp), %rax
orb $0x1, %al
movq %rax, (%rsp)
movb %al, (%rbx)
movb (%r14), %bpl
movzbl %bpl, %eax
testb %al, %al
je 0xd87e
cmpl $0x2e, %eax
jne 0xda62
incq %r14
movl $0x2, %eax
jmp 0xd87e
movb $0x3, (%rbx)
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0xda53