// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/fsio/rt11.c
// Function: rt11ParseFilespec
int rt11ParseFilespec(
  char *ptr,
  struct rt11FileSpec *spec,
  int wildcard
)
{
  int state = P_NAME;
  unsigned int i;

  memset(spec, 0, sizeof(struct rt11FileSpec));
  memset(&spec->fname, ' ', sizeof(spec->fname));
  memset(&spec->ftype, ' ', sizeof(spec->ftype));

  if (wildcard == RT11_M_NONAME)
    if (*ptr == '\0') {
      spec->flags = RT11_WC_NAME | RT11_WC_TYPE;
      spec->fname[0] = spec->ftype[0] = '*';
      return 1;
    }

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

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

          spec->fname[i++] = ch;

          if (!isalnum(ch))
            switch (ch) {
              case '*':
              case '%':
                if (wildcard) {
                  spec->flags |= RT11_WC_NAME;
                  break;
                }
                /* FALLTHROUGH */

              default:
                return 0;
            }
        }

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

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

          default:
            return 0;
        }
        break;

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

          spec->ftype[i++] = ch;

          if (!isalnum(ch))
            switch (ch) {
              case '*':
              case '%':
                if (wildcard) {
                  spec->flags |= RT11_WC_TYPE;
                  break;
                }
                /* FALLTHROUGH */

              default:
                return 0;
            }
        }

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

        state = P_DONE;
        break;
    }
  }

  if ((spec->flags & RT11_WC_NAME) == 0) {
    spec->name[0] = ascR50(&spec->fname[0]);
    spec->name[1] = ascR50(&spec->fname[3]);
  }
  if ((spec->flags & RT11_WC_TYPE) == 0)
    spec->type = ascR50(&spec->ftype[0]);

  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rsi)
movw $0x0, 0x10(%rsi)
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x8(%rsi)
movb $0x20, 0x10(%rsi)
movl %edx, 0x4(%rsp)
cmpl $0x2, %edx
jne 0x9725
cmpb $0x0, (%r15)
je 0x9860
leaq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0xe(%rbx), %rax
movq %rax, 0x10(%rsp)
movl $0x1, (%rsp)
xorl %r14d, %r14d
movl (%rsp), %eax
cmpl $0x1, %eax
je 0x97db
cmpl $0x2, %eax
jne 0x9883
movb (%r15), %bpl
movl $0x0, (%rsp)
testb %bpl, %bpl
je 0x9741
callq 0x3300
xorl %ecx, %ecx
movb %bpl, 0xe(%rbx,%rcx)
movq (%rax), %rdx
movsbq %bpl, %rsi
testb $0x8, (%rdx,%rsi,2)
jne 0x97a6
xorl %r13d, %r13d
cmpb $0x2a, %bpl
je 0x9794
movzbl %bpl, %edx
cmpl $0x25, %edx
jne 0x9871
cmpl $0x0, 0x4(%rsp)
je 0x9871
orb $0x2, %r14b
movb %r14b, (%rbx)
movb 0x1(%r15,%rcx), %bpl
leaq 0x1(%rcx), %rdx
testb %bpl, %bpl
je 0x97bd
cmpq $0x2, %rcx
movq %rdx, %rcx
jb 0x976c
addq %rdx, %r15
movl $0x0, (%rsp)
movl $0x0, %r13d
testb %bpl, %bpl
je 0x9741
jmp 0x9871
movb (%r15), %r12b
movl $0x0, (%rsp)
testb %r12b, %r12b
je 0x9741
xorl %ebp, %ebp
cmpb $0x2e, %r12b
je 0x9848
cmpq $0x5, %rbp
ja 0x9848
movb %r12b, 0x8(%rbx,%rbp)
callq 0x3300
movq (%rax), %rax
movsbq %r12b, %rcx
testb $0x8, (%rax,%rcx,2)
jne 0x9833
xorl %r13d, %r13d
cmpb $0x2a, %r12b
je 0x9825
movzbl %r12b, %eax
cmpl $0x25, %eax
jne 0x9871
cmpl $0x0, 0x4(%rsp)
je 0x9871
orb $0x1, %r14b
movb %r14b, (%rbx)
movb 0x1(%r15,%rbp), %r12b
incq %rbp
testb %r12b, %r12b
jne 0x97f0
addq %rbp, %r15
jmp 0x9741
cmpb $0x2e, %r12b
jne 0x98c3
addq %rbp, %r15
incq %r15
movl $0x2, (%rsp)
jmp 0x9741
movb $0x3, (%rbx)
movb $0x2a, %al
movb %al, 0xe(%rbx)
movb %al, 0x8(%rbx)
movl $0x1, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, %r14b
jne 0x98a7
movq 0x8(%rsp), %rdi
callq 0x665e
movw %ax, 0x2(%rbx)
leaq 0xb(%rbx), %rdi
callq 0x665e
movw %ax, 0x4(%rbx)
movb (%rbx), %r14b
movl $0x1, %r13d
testb $0x2, %r14b
jne 0x9871
movq 0x10(%rsp), %rdi
callq 0x665e
movw %ax, 0x6(%rbx)
jmp 0x9871
xorl %r13d, %r13d
jmp 0x9871