// File: /workspace/github_c_makefile_star2_O1/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, 0x21a5a(%rip)     # 0x2efb8
movq (%rdi), %rdi
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %rdx
callq 0xce0d
movl $0x2, %ebp
cmpl $0xa, %eax
ja 0xd928
movl %eax, %eax
leaq 0x116c1(%rip), %rcx     # 0x1ec48
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r14), %r12
testq %r12, %r12
je 0xd854
leaq 0x8904(%rip), %rsi      # 0x15ea8
movq %r12, %rdi
callq 0x51a0
movzbl (%r12,%rax), %eax
cmpl $0x2a, %eax
je 0xd5be
testl %eax, %eax
jne 0xd854
addq $0x8, %r14
movq %r12, %rdi
callq 0x52d0
movl %eax, 0x20(%rsp)
movl $0x1, 0xc0(%rsp)
movl $0x1, %ecx
leaq 0x2089b(%rip), %r13     # 0x2de80
leaq 0x1f0f0(%rip), %rbp     # 0x2c6dc
leaq 0x1ffed(%rip), %r12     # 0x2d5e0
testb $0x2, (%rbp)
jne 0xd62c
movl 0xc0(%rsp), %eax
movl %eax, (%r13)
movl 0x20(%rsp), %ecx
movl %ecx, 0x4(%r13)
movl (%r12), %ecx
movl %ecx, 0x8(%r13)
addq $0xc, %r13
leal 0x1(%rax), %ecx
movl %ecx, 0xc0(%rsp)
cmpl $0xc, %eax
jl 0xd5f3
jmp 0xd83f
movq 0x1a9bd(%rip), %rax     # 0x27ff0
movq (%rax), %rdi
movl (%r12), %edx
movl 0x20(%rsp), %r8d
leaq 0x117f1(%rip), %rsi     # 0x1ee37
xorl %eax, %eax
callq 0x5210
jmp 0xd5f9
movl 0x8(%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 0xde32
movslq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x1b2f5(%rip), %rdx     # 0x28980
movq 0x10(%rdx,%rcx,8), %rax
testq %rax, %rax
je 0xd8c7
leaq 0x207e0(%rip), %r12     # 0x2de80
movq %r12, %rdi
callq *%rax
cltq
leaq (%rax,%rax,2), %rax
movl $0x0, 0x8(%r12,%rax,4)
movq $0x0, (%r12,%rax,4)
jmp 0xd906
leaq 0x1ef24(%rip), %rax     # 0x2c5ec
cmpl $0x0, (%rax)
jne 0xd928
movq 0x8(%r14), %r12
testq %r12, %r12
je 0xd928
leaq 0x1eff7(%rip), %rax     # 0x2c6dc
testb $0x2, (%rax)
jne 0xd9d4
addq $0x8, %r14
movl 0x8(%rsp), %eax
movl %eax, 0x20784(%rip)     # 0x2de80
movq %r12, %rdi
callq 0x52d0
jmp 0xd783
leaq 0x1eedf(%rip), %rax     # 0x2c5ec
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 0xab3b
movl %eax, 0x8(%rsp)
cmpl $0x3, %eax
jl 0xd762
cmpl $0x63, 0x10(%rsp)
jg 0xd74e
callq 0xa92f
addl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
leaq 0x1fe87(%rip), %rcx     # 0x2d5e0
movl %eax, (%rcx)
movb $0x1, 0x21856(%rip)     # 0x2efb8
leaq 0x1ef73(%rip), %rax     # 0x2c6dc
testb $0x2, (%rax)
jne 0xd9bd
movl 0xc0(%rsp), %eax
movl %eax, 0x20701(%rip)     # 0x2de80
movl 0x20(%rsp), %eax
movl %eax, 0x206fb(%rip)     # 0x2de84
leaq 0x1fe50(%rip), %rax     # 0x2d5e0
movl (%rax), %eax
movl %eax, 0x206f0(%rip)     # 0x2de88
movl $0x0, 0x206f2(%rip)     # 0x2de94
movq $0x0, 0x206df(%rip) # 0x2de8c
jmp 0xd906
leaq 0x1ee33(%rip), %rax     # 0x2c5ec
cmpl $0x1, (%rax)
jne 0xd928
movq (%r14), %rdi
callq 0x52d0
movl %eax, 0x20(%rsp)
movq 0x8(%r14), %rdi
addq $0x8, %r14
callq 0xcae2
testl %eax, %eax
je 0xd93c
movq (%r14), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0xc9f2
movl %eax, 0xc0(%rsp)
cmpl $-0x1, %eax
je 0xd928
leaq 0x1eed3(%rip), %rcx     # 0x2c6dc
testb $0x2, (%rcx)
jne 0xd9e6
movl 0xc0(%rsp), %eax
movl %eax, 0x20661(%rip)     # 0x2de80
movl 0x20(%rsp), %eax
movl %eax, 0x2065b(%rip)     # 0x2de84
leaq 0x1fdb0(%rip), %rax     # 0x2d5e0
movl (%rax), %eax
movl %eax, 0x20650(%rip)     # 0x2de88
leaq 0x2064d(%rip), %r13     # 0x2de8c
movl $0x0, 0x8(%r13)
movq $0x0, (%r13)
jmp 0xd906
movl $0x4, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
movl 0x8(%rsp), %r13d
movl 0xc(%rsp), %r12d
cmpl $0x1, %r13d
jne 0xd8ae
cmpq $0x0, 0x8(%r14)
je 0xd8ae
movq 0x10(%r14), %rdi
callq 0xcd57
cmpl $-0x1, %eax
je 0xd8ae
movq 0x8(%r14), %rdi
movl $0x1, %esi
callq 0xcb3b
cmpl $-0x1, %eax
je 0xd928
addq $0x10, %r14
movl %r12d, %edi
movl %eax, %esi
jmp 0xd65c
leaq 0x8(%r14), %rdx
movl %r13d, %edi
movl %r12d, %esi
callq 0xda13
testl %eax, %eax
jne 0xd902
addq $0x18, %r14
jmp 0xd906
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 0xa985
leaq 0x1c(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r13, %rdi
callq 0xd53d
testl %eax, %eax
je 0xd906
movl %eax, %ebp
jmp 0xd928
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
movl $0x1, 0xc0(%rsp)
movl $0x1, %ecx
leaq 0x2052d(%rip), %r13     # 0x2de80
leaq 0x1ed82(%rip), %rbp     # 0x2c6dc
leaq 0x1fc7f(%rip), %r12     # 0x2d5e0
testb $0x2, (%rbp)
jne 0xd99a
movl 0xc0(%rsp), %eax
movl %eax, (%r13)
movl 0x20(%rsp), %ecx
movl %ecx, 0x4(%r13)
movl (%r12), %ecx
movl %ecx, 0x8(%r13)
addq $0xc, %r13
leal 0x1(%rax), %ecx
movl %ecx, 0xc0(%rsp)
cmpl $0xc, %eax
jl 0xd961
jmp 0xd83f
movq 0x1a64f(%rip), %rax     # 0x27ff0
movq (%rax), %rdi
movl (%r12), %edx
movl 0x20(%rsp), %r8d
leaq 0x11483(%rip), %rsi     # 0x1ee37
xorl %eax, %eax
callq 0x5210
jmp 0xd967
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5684
jmp 0xd772
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x56b3
jmp 0xd6ee
movq 0x1a603(%rip), %rcx     # 0x27ff0
movq (%rcx), %rdi
leaq 0x1fbe9(%rip), %rcx     # 0x2d5e0
movl (%rcx), %edx
movl 0x20(%rsp), %r8d
leaq 0x11432(%rip), %rsi     # 0x1ee37
movl %eax, %ecx
xorl %eax, %eax
callq 0x5210
jmp 0xd812