// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathmsc.cpp
// Function: read_calendar(char*, int)
int read_calendar(char *s, int erase)
{
FILE *cal_file;
int i;
int nth, day, month;
char text[128+1];
int len;
char *buf;
int field;
int text_ptr;
int val;
int sign;
int skipping;
char c;

   // Replace default greetings with data from HEATHER.CAL
   cal_file = topen(s, "r");
   if(cal_file == 0) return 1;

   if(erase) clear_calendar();   // clear out the old calendar

   while(fgets(out, sizeof out, cal_file) != NULL) {
      if((out[0] == '*') || (out[0] == ';') || (out[0] == '/') || (out[0] == '#')) {
         if(!strnicmp(out, "#CLEAR", 6)) clear_calendar();
         continue;  // comment line
      }

      field = 0;
      text[0] = 0;
      text_ptr = 0;
      val = 0;
      skipping = 1;
      sign = (+1);

      len = strlen(out);
      for(i=0; i<len; i++) {
         c = out[i];
         if     (c == 0x00) break;
         else if(c == 0x0D) break;
         else if(c == 0x0A) break;
         else if(field < 4) {  // getting a number value
            if     (c == '-') { sign = (-1); skipping=0; }
            else if(c == '+') { sign = (+1);  skipping=0; }
            else if((c >= '0') && (c <= '9')) {
               val = (val*10) + (c-'0');
               skipping = 0;
            }
            else if((c == ' ') || (c == '\t') || (c == ',')) {
               if(skipping) continue;
               ++field;
               if     (field == 1) {
                  nth = val*sign;
               }
               else if(field == 2) day = val*sign;
               else if(field == 3) { month = val*sign; ++field; }
               skipping = 1;
               sign = 1;
               val = 0;
            }
            else {  // invalid char in a number, ignore the line
               break;
            }
         }
         else if(((c == ' ') || (c == '\t')) && skipping) {
            continue;
         }
         else {  // get the text string
            text[text_ptr++] = c;
            text[text_ptr] = 0;
            skipping = 0;
            field = 4;
         }
      }
      if(field != 4) continue;

      buf = (char *) calloc(len+1, 1);
      if(buf == 0) break;

      strcpy(buf, text);
      holiday[calendar_entries].nth = nth;
      holiday[calendar_entries].day = day;
      holiday[calendar_entries].month = month;
      holiday[calendar_entries].text = buf;

      if(++calendar_entries >= MAX_HOLIDAYS) break;
   }

   fclose(cal_file);

   calc_greetings();
   show_greetings();
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %esi, %r14d
leaq 0x4651b(%rip), %rsi     # 0x120cad
callq 0x9a4d
testq %rax, %rax
je 0xdaa63
movq %rax, %rbx
testl %r14d, %r14d
je 0xda7dd
movl $0x8, %eax
leaq 0x9069c(%rip), %rcx     # 0x16ae50
movl $0x0, (%rax,%rcx)
movq $0x0, -0x8(%rax,%rcx)
addq $0x18, %rax
cmpq $0x2258, %rax           # imm = 0x2258
jne 0xda7b4
leaq 0x13e019(%rip), %rax    # 0x2187f0
movl $0x0, (%rax)
leaq 0x261a3c(%rip), %r14    # 0x33c220
movq %r14, %rdi
movl $0x201, %esi            # imm = 0x201
movq %rbx, %rdx
callq 0x9600
testq %rax, %rax
je 0xdaa4d
leaq 0x9064c(%rip), %r15     # 0x16ae50
movabsq $0x800840800000000, %r13 # imm = 0x800840800000000
leaq 0x5a28f(%rip), %r12     # 0x134aa4
movzbl (%r14), %eax
cmpq $0x3b, %rax
ja 0xda882
btq %rax, %r13
jae 0xda882
movl $0x6, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x94a0
testl %eax, %eax
jne 0xda868
movl $0x8, %eax
movl $0x0, (%rax,%r15)
movq $0x0, -0x8(%rax,%r15)
addq $0x18, %rax
cmpq $0x2258, %rax           # imm = 0x2258
jne 0xda83e
leaq 0x13df8e(%rip), %rax    # 0x2187f0
movl $0x0, (%rax)
movq %r14, %rdi
movl $0x201, %esi            # imm = 0x201
movq %rbx, %rdx
callq 0x9600
testq %rax, %rax
jne 0xda815
jmp 0xdaa4d
movb $0x0, -0xd0(%rbp)
movq %r14, %rdi
callq 0x9120
xorl %edi, %edi
testl %eax, %eax
jle 0xda9de
movq %rax, -0x48(%rbp)
movq %rax, %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl $0x1, %r11d
xorl %esi, %esi
movl $0x1, -0x30(%rbp)
xorl %r8d, %r8d
xorl %edx, %edx
movzbl (%r14,%rsi), %r9d
cmpl $0xd, %r9d
ja 0xda8d6
movl $0x2401, %eax           # imm = 0x2401
btl %r9d, %eax
jb 0xda9d3
cmpl $0x3, %edx
jg 0xda8f6
xorl %r10d, %r10d
cmpl $0x2d, %r9d
je 0xda936
cmpl $0x2b, %r9d
jne 0xda93f
movl $0x1, -0x30(%rbp)
jmp 0xda976
cmpb $0x20, %r9b
sete %r10b
cmpb $0x9, %r9b
sete %al
testl %r11d, %r11d
je 0xda915
orb %al, %r10b
movl $0x1, %r10d
jne 0xda976
movslq %r8d, %rax
leaq 0x1(%rax), %r8
movb %r9b, -0xd0(%rbp,%rax)
movb $0x0, -0xcf(%rbp,%rax)
xorl %r10d, %r10d
movl $0x4, %edx
jmp 0xda976
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0xda976
leal -0x30(%r9), %eax
cmpb $0x9, %al
ja 0xda952
leal (%rdi,%rdi,4), %edi
movzbl %al, %eax
leal (%rax,%rdi,2), %edi
jmp 0xda976
cmpl $0x2c, %r9d
ja 0xda9d3
movl %r9d, %eax
movabsq $0x100100000200, %r9    # imm = 0x100100000200
btq %rax, %r9
jae 0xda9d3
movl $0x1, %r10d
testl %r11d, %r11d
je 0xda987
incq %rsi
movl %r10d, %r11d
cmpq %rsi, %rcx
jne 0xda8bc
jmp 0xda9d3
testl %edx, %edx
je 0xda9a5
cmpl $0x2, %edx
je 0xda9ba
cmpl $0x1, %edx
jne 0xda9ca
movl -0x30(%rbp), %eax
imull %edi, %eax
movl $0x2, %edx
movl %eax, -0x34(%rbp)
jmp 0xda9cc
movl -0x30(%rbp), %eax
imull %edi, %eax
xorl %edi, %edi
movl $0x1, %edx
movl %eax, -0x3c(%rbp)
jmp 0xda8ea
movl -0x30(%rbp), %eax
imull %edi, %eax
movl $0x4, %edx
movl %eax, -0x38(%rbp)
jmp 0xda9cc
incl %edx
xorl %edi, %edi
jmp 0xda8ea
cmpl $0x4, %edx
sete %dil
movq -0x48(%rbp), %rax
testb %dil, %dil
je 0xda868
incl %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x9230
testq %rax, %rax
je 0xdaa4d
movq %rax, %rdi
leaq -0xd0(%rbp), %rsi
movq %rax, -0x30(%rbp)
callq 0x9340
leaq 0x13dddb(%rip), %rdx    # 0x2187f0
movslq (%rdx), %rax
leaq (%rax,%rax,2), %rcx
movl -0x3c(%rbp), %esi
movl %esi, (%r15,%rcx,8)
movl -0x34(%rbp), %esi
movl %esi, 0x4(%r15,%rcx,8)
movl -0x38(%rbp), %esi
movl %esi, 0x8(%r15,%rcx,8)
movq -0x30(%rbp), %rsi
movq %rsi, 0x10(%r15,%rcx,8)
leal 0x1(%rax), %ecx
movl %ecx, (%rdx)
cmpq $0x16d, %rax            # imm = 0x16D
jl 0xda868
movq %rbx, %rdi
callq 0x9370
callq 0xe455f
callq 0xe3e17
xorl %eax, %eax
jmp 0xdaa68
movl $0x1, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq