// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/dos11.c
// Function: dos11ParseFilespec
int dos11ParseFilespec(
  char *ptr,
  struct dos11FileSpec *spec,
  unsigned char user,
  unsigned char group,
  int wildcard
)
{
  char term[] = { '\0', '.', '[', ',', ']' };
  char flags[] =
    { 0, DOS11_WC_NAME, DOS11_WC_EXT, DOS11_WC_GROUP, DOS11_WC_USER };
  int state = P_NAME;
  unsigned int uic, i;
  char filename[6], ext[3];

  memset(spec, 0, sizeof(struct dos11FileSpec));
  spec->user = user;
  spec->group = group;

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

  if (wildcard == DOS11_M_NONAME)
    if ((*ptr == '\0') || (*ptr == '['))
      spec->flags = DOS11_WC_NAME | DOS11_WC_EXT;

  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_USER)
            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 < sizeof(filename)))
          filename[i++] = toupper(*ptr++);

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

          case '.':
            state = P_EXT;
            break;

          case '[':
            state = P_GROUP;
            break;

          default:
            return 0;
        }
        break;

      case P_EXT:
        while ((*ptr != '\0') &&
               (strchr(rad50, toupper(*ptr)) != NULL) &&
               (i < sizeof(ext)))
          ext[i++] = toupper(*ptr++);
        
        switch (*ptr++) {
          case '\0':
            state = P_DONE;
            break;

          case '[':
            state = P_GROUP;
            break;

          default:
            return 0;
        }
        break;

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

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

        state = P_USER;
        break;

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

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

        state = P_DONE;
        break;
    }
  }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %cl, -0x19(%rbp)
movb %al, -0x1a(%rbp)
movl %r8d, -0x20(%rbp)
movl 0x1159c(%rip), %eax     # 0x198c0
movl %eax, -0x25(%rbp)
movb 0x11597(%rip), %al      # 0x198c4
movb %al, -0x21(%rbp)
movl 0x1158f(%rip), %eax     # 0x198c5
movl %eax, -0x2a(%rbp)
movb 0x1158a(%rip), %al      # 0x198c9
movb %al, -0x26(%rbp)
movl $0x1, -0x30(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3170
movb -0x19(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x8(%rax)
movb -0x1a(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x9(%rax)
leaq -0x3e(%rbp), %rdi
movl $0x20, %esi
movl $0x6, %edx
callq 0x3170
leaq -0x41(%rbp), %rdi
movl $0x20, %esi
movl $0x3, %edx
callq 0x3170
cmpl $0x2, -0x20(%rbp)
jne 0x83ba
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x83b1
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0x83b8
movq -0x18(%rbp), %rax
movb $0x3, (%rax)
jmp 0x83ba
jmp 0x83bc
cmpl $0x0, -0x30(%rbp)
je 0x87c1
cmpl $0x0, -0x20(%rbp)
je 0x8464
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0x8462
movslq -0x30(%rbp), %rax
movsbl -0x2a(%rbp,%rax), %edx
movq -0x18(%rbp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x8415
movl $0x0, -0x30(%rbp)
jmp 0x8451
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
movslq -0x30(%rbp), %rcx
movsbl -0x25(%rbp,%rcx), %ecx
cmpl %ecx, %eax
jne 0x8443
cmpl $0x4, -0x30(%rbp)
jne 0x8438
movl $0x0, -0x30(%rbp)
jmp 0x8441
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x844f
movl $0x0, -0x4(%rbp)
jmp 0x8808
jmp 0x8451
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x83bc
jmp 0x8464
movl $0x0, -0x38(%rbp)
movl -0x30(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x3, %eax
ja 0x87bc
movq -0x50(%rbp), %rax
leaq 0x11426(%rip), %rcx     # 0x198b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x8495
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x51(%rbp)
je 0x84ec
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2e, %ecx
movb %al, -0x51(%rbp)
je 0x84ec
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x30d0
movl %eax, %esi
leaq 0x16144(%rip), %rdi     # 0x1e610
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x51(%rbp)
je 0x84ec
movl -0x38(%rbp), %eax
cmpq $0x6, %rax
setb %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x84f5
jmp 0x8524
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %edi
callq 0x30d0
movb %al, %cl
movl -0x38(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x38(%rbp)
movl %eax, %eax
movb %cl, -0x3e(%rbp,%rax)
jmp 0x8495
movq -0x10(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %eax
movl %eax, -0x58(%rbp)
testl %eax, %eax
je 0x8552
jmp 0x853e
movl -0x58(%rbp), %eax
subl $0x2e, %eax
je 0x855b
jmp 0x8548
movl -0x58(%rbp), %eax
subl $0x5b, %eax
je 0x8564
jmp 0x856d
movl $0x0, -0x30(%rbp)
jmp 0x8579
movl $0x2, -0x30(%rbp)
jmp 0x8579
movl $0x3, -0x30(%rbp)
jmp 0x8579
movl $0x0, -0x4(%rbp)
jmp 0x8808
jmp 0x87bc
jmp 0x8580
movq -0x10(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x59(%rbp)
je 0x85c6
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x30d0
movl %eax, %esi
leaq 0x1606a(%rip), %rdi     # 0x1e610
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x59(%rbp)
je 0x85c6
movl -0x38(%rbp), %eax
cmpq $0x3, %rax
setb %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x85cf
jmp 0x85fb
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %edi
callq 0x30d0
movb %al, %cl
movl -0x38(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x38(%rbp)
movl %eax, %eax
movb %cl, -0x41(%rbp,%rax)
jmp 0x8580
movq -0x10(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %eax
movl %eax, -0x60(%rbp)
testl %eax, %eax
je 0x861f
jmp 0x8615
movl -0x60(%rbp), %eax
subl $0x5b, %eax
je 0x8628
jmp 0x8631
movl $0x0, -0x30(%rbp)
jmp 0x863d
movl $0x3, -0x30(%rbp)
jmp 0x863d
movl $0x0, -0x4(%rbp)
jmp 0x8808
jmp 0x87bc
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %esi
leaq 0x112fb(%rip), %rdi     # 0x19952
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x61(%rbp)
je 0x8674
cmpl $0x3, -0x38(%rbp)
setb %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x867d
jmp 0x86a8
movl -0x34(%rbp), %eax
shll $0x3, %eax
movq -0x10(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movsbl (%rcx), %ecx
subl $0x30, %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x8649
cmpl $0x0, -0x34(%rbp)
je 0x86b7
cmpl $0xff, -0x34(%rbp)
jbe 0x86c3
movl $0x0, -0x4(%rbp)
jmp 0x8808
movl -0x34(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x9(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %eax
cmpl $0x2c, %eax
je 0x86f7
movl $0x0, -0x4(%rbp)
jmp 0x8808
movl $0x4, -0x30(%rbp)
jmp 0x87bc
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %esi
leaq 0x1123a(%rip), %rdi     # 0x19952
callq 0x3150
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x62(%rbp)
je 0x8735
cmpl $0x3, -0x38(%rbp)
setb %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
testb $0x1, %al
jne 0x873e
jmp 0x8769
movl -0x34(%rbp), %eax
shll $0x3, %eax
movq -0x10(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x10(%rbp)
movsbl (%rcx), %ecx
subl $0x30, %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x870a
cmpl $0x0, -0x34(%rbp)
je 0x8778
cmpl $0xff, -0x34(%rbp)
jbe 0x8784
movl $0x0, -0x4(%rbp)
jmp 0x8808
movl -0x34(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movsbl (%rax), %eax
cmpl $0x5d, %eax
je 0x87b5
movl $0x0, -0x4(%rbp)
jmp 0x8808
movl $0x0, -0x30(%rbp)
jmp 0x83bc
leaq -0x3e(%rbp), %rdi
callq 0x5d50
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
leaq -0x3e(%rbp), %rdi
addq $0x3, %rdi
callq 0x5d50
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
leaq -0x41(%rbp), %rdi
callq 0x5d50
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x6(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)