// File: /workspace/github_c_makefile_star2_O1/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 0x9a45
cmpb $0x0, (%r15)
je 0x9b7c
leaq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0xe(%rbx), %rax
movq %rax, 0x10(%rsp)
movl $0x1, %r14d
cmpl $0x1, %r14d
je 0x9aec
cmpl $0x2, %r14d
jne 0x9b9f
movb (%r15), %bpl
testb %bpl, %bpl
setne %dl
je 0x9ad6
callq 0x32f0
xorl %ecx, %ecx
movb %bpl, 0xe(%rbx,%rcx)
movq (%rax), %rdx
movsbq %bpl, %rsi
testb $0x8, (%rdx,%rsi,2)
jne 0x9ab9
xorl %r13d, %r13d
cmpb $0x2a, %bpl
je 0x9aab
movzbl %bpl, %edx
cmpl $0x25, %edx
jne 0x9b8d
cmpl $0x0, 0x4(%rsp)
je 0x9b8d
orb $0x2, (%rbx)
movb 0x1(%r15,%rcx), %bpl
leaq 0x1(%rcx), %rsi
testb %bpl, %bpl
setne %dl
je 0x9ad3
cmpq $0x2, %rcx
movq %rsi, %rcx
jb 0x9a83
addq %rsi, %r15
xorl %r14d, %r14d
movl $0x0, %r13d
testb %dl, %dl
je 0x9a5d
jmp 0x9b8d
movb (%r15), %bpl
xorl %r14d, %r14d
testb %bpl, %bpl
je 0x9a5d
xorl %r12d, %r12d
cmpb $0x2e, %bpl
je 0x9b52
cmpq $0x5, %r12
ja 0x9b52
movb %bpl, 0x8(%rbx,%r12)
callq 0x32f0
movq (%rax), %rax
movsbq %bpl, %rcx
testb $0x8, (%rax,%rcx,2)
jne 0x9b3d
xorl %r13d, %r13d
cmpb $0x2a, %bpl
je 0x9b33
movzbl %bpl, %eax
cmpl $0x25, %eax
jne 0x9b8d
cmpl $0x0, 0x4(%rsp)
je 0x9b8d
orb $0x1, (%rbx)
movb 0x1(%r15,%r12), %bpl
incq %r12
testb %bpl, %bpl
jne 0x9afe
addq %r12, %r15
jmp 0x9a5d
cmpb $0x2e, %bpl
je 0x9b6b
movzbl %bpl, %eax
testl %eax, %eax
jne 0x9bda
addq %r12, %r15
xorl %r14d, %r14d
jmp 0x9a5d
addq %r12, %r15
incq %r15
movl $0x2, %r14d
jmp 0x9a5d
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, (%rbx)
jne 0x9bbf
movq 0x8(%rsp), %rdi
callq 0x66bc
movw %ax, 0x2(%rbx)
leaq 0xb(%rbx), %rdi
callq 0x66bc
movw %ax, 0x4(%rbx)
movl $0x1, %r13d
testb $0x2, (%rbx)
jne 0x9b8d
movq 0x10(%rsp), %rdi
callq 0x66bc
movw %ax, 0x6(%rbx)
jmp 0x9b8d
xorl %r13d, %r13d
jmp 0x9b8d