// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x30(%rbp)
movl 0xa0e0(%rip), %eax      # 0x1a48c
movl %eax, -0x35(%rbp)
movb 0xa0db(%rip), %al       # 0x1a490
movb %al, -0x31(%rbp)
movl 0xa0d3(%rip), %eax      # 0x1a491
movl %eax, -0x3a(%rbp)
movb 0xa0ce(%rip), %al       # 0x1a495
movb %al, -0x36(%rbp)
movl $0x1, -0x40(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %edx
andl $0x100, %edx            # imm = 0x100
movl $0x6, %eax
movl $0x9, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x3170
movq -0x30(%rbp), %rax
movb 0x208(%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x30(%rbp), %rax
movb 0x209(%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, 0xb(%rax)
leaq -0x55(%rbp), %rdi
movl $0x20, %esi
movl $0x9, %edx
callq 0x3170
leaq -0x58(%rbp), %rdi
movl $0x20, %esi
movl $0x3, %edx
callq 0x3170
cmpl $0x2, -0x24(%rbp)
jne 0x10457
movq -0x20(%rbp), %rax
movb $0xf, (%rax)
jmp 0x10459
cmpl $0x0, -0x40(%rbp)
je 0x10884
cmpl $0x0, -0x24(%rbp)
je 0x10501
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0x104ff
movslq -0x40(%rbp), %rax
movsbl -0x3a(%rbp,%rax), %edx
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x104b2
movl $0x0, -0x40(%rbp)
jmp 0x104ee
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
movslq -0x40(%rbp), %rcx
movsbl -0x35(%rbp,%rcx), %ecx
cmpl %ecx, %eax
jne 0x104e0
cmpl $0x4, -0x40(%rbp)
jne 0x104d5
movl $0x0, -0x40(%rbp)
jmp 0x104de
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x104ec
movl $0x0, -0x4(%rbp)
jmp 0x108e3
jmp 0x104ee
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x10459
jmp 0x10501
movl $0x0, -0x48(%rbp)
movl -0x40(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x3, %eax
ja 0x1087f
movq -0x60(%rbp), %rax
leaq 0x9f55(%rip), %rcx      # 0x1a47c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x10532
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x61(%rbp)
je 0x10588
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2e, %ecx
movb %al, -0x61(%rbp)
je 0x10588
movq -0x18(%rbp), %rax
movsbl (%rax), %edi
callq 0x30d0
movl %eax, %esi
leaq 0xe0a7(%rip), %rdi      # 0x1e610
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x61(%rbp)
je 0x10588
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
setb %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x10591
jmp 0x105cc
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $-0x2, %ecx
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movsbl (%rax), %edi
callq 0x30d0
movb %al, %cl
movl -0x48(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x48(%rbp)
movl %eax, %eax
movb %cl, -0x55(%rbp,%rax)
jmp 0x10532
movq -0x18(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x18(%rbp)
movsbl (%rax), %eax
movl %eax, -0x68(%rbp)
testl %eax, %eax
je 0x105fa
jmp 0x105e6
movl -0x68(%rbp), %eax
subl $0x2e, %eax
je 0x10603
jmp 0x105f0
movl -0x68(%rbp), %eax
subl $0x5b, %eax
je 0x1060c
jmp 0x10615
movl $0x0, -0x40(%rbp)
jmp 0x10621
movl $0x2, -0x40(%rbp)
jmp 0x10621
movl $0x3, -0x40(%rbp)
jmp 0x10621
movl $0x0, -0x4(%rbp)
jmp 0x108e3
jmp 0x1087f
jmp 0x10628
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x69(%rbp)
je 0x1066e
movq -0x18(%rbp), %rax
movsbl (%rax), %edi
callq 0x30d0
movl %eax, %esi
leaq 0xdfc2(%rip), %rdi      # 0x1e610
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x69(%rbp)
je 0x1066e
movl -0x48(%rbp), %eax
cmpq $0x3, %rax
setb %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x10677
jmp 0x106b2
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $-0x3, %ecx
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movsbl (%rax), %edi
callq 0x30d0
movb %al, %cl
movl -0x48(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x48(%rbp)
movl %eax, %eax
movb %cl, -0x58(%rbp,%rax)
jmp 0x10628
movq -0x18(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x18(%rbp)
movsbl (%rax), %eax
movl %eax, -0x70(%rbp)
testl %eax, %eax
je 0x106d6
jmp 0x106cc
movl -0x70(%rbp), %eax
subl $0x5b, %eax
je 0x106df
jmp 0x106e8
movl $0x0, -0x40(%rbp)
jmp 0x106f4
movl $0x3, -0x40(%rbp)
jmp 0x106f4
movl $0x0, -0x4(%rbp)
jmp 0x108e3
jmp 0x1087f
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $-0xd, %ecx
movb %cl, (%rax)
movl $0x0, -0x44(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %esi
leaq 0x9238(%rip), %rdi      # 0x19952
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x71(%rbp)
je 0x10737
cmpl $0x3, -0x48(%rbp)
setb %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x10740
jmp 0x1076b
movl -0x44(%rbp), %eax
shll $0x3, %eax
movq -0x18(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x18(%rbp)
movsbl (%rcx), %ecx
subl $0x30, %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1070c
cmpl $0x0, -0x44(%rbp)
je 0x1077a
cmpl $0xff, -0x44(%rbp)
jbe 0x10786
movl $0x0, -0x4(%rbp)
jmp 0x108e3
movl -0x44(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xa(%rax)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movsbl (%rax), %eax
cmpl $0x2c, %eax
je 0x107ba
movl $0x0, -0x4(%rbp)
jmp 0x108e3
movl $0x4, -0x40(%rbp)
jmp 0x1087f
movl $0x0, -0x44(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %esi
leaq 0x9177(%rip), %rdi      # 0x19952
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x72(%rbp)
je 0x107f8
cmpl $0x3, -0x48(%rbp)
setb %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x10801
jmp 0x1082c
movl -0x44(%rbp), %eax
shll $0x3, %eax
movq -0x18(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x18(%rbp)
movsbl (%rcx), %ecx
subl $0x30, %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x107cd
cmpl $0x0, -0x44(%rbp)
je 0x1083b
cmpl $0xff, -0x44(%rbp)
jbe 0x10847
movl $0x0, -0x4(%rbp)
jmp 0x108e3
movl -0x44(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xb(%rax)
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movsbl (%rax), %eax
cmpl $0x5d, %eax
je 0x10878
movl $0x0, -0x4(%rbp)
jmp 0x108e3
movl $0x0, -0x40(%rbp)
jmp 0x10459
leaq -0x55(%rbp), %rdi
callq 0x5d50
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x2(%rax)
leaq -0x55(%rbp), %rdi
addq $0x3, %rdi
callq 0x5d50
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x4(%rax)
leaq -0x55(%rbp), %rdi
addq $0x6, %rdi
callq 0x5d50
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x6(%rax)
leaq -0x58(%rbp), %rdi
callq 0x5d50
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x8(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop