// File: /workspace/github_c_makefile_star2_O3/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 $0x188, %rsp            # imm = 0x188
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movb $0x0, 0x225b2(%rip)     # 0x2ffb8
movq (%rdi), %rdi
leaq 0xc(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0xd2ce
movl $0x2, %ebp
cmpl $0xa, %eax
ja 0xde5e
movl %eax, %eax
leaq 0x1228d(%rip), %rcx     # 0x1fcbc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r14), %rbp
movl $0x4, %r13d
xorl %r12d, %r12d
testq %rbp, %rbp
je 0xdcff
leaq 0x94ab(%rip), %rsi      # 0x16f00
movq %rbp, %rdi
callq 0x51a0
movzbl (%rbp,%rax), %eax
cmpl $0x2a, %eax
je 0xda6f
testl %eax, %eax
jne 0xdcff
addq $0x8, %r14
movq %rbp, %rdi
callq 0x52d0
movl %eax, %ebp
movl %eax, 0x20(%rsp)
leaq 0x1fc54(%rip), %rax     # 0x2d6dc
movl (%rax), %eax
leaq 0x20b4f(%rip), %rcx     # 0x2e5e0
movl (%rcx), %edx
movl $0x1, %r12d
leaq 0x213e0(%rip), %r13     # 0x2ee80
testb $0x2, %al
jne 0xdac2
movl %r12d, (%r13)
movl %ebp, 0x4(%r13)
movl %edx, 0x8(%r13)
addq $0xc, %r13
incl %r12d
cmpl $0xd, %r12d
jne 0xdaa0
jmp 0xde21
movq 0x1b527(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
leaq 0x123d8(%rip), %rsi     # 0x1feab
movl %r12d, %ecx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x5210
leaq 0x1fbf5(%rip), %rax     # 0x2d6dc
movl (%rax), %eax
leaq 0x20af0(%rip), %rcx     # 0x2e5e0
movl (%rcx), %edx
jmp 0xdaa4
movl 0xc(%rsp), %esi
addq $0x8, %r14
movl $0x1, %edi
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe2f6
leaq 0x1fac5(%rip), %rax     # 0x2d5ec
cmpl $0x0, (%rax)
jne 0xde5e
movq 0x8(%r14), %r12
testq %r12, %r12
je 0xde5e
leaq 0x1fb98(%rip), %rax     # 0x2d6dc
testb $0x2, (%rax)
movl 0xc(%rsp), %ebp
jne 0xdea6
addq $0x8, %r14
movl %ebp, 0x21325(%rip)     # 0x2ee80
movq %r12, %rdi
callq 0x52d0
movl %eax, 0x2131b(%rip)     # 0x2ee84
leaq 0x20a70(%rip), %rax     # 0x2e5e0
movl (%rax), %eax
jmp 0xdd4f
movslq 0xc(%rsp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x1bdf9(%rip), %rdx     # 0x29980
movq 0x10(%rdx,%rcx,8), %rax
testq %rax, %rax
je 0xdd6f
leaq 0x212e4(%rip), %r12     # 0x2ee80
movq %r12, %rdi
callq *%rax
cltq
leaq (%rax,%rax,2), %rax
movl $0x0, 0x8(%r12,%rax,4)
movq $0x0, (%r12,%rax,4)
jmp 0xde3c
leaq 0x1fa28(%rip), %rax     # 0x2d5ec
cmpl $0x0, (%rax)
movq (%r14), %rdi
leaq 0xc0(%rsp), %rdx
leaq 0x20(%rsp), %rax
movq %rax, %rsi
cmoveq %rdx, %rsi
cmoveq %rax, %rdx
leaq 0x10(%rsp), %rcx
callq 0xb103
cmpl $0x2, %eax
jle 0xdd1f
movl 0x10(%rsp), %eax
cmpl $0x63, %eax
jg 0xdc0b
callq 0xaee9
addl 0x10(%rsp), %eax
movl %eax, 0x10(%rsp)
leaq 0x209ce(%rip), %rcx     # 0x2e5e0
movl %eax, (%rcx)
movb $0x1, 0x2239d(%rip)     # 0x2ffb8
jmp 0xdd28
leaq 0x1f9c5(%rip), %rax     # 0x2d5ec
cmpl $0x1, (%rax)
jne 0xde5e
movq (%r14), %rdi
callq 0x52d0
movl %eax, %r12d
movl %eax, 0x20(%rsp)
movq 0x8(%r14), %rdi
addq $0x8, %r14
callq 0xcfae
testl %eax, %eax
je 0xddb5
movq (%r14), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xcebe
movl %eax, 0xc0(%rsp)
cmpl $-0x1, %eax
je 0xde5e
movl %eax, %r13d
leaq 0x1fa5f(%rip), %rax     # 0x2d6dc
testb $0x2, (%rax)
jne 0xdeb5
movl %r13d, 0x211f3(%rip)    # 0x2ee80
movl %r12d, 0x211f0(%rip)    # 0x2ee84
leaq 0x20945(%rip), %rax     # 0x2e5e0
movl (%rax), %eax
movl %eax, 0x211e5(%rip)     # 0x2ee88
leaq 0x211e2(%rip), %r13     # 0x2ee8c
jmp 0xde2c
movl 0xc(%rsp), %r13d
movl 0x18(%rsp), %r12d
cmpl $0x1, %r13d
jne 0xdcff
movl $0x1, %r13d
cmpq $0x0, 0x8(%r14)
je 0xdcff
movq 0x10(%r14), %rdi
callq 0xd218
cmpl $-0x1, %eax
je 0xdcff
movq 0x8(%r14), %rdi
movl $0x1, %esi
callq 0xd007
cmpl $-0x1, %eax
je 0xde5e
addq $0x10, %r14
movl %r12d, %edi
movl %eax, %esi
jmp 0xdb01
leaq 0x8(%r14), %rdx
movl %r13d, %edi
movl %r12d, %esi
callq 0xdee1
testl %eax, %eax
jne 0xddae
addq $0x18, %r14
jmp 0xde3c
leaq 0x208ba(%rip), %rax     # 0x2e5e0
movl (%rax), %eax
leaq 0x1f9ad(%rip), %rcx     # 0x2d6dc
testb $0x2, (%rcx)
jne 0xde72
movl 0xc0(%rsp), %ecx
movl %ecx, 0x2113b(%rip)     # 0x2ee80
movl 0x20(%rsp), %ecx
movl %ecx, 0x21135(%rip)     # 0x2ee84
movl %eax, 0x21133(%rip)     # 0x2ee88
movl $0x0, 0x21135(%rip)     # 0x2ee94
movq $0x0, 0x21122(%rip) # 0x2ee8c
jmp 0xde3c
movq 0x8(%rdx,%rcx,8), %rsi
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
callq 0x50a0
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xaf3b
leaq 0x1c(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r13, %rdi
callq 0xd9e5
testl %eax, %eax
je 0xde3c
movl %eax, %ebp
jmp 0xde5e
leaq 0x1f920(%rip), %rax     # 0x2d6dc
movl (%rax), %eax
leaq 0x2081b(%rip), %rcx     # 0x2e5e0
movl (%rcx), %edx
movl $0x1, %ebp
leaq 0x210ad(%rip), %r13     # 0x2ee80
testb $0x2, %al
jne 0xddf0
movl %ebp, (%r13)
movl %r12d, 0x4(%r13)
movl %edx, 0x8(%r13)
addq $0xc, %r13
incl %ebp
cmpl $0xd, %ebp
jne 0xddd3
jmp 0xde21
movq 0x1b1f9(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
leaq 0x120aa(%rip), %rsi     # 0x1feab
movl %ebp, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x5210
leaq 0x1f8c8(%rip), %rax     # 0x2d6dc
movl (%rax), %eax
leaq 0x207c3(%rip), %rcx     # 0x2e5e0
movl (%rcx), %edx
jmp 0xddd7
movl $0xd, 0xc0(%rsp)
movl $0x0, 0x8(%r13)
movq $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 $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1b177(%rip), %rcx     # 0x28ff0
movq (%rcx), %rdi
movl 0xc0(%rsp), %ecx
movl 0x20(%rsp), %r8d
leaq 0x1201c(%rip), %rsi     # 0x1feab
movl %eax, %edx
xorl %eax, %eax
callq 0x5210
leaq 0x20741(%rip), %rax     # 0x2e5e0
movl (%rax), %eax
jmp 0xdd38
movq %r12, %rdi
movl %ebp, %esi
callq 0x5653
jmp 0xdb51
movq 0x1b134(%rip), %rax     # 0x28ff0
movq (%rax), %rdi
leaq 0x2071a(%rip), %rax     # 0x2e5e0
movl (%rax), %edx
leaq 0x11fdc(%rip), %rsi     # 0x1feab
movl %r13d, %ecx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x5210
jmp 0xdc86