// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rsi)
andw $0x0, 0x10(%rsi)
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rax, 0x8(%rsi)
movb $0x20, 0x10(%rsi)
movl %edx, 0xc(%rsp)
cmpl $0x2, %edx
jne 0x8338
cmpb $0x0, (%r15)
je 0x845a
leaq 0x8(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0xe(%rbx), %rax
movq %rax, 0x20(%rsp)
pushq $0x1
popq %r13
xorl %r12d, %r12d
cmpl $0x1, %r13d
je 0x83cd
cmpl $0x2, %r13d
jne 0x846b
movq %r12, 0x10(%rsp)
movl %r12d, %r14d
orb $0x2, %r14b
xorl %ebp, %ebp
movsbq (%r15), %r12
testq %r12, %r12
je 0x842d
cmpq $0x2, %rbp
ja 0x842d
incq %r15
movb %r12b, 0xe(%rbx,%rbp)
incq %rbp
callq 0x3300
movq (%rax), %rax
testb $0x8, (%rax,%r12,2)
jne 0x836f
movzbl %r12b, %eax
xorl %r13d, %r13d
cmpl $0x2a, %eax
je 0x83b5
cmpl $0x25, %eax
jne 0x84ac
cmpl $0x0, 0xc(%rsp)
je 0x84ac
movb %r14b, (%rbx)
movl %r14d, %eax
movq %rax, 0x10(%rsp)
jmp 0x836f
movl %r12d, %r14d
orb $0x1, %r14b
xorl %ebp, %ebp
movsbq (%r15), %r13
testq %r13, %r13
je 0x8440
cmpb $0x2e, %r13b
je 0x8448
cmpq $0x5, %rbp
ja 0x8448
incq %r15
movb %r13b, 0x8(%rbx,%rbp)
incq %rbp
callq 0x3300
movq (%rax), %rax
testb $0x8, (%rax,%r13,2)
jne 0x83d6
movzbl %r13b, %eax
xorl %r13d, %r13d
cmpl $0x2a, %eax
je 0x841a
cmpl $0x25, %eax
jne 0x84ac
cmpl $0x0, 0xc(%rsp)
je 0x84ac
movb %r14b, (%rbx)
movl %r14d, %r12d
jmp 0x83d6
xorl %r13d, %r13d
testb %r12b, %r12b
movq 0x10(%rsp), %r12
je 0x8351
jmp 0x84ac
xorl %r13d, %r13d
jmp 0x8351
cmpb $0x2e, %r13b
jne 0x84a9
incq %r15
pushq $0x2
popq %r13
jmp 0x8351
movb $0x3, (%rbx)
movb $0x2a, %al
movb %al, 0xe(%rbx)
movb %al, 0x8(%rbx)
pushq $0x1
popq %r13
jmp 0x84ac
testb $0x1, %r12b
jne 0x848f
movq 0x18(%rsp), %rdi
callq 0x5119
movw %ax, 0x2(%rbx)
leaq 0xb(%rbx), %rdi
callq 0x5119
movw %ax, 0x4(%rbx)
movb (%rbx), %r12b
pushq $0x1
popq %r13
testb $0x2, %r12b
jne 0x84ac
movq 0x20(%rsp), %rdi
callq 0x5119
movw %ax, 0x6(%rbx)
jmp 0x84ac
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq