// File: /workspace/github_c_makefile_star2_O2/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
andw $0x0, 0x8(%rsi)
andq $0x0, (%rsi)
movq %rdi, %r14
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0xa(%rsi)
cmpl $0x2, %edx
jne 0xc7b0
cmpb $0x0, (%r14)
je 0xc8fc
leaq 0x8(%rbx), %r15
leaq 0x2(%rbx), %r13
pushq $0x1
popq %rax
cmpl $0x1, %eax
je 0xc820
cmpl $0x2, %eax
jne 0xc8ff
xorl %r12d, %r12d
movsbq (%r14,%r12), %rbp
testq %rbp, %rbp
je 0xc883
cmpq $0x1, %r12
ja 0xc883
callq 0x3030
movq (%rax), %rax
movl (%rax,%rbp,4), %ebp
callq 0x3300
movq (%rax), %rax
movsbq %bpl, %rcx
testb $0x8, (%rax,%rcx,2)
je 0xc888
movsbl %bpl, %ebp
movl %ebp, %edi
movq %r15, %rsi
movl %r12d, %edx
callq 0xc915
movb %bpl, 0x10(%rbx,%r12)
incq %r12
jmp 0xc7cc
xorl %r12d, %r12d
movsbq (%r14,%r12), %rbp
testq %rbp, %rbp
je 0xc8b3
cmpb $0x2e, %bpl
je 0xc8bd
cmpq $0x5, %r12
ja 0xc8bd
callq 0x3030
movq (%rax), %rax
movl (%rax,%rbp,4), %ebp
callq 0x3300
movq (%rax), %rax
movsbq %bpl, %rcx
testb $0x8, (%rax,%rcx,2)
je 0xc8c2
movq %r12, %rsi
andq $-0x2, %rsi
addq %r13, %rsi
movl %r12d, %edx
andl $0x1, %edx
movsbl %bpl, %ebp
movl %ebp, %edi
callq 0xc915
movb %bpl, 0xa(%rbx,%r12)
incq %r12
jmp 0xc823
addq %r12, %r14
jmp 0xc8a6
shll $0x18, %ebp
xorl %eax, %eax
cmpl $0x2a000000, %ebp       # imm = 0x2A000000
jne 0xc902
testq %r12, %r12
jne 0xc902
addq %r12, %r14
incq %r14
orb $0x2, (%rbx)
movb (%r14), %bpl
xorl %eax, %eax
testb %bpl, %bpl
je 0xc7bb
jmp 0xc902
addq %r12, %r14
xorl %eax, %eax
jmp 0xc7bb
addq %r12, %r14
jmp 0xc8e0
shll $0x18, %ebp
xorl %eax, %eax
cmpl $0x2a000000, %ebp       # imm = 0x2A000000
jne 0xc902
testq %r12, %r12
jne 0xc902
addq %r12, %r14
incq %r14
orb $0x1, (%rbx)
movb (%r14), %bpl
movzbl %bpl, %eax
testb %al, %al
je 0xc7bb
cmpl $0x2e, %eax
jne 0xc911
incq %r14
pushq $0x2
popq %rax
jmp 0xc7bb
movb $0x3, (%rbx)
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0xc902