// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/fsio/dosmt.c
// Function: dosmtParseFilespec
int dosmtParseFilespec(
  struct mountedFS *mount,
  char *ptr,
  struct dosmtFileSpec *spec,
  int wildcard
)
{
  struct DOSMTdata *data = &mount->dosmtdata;
  char term[] = { '\0', '.', '[', ',', ']' };
  char flags[] =
    { 0, DOSMT_WC_NAME, DOSMT_WC_EXT, DOSMT_WC_PROJ, DOSMT_WC_PROG };
  int state = P_NAME;
  unsigned int uic, i, namemax = ((mount->flags & FS_DOSMTEXT) != 0) ? 9 : 6;
  char filename[9], ext[3];

  memset(spec, 0, sizeof(struct dosmtFileSpec));
  spec->proj = data->proj;
  spec->prog = data->prog;

  memset(&filename, ' ', sizeof(filename));
  memset(&ext, ' ', sizeof(ext));

  if (wildcard == DOSMT_M_NONAME)
    spec->flags = DOSMT_WC_NAME | DOSMT_WC_EXT | DOSMT_WC_PROJ | DOSMT_WC_PROG;

  while (state != P_DONE) {
    if (wildcard) {
      if (*ptr == '*') {
        spec->flags |= flags[state];
        ptr++;
        if (*ptr == '\0')
          state = P_DONE;
        else if (*ptr == term[state]) {
          if (state == P_PROG)
            state = P_DONE;
          else state++;
        } else return 0;
        ptr++;
        continue;
      }
    }

    i = 0;

    switch (state) {
      case P_NAME:
        while ((*ptr != '\0') &&
               (*ptr != '.') &&
               (strchr(rad50, toupper(*ptr)) != NULL) &&
               (i < namemax)) {
          spec->flags &= ~DOSMT_WC_NAME;
          filename[i++] = toupper(*ptr++);
        }

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

          case '.':
            state = P_EXT;
            break;

          case '[':
            state = P_PROJ;
            break;

          default:
            return 0;
        }
        break;

      case P_EXT:
        while ((*ptr != '\0') &&
               (strchr(rad50, toupper(*ptr)) != NULL) &&
               (i < sizeof(ext))) {
          spec->flags &= ~DOSMT_WC_EXT;
          ext[i++] = toupper(*ptr++);
        }

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

          case '[':
            state = P_PROJ;
            break;

          default:
            return 0;
        }
        break;

      case P_PROJ:
        spec->flags &= ~(DOSMT_WC_PROJ | DOSMT_WC_PROG);
        uic = 0;
        while ((strchr("01234567", *ptr) != NULL) && (i < 3)) {
          uic = (uic << 3) | (*ptr++ - '0');
          i++;
        }
        if ((uic == 0) || (uic > 0377))
          return 0;
        spec->proj = uic & 0377;

        if (*ptr++ != ',')
          return 0;

        state = P_PROG;
        break;

      case P_PROG:
        uic = 0;
        while ((strchr("01234567", *ptr) != NULL) && (i < 3)) {
          uic = (uic << 3) | (*ptr++ - '0');
          i++;
        }
        if ((uic == 0) || (uic > 0377))
          return 0;
        spec->prog = uic & 0377;

        if (*ptr++ != ']')
          return 0;

        state = P_DONE;
        break;
    }
  }

  spec->name[0] = ascR50(&filename[0]);
  spec->name[1] = ascR50(&filename[3]);
  spec->name[2] = ascR50(&filename[6]);
  spec->ext = ascR50(&ext[0]);
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbp
movq %rsi, %r14
movzwl 0x30(%rdi), %eax
movl $0x0, 0x8(%rdx)
movq $0x0, (%rdx)
movb 0x250(%rdi), %dl
movb %dl, 0xa(%rbp)
movb 0x251(%rdi), %dl
movb %dl, 0xb(%rbp)
movb $0x20, %sil
movb %sil, 0x18(%rsp)
movabsq $0x2020202020202020, %rdx # imm = 0x2020202020202020
movq %rdx, 0x10(%rsp)
movb %sil, 0xe(%rsp)
movw $0x2020, 0xc(%rsp)      # imm = 0x2020
movl $0x0, %edx
movq %rdx, (%rsp)
movl %ecx, 0x2c(%rsp)
cmpl $0x2, %ecx
jne 0xbd7f
movb $0xf, (%rbp)
movb $0xf, %cl
movq %rcx, (%rsp)
shrl $0x8, %eax
andl $0x1, %eax
leaq (%rax,%rax,2), %rax
addq $0x6, %rax
movq %rax, 0x30(%rsp)
movl $0x1, %eax
movq %rbp, 0x20(%rsp)
cmpl $0x0, 0x2c(%rsp)
je 0xbdef
cmpb $0x2a, (%r14)
jne 0xbdef
movl %eax, %ecx
movq (%rsp), %rdx
leaq 0x668b(%rip), %rsi      # 0x12441
orb (%rcx,%rsi), %dl
movq %rdx, (%rsp)
movb %dl, (%rbp)
movb 0x1(%r14), %dl
testb %dl, %dl
je 0xbfc9
leaq 0x6669(%rip), %rsi      # 0x1243c
cmpb (%rcx,%rsi), %dl
jne 0xc0c6
cmpl $0x4, %eax
leal 0x1(%rax), %eax
movl $0x0, %ecx
cmovel %ecx, %eax
jmp 0xbfcb
decl %eax
leaq 0x6634(%rip), %rcx      # 0x1242c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rsp), %rax
movl %eax, %r13d
andb $-0x2, %r13b
xorl %r15d, %r15d
movzbl (%r14,%r15), %ebx
movsbq %bl, %r12
testl %ebx, %ebx
je 0xbfa5
cmpl $0x2e, %ebx
je 0xbfa5
callq 0x3030
movq (%rax), %rbp
movl (%rbp,%r12,4), %esi
leaq 0xc7e3(%rip), %rdi      # 0x18620
callq 0x3150
testq %rax, %rax
je 0xbfa5
cmpq 0x30(%rsp), %r15
jae 0xbfa5
movq 0x20(%rsp), %rax
movb %r13b, (%rax)
movsbq (%r14,%r15), %rax
movb (%rbp,%rax,4), %al
movb %al, 0x10(%rsp,%r15)
incq %r15
movl %r13d, %eax
movq %rax, (%rsp)
jmp 0xbe0f
movq (%rsp), %rax
andb $-0xd, %al
movq %rax, (%rsp)
movb %al, (%rbp)
movsbl (%r14), %r13d
movl $0x9, %edx
leaq 0x5a73(%rip), %rbx      # 0x11908
movq %rbx, %rdi
movl %r13d, %esi
callq 0x31a0
testq %rax, %rax
je 0xc0c6
xorl %r12d, %r12d
xorl %r15d, %r15d
movl %r15d, %eax
shll $0x3, %eax
addl $-0x30, %r13d
movl %r13d, %r15d
orl %eax, %r15d
movsbl 0x1(%r14,%r12), %r13d
movl $0x9, %edx
movq %rbx, %rdi
movl %r13d, %esi
callq 0x31a0
leaq 0x1(%r12), %rcx
testq %rax, %rax
je 0xbee8
cmpl $0x2, %r12d
movq %rcx, %r12
jb 0xbeaf
leal -0x100(%r15), %edx
xorl %eax, %eax
cmpl $0xffffff01, %edx       # imm = 0xFFFFFF01
jb 0xc020
movb %r15b, 0xa(%rbp)
cmpb $0x2c, (%r14,%rcx)
jne 0xc020
addq %rcx, %r14
incq %r14
movl $0x4, %eax
jmp 0xbfdb
movsbq (%r14), %r13
testq %r13, %r13
je 0xbfe3
callq 0x3030
movq (%rax), %r15
movl (%r15,%r13,4), %esi
leaq 0xc6e4(%rip), %rdi      # 0x18620
callq 0x3150
testq %rax, %rax
je 0xbf96
movq (%rsp), %rax
andb $-0x3, %al
movq %rax, (%rsp)
xorl %ebx, %ebx
movq (%rsp), %rax
movb %al, (%rbp)
movsbq (%r14,%rbx), %rax
movb (%r15,%rax,4), %al
movb %al, 0xc(%rsp,%rbx)
movsbq 0x1(%r14,%rbx), %r13
testq %r13, %r13
je 0xbfe3
leaq 0x1(%rbx), %r12
movl (%r15,%r13,4), %esi
leaq 0xc6a0(%rip), %rdi      # 0x18620
callq 0x3150
testq %rax, %rax
je 0xbf93
cmpq $0x1, %rbx
movq %r12, %rbx
jbe 0xbf52
addq %r12, %r14
cmpb $0x5b, %r13b
jne 0xc0c6
incq %r14
jmp 0xbfc2
addq %r15, %r14
incq %r14
cmpb $0x2e, %bl
je 0xbfd1
movzbl %r12b, %eax
cmpl $0x5b, %eax
movq 0x20(%rsp), %rbp
jne 0xc0be
movl $0x3, %eax
jmp 0xbfdb
xorl %eax, %eax
addq $0x2, %r14
jmp 0xbfdb
movl $0x2, %eax
movq 0x20(%rsp), %rbp
testl %eax, %eax
jne 0xbd9c
leaq 0x10(%rsp), %rdi
callq 0x665e
movw %ax, 0x2(%rbp)
leaq 0x13(%rsp), %rdi
callq 0x665e
movw %ax, 0x4(%rbp)
leaq 0x16(%rsp), %rdi
callq 0x665e
movw %ax, 0x6(%rbp)
leaq 0xc(%rsp), %rdi
callq 0x665e
movw %ax, 0x8(%rbp)
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rbx
movsbl (%r14), %ebp
leaq 0x58cb(%rip), %rdi      # 0x11908
movl $0x9, %edx
movl %ebp, %esi
callq 0x31a0
testq %rax, %rax
je 0xc0c6
xorl %r12d, %r12d
leaq 0x58b0(%rip), %r15      # 0x11908
xorl %r13d, %r13d
movl %r13d, %eax
shll $0x3, %eax
addl $-0x30, %ebp
movl %ebp, %r13d
orl %eax, %r13d
movsbl 0x1(%r14,%r12), %ebp
movl $0x9, %edx
movq %r15, %rdi
movl %ebp, %esi
callq 0x31a0
leaq 0x1(%r12), %rcx
testq %rax, %rax
je 0xc092
cmpl $0x2, %r12d
movq %rcx, %r12
jb 0xc05b
leal -0x100(%r13), %edx
xorl %eax, %eax
cmpl $0xffffff01, %edx       # imm = 0xFFFFFF01
jb 0xc020
movq %rbx, %rbp
movb %r13b, 0xb(%rbx)
cmpb $0x5d, (%r14,%rcx)
je 0xbfe3
jmp 0xc020
testl %eax, %eax
je 0xbfe3
xorl %eax, %eax
jmp 0xc020