// File: /workspace/github_c_makefile_star2_O2/mmayer[P]pcal/src/readfile.c
// Function: parse_date
int parse_date (char **pword, int *ptype, char ***pptext)
{
   int mm, dd, yy;
   int token, n, v, ord, val, wkd, rtn;
   date_str *pdate;
   char *cp;
   
   pdate = candidate_dates;
   curr_year_reset = FALSE;   /* set below if date is dd/mm/yy */
   
   switch (token = date_type(*pword, &n, &v)) {
      
   case DT_MONTH:   /* <month> dd */
      if (date_style != USA_DATES) return PARSE_INVLINE;

      if ((cp = *++pword) == NULL) return PARSE_INVLINE;
      
      ADD_DATE(n, atoi(cp), curr_year);
      TERM_DATES;
      
      break;

   case DT_DATE:   /* mm/dd{/yy} | dd/mm{/yy} */
      n = split_date(*pword,
                     date_style == USA_DATES ? &mm : &dd,
                     date_style == USA_DATES ? &dd : &mm,
                     &yy);
      
      if (n > 2) {   /* year present? */
         if (yy < 100) yy += century();
         curr_year = yy;   /* reset current year */
         curr_year_reset = TRUE;
      }
      
      ADD_DATE(mm, dd, curr_year);
      TERM_DATES;
      
      break;

   case DT_EURDATE:   /* dd [ <month> | "all" ] */
      if (date_style != EUR_DATES) return PARSE_INVLINE;
      
      dd = atoi(*pword);
      
      if (get_keywd(*++pword) == DT_ALL) {
         for (mm = JAN; mm <= DEC; mm++) {   /* wildcard */
            ADD_DATE(mm, dd, curr_year);
         }
      }
      else {   /* one month */
         if ((mm = get_month(*pword, TRUE, FALSE)) == NOT_MONTH) return PARSE_INVLINE;

         ADD_DATE(mm, dd, curr_year);
      }
      
      TERM_DATES;
      break;
      
   case DT_ALL:   
      /* "all" <weekday> "in" [ <month> | "all" ] or "all" <day>" */
      if ((cp = *(pword+1)) && (*(cp += strspn(cp, DIGITS)) == '\0' || *cp == '*')) {
         dd = atoi(*++pword);   /* "all" <day> */
         for (mm = JAN; mm <= DEC; mm++) ADD_DATE(mm, dd, curr_year);
         TERM_DATES;
         break;   /* leave switch */
      }
      
      n = ORD_ALL;   /* "all" <weekday> ... */
      v = 0;
      /* fall through */
      
   case DT_ORDINAL:   
      /* 
         <ordinal> <weekday> in [ <month> | "all" ] 
            or 
         <ordinal> <weekday> <prep> <date> 
      */
      ord = n;
      val = v;

      /* disambiguate above cases based on preposition */
      if (ord == ORD_POSNUM && pword[1] && (get_prep(pword[2]) != PR_OTHER)) {
         if ((wkd = get_weekday(pword[1], TRUE)) == NOT_WEEKDAY) return PARSE_INVLINE;
         return parse_rel(val, wkd, pword += 2, ptype, pptext);
      }
      if ((rtn = parse_ord(ord, val, pword + 1)) != PARSE_OK) return rtn;
      
      pword += 3;   /* last word of date */
      break;
      
   case DT_WEEKDAY:   /* <weekday> <prep> <date> */
      wkd = n;
      /* parse_rel() calls parse_date() recursively */
      return parse_rel(1, wkd, ++pword, ptype, pptext);
      break;
      
   case DT_PREDEF_EVENT:   /* predefined event */
      /*
         predefined events will either have a redefinition string or a
         dispatch function - never both (cf. pcallang.h)
      */
      if (predef_events[n].pfcn == NULL) {
         char redef[STRSIZ], *rwords[20], **pdum;
         int rtn, idum;

         /* tokenize local copy of redefinition string */
         strcpy(redef, predef_events[n].def);
         (void) loadwords(rwords, redef);

         /* call parse_date() recursively to parse the redefinition - if OK,
            drop through to fill in real ptype and pptext from original string
            (this works basically because the holiday is always the last token
            before the text)
         */
         if ((rtn = parse_date(rwords, &idum, &pdum)) != PARSE_OK) return rtn;
      } 
      else {
         /* predefined event has a dispatch function - use it */
         pdate += (*predef_events[n].pfcn)(pdate);
         TERM_DATES;
      }
      break;
      
   default:
      return PARSE_INVLINE;
      break;
   }

   /* at this point, pword points to the last component of the date; fill in
      type code and pointer to following word (start of text)
   */
   *ptype = LASTCHAR(*pword) == '*' ? HOLIDAY_TEXT : DAY_TEXT;
   *pptext = ++pword;
   
   return PARSE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movb $0x0, 0x225d4(%rip)     # 0x2efa8
movq (%rdi), %rdi
leaq 0xc(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xc226
pushq $0x2
popq %rbp
cmpl $0xa, %eax
ja 0xce2f
movl %eax, %eax
leaq 0x11271(%rip), %rcx     # 0x1dc6c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r14), %rbp
pushq $0x4
popq %r13
xorl %r12d, %r12d
testq %rbp, %rbp
je 0xccb5
leaq 0x8489(%rip), %rsi      # 0x14ea8
movq %rbp, %rdi
callq 0x5190
movzbl (%rbp,%rax), %eax
cmpl $0x2a, %eax
je 0xca39
testl %eax, %eax
jne 0xccb5
movq %r15, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
addq $0x8, %r14
movq %rbp, %rdi
callq 0x52c0
movl %eax, %ebp
movl %eax, 0x30(%rsp)
pushq $0x1
popq %r12
leaq 0x21418(%rip), %r13     # 0x2de78
leaq 0x1fc65(%rip), %rbx     # 0x2c6cc
leaq 0x20b62(%rip), %r15     # 0x2d5d0
cmpl $0xd, %r12d
je 0xcd1f
testb $0x2, (%rbx)
movl (%r15), %edx
jne 0xca95
movl %r12d, -0x8(%r13)
movl %ebp, -0x4(%r13)
movl %edx, (%r13)
incl %r12d
addq $0xc, %r13
jmp 0xca6e
movq 0x1b55c(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x113b5(%rip), %rsi     # 0x1de5b
movl %r12d, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5200
movl (%r15), %edx
jmp 0xca80
movl 0xc(%rsp), %esi
addq $0x8, %r14
pushq $0x1
popq %rdi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd2bf
leaq 0x1faf3(%rip), %rax     # 0x2c5dc
cmpl $0x0, (%rax)
jne 0xce2f
movq 0x8(%r14), %r12
testq %r12, %r12
je 0xce2f
leaq 0x1fbc6(%rip), %rax     # 0x2c6cc
testb $0x2, (%rax)
movl 0xc(%rsp), %ebp
jne 0xce77
addq $0x8, %r14
movl %ebp, 0x21353(%rip)     # 0x2de70
movq %r12, %rdi
callq 0x52c0
movl %eax, 0x21349(%rip)     # 0x2de74
leaq 0x20a9e(%rip), %rax     # 0x2d5d0
movl (%rax), %eax
jmp 0xcd05
movslq 0xc(%rsp), %rax
imulq $0x18, %rax, %rcx
leaq 0x1be27(%rip), %rdx     # 0x28970
movq 0x10(%rdx,%rcx), %rax
testq %rax, %rax
je 0xcd43
leaq 0x21312(%rip), %r12     # 0x2de70
movq %r12, %rdi
callq *%rax
cltq
imulq $0xc, %rax, %rax
andl $0x0, 0x8(%rax,%r12)
andq $0x0, (%rax,%r12)
jmp 0xce0d
leaq 0x1fa5c(%rip), %rax     # 0x2c5dc
cmpl $0x0, (%rax)
movq (%r14), %rdi
leaq 0xd0(%rsp), %rdx
leaq 0x30(%rsp), %rax
movq %rax, %rsi
cmoveq %rdx, %rsi
cmoveq %rax, %rdx
leaq 0x18(%rsp), %rcx
callq 0xa2b3
cmpl $0x2, %eax
jle 0xccd5
movl 0x18(%rsp), %eax
cmpl $0x63, %eax
jg 0xcbc7
callq 0xa0c8
addl 0x18(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x20a02(%rip), %rcx     # 0x2d5d0
movl %eax, (%rcx)
movb $0x1, 0x223d1(%rip)     # 0x2efa8
jmp 0xccde
leaq 0x1f9f9(%rip), %rax     # 0x2c5dc
cmpl $0x1, (%rax)
jne 0xce2f
movq (%r14), %rdi
callq 0x52c0
movl %eax, %r12d
movl %eax, 0x30(%rsp)
movq 0x8(%r14), %rdi
addq $0x8, %r14
callq 0xbf4e
testl %eax, %eax
je 0xcd89
movq (%r14), %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0xbe6c
movl %eax, 0xd0(%rsp)
cmpl $-0x1, %eax
je 0xce2f
movl %eax, %r13d
leaq 0x1fa95(%rip), %rax     # 0x2c6cc
testb $0x2, (%rax)
jne 0xceb5
movl %r13d, 0x21229(%rip)    # 0x2de70
movl %r12d, 0x21226(%rip)    # 0x2de74
leaq 0x2097b(%rip), %rax     # 0x2d5d0
movl (%rax), %eax
movl %eax, 0x2121b(%rip)     # 0x2de78
leaq 0x21218(%rip), %r13     # 0x2de7c
jmp 0xce03
movl 0xc(%rsp), %r13d
movl 0x28(%rsp), %r12d
cmpl $0x1, %r13d
jne 0xccb5
pushq $0x1
popq %r13
cmpq $0x0, 0x8(%r14)
je 0xccb5
movq 0x10(%r14), %rdi
callq 0xc187
cmpl $-0x1, %eax
je 0xccb5
movq 0x8(%r14), %rdi
pushq $0x1
popq %rsi
callq 0xbf9b
cmpl $-0x1, %eax
je 0xce2f
addq $0x10, %r14
movl %r12d, %edi
movl %eax, %esi
jmp 0xcac3
leaq 0x8(%r14), %rdx
movl %r13d, %edi
movl %r12d, %esi
callq 0xcee1
testl %eax, %eax
jne 0xcd82
addq $0x18, %r14
jmp 0xce0d
leaq 0x208f4(%rip), %rax     # 0x2d5d0
movl (%rax), %eax
leaq 0x1f9e7(%rip), %rcx     # 0x2c6cc
testb $0x2, (%rcx)
jne 0xce43
movl 0xd0(%rsp), %ecx
movl %ecx, 0x21175(%rip)     # 0x2de70
movl 0x30(%rsp), %ecx
movl %ecx, 0x2116f(%rip)     # 0x2de74
movl %eax, 0x2116d(%rip)     # 0x2de78
andl $0x0, 0x21172(%rip)     # 0x2de84
andq $0x0, 0x21162(%rip)     # 0x2de7c
jmp 0xce0d
andl $0x0, (%r13)
movl $0xd, 0xd0(%rsp)
andq $0x0, -0x8(%r13)
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %r15
jmp 0xce0d
movq 0x8(%rdx,%rcx), %rsi
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
callq 0x50a0
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xa10d
leaq 0x2c(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r13, %rdi
callq 0xc9b3
testl %eax, %eax
je 0xce0d
movl %eax, %ebp
jmp 0xce2f
movq %r15, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x210d6(%rip), %r13     # 0x2de70
pushq $0x1
popq %rbp
leaq 0x1f928(%rip), %rbx     # 0x2c6cc
leaq 0x20825(%rip), %r15     # 0x2d5d0
cmpl $0xd, %ebp
je 0xcdee
testb $0x2, (%rbx)
movl (%r15), %edx
jne 0xcdcc
movl %ebp, (%r13)
movl %r12d, 0x4(%r13)
movl %edx, 0x8(%r13)
addq $0xc, %r13
incl %ebp
jmp 0xcdab
movq 0x1b225(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x1107e(%rip), %rsi     # 0x1de5b
movl %ebp, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x5200
movl (%r15), %edx
jmp 0xcdb8
movl $0xd, 0xd0(%rsp)
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %r15
andl $0x0, 0x8(%r13)
andq $0x0, (%r13)
movq (%r14), %r12
movq %r12, %rdi
callq 0x5100
xorl %ecx, %ecx
cmpb $0x2a, -0x1(%r12,%rax)
sete %cl
movl %ecx, (%r15)
addq $0x8, %r14
movq %r14, (%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1b1ae(%rip), %rcx     # 0x27ff8
movq (%rcx), %rdi
movl 0xd0(%rsp), %ecx
movl 0x30(%rsp), %r8d
leaq 0x10ffb(%rip), %rsi     # 0x1de5b
movl %eax, %edx
xorl %eax, %eax
callq 0x5200
leaq 0x20760(%rip), %rax     # 0x2d5d0
movl (%rax), %eax
jmp 0xccee
movq 0x1b17a(%rip), %rax     # 0x27ff8
movq (%rax), %r13
leaq 0x20748(%rip), %rax     # 0x2d5d0
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movq %r12, %rdi
callq 0x52c0
leaq 0x10fbe(%rip), %rsi     # 0x1de5b
movq %r13, %rdi
movl 0x10(%rsp), %edx
movl %ebp, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x5200
jmp 0xcb13
movq 0x1b13c(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
leaq 0x2070a(%rip), %rax     # 0x2d5d0
movl (%rax), %edx
leaq 0x10f8c(%rip), %rsi     # 0x1de5b
movl %r13d, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x5200
jmp 0xcc40