// File: /workspace/github_cpp_makefile_star2_O3/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 0x45f61(%rip), %rsi     # 0x120d8d
callq 0x9a47
testq %rax, %rax
je 0xdb11e
movq %rax, %rbx
testl %r14d, %r14d
je 0xdae77
movl $0x8, %eax
leaq 0x90002(%rip), %rcx     # 0x16ae50
movl $0x0, (%rax,%rcx)
movq $0x0, -0x8(%rax,%rcx)
addq $0x18, %rax
cmpq $0x2258, %rax           # imm = 0x2258
jne 0xdae4e
leaq 0x13d97f(%rip), %rax    # 0x2187f0
movl $0x0, (%rax)
leaq 0x2613a2(%rip), %r14    # 0x33c220
movq %r14, %rdi
movl $0x201, %esi            # imm = 0x201
movq %rbx, %rdx
callq 0x9600
testq %rax, %rax
je 0xdb108
leaq 0x8ffb2(%rip), %r13     # 0x16ae50
movabsq $0x800840800000000, %r15 # imm = 0x800840800000000
leaq 0x59ce5(%rip), %r12     # 0x134b94
movzbl (%r14), %eax
cmpq $0x3b, %rax
ja 0xdaf1c
btq %rax, %r15
jae 0xdaf1c
movl $0x6, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x94a0
testl %eax, %eax
jne 0xdaf02
movl $0x8, %eax
movl $0x0, (%rax,%r13)
movq $0x0, -0x8(%rax,%r13)
addq $0x18, %rax
cmpq $0x2258, %rax           # imm = 0x2258
jne 0xdaed8
leaq 0x13d8f4(%rip), %rax    # 0x2187f0
movl $0x0, (%rax)
movq %r14, %rdi
movl $0x201, %esi            # imm = 0x201
movq %rbx, %rdx
callq 0x9600
testq %rax, %rax
jne 0xdaeaf
jmp 0xdb108
movb $0x0, -0xd0(%rbp)
movq %r14, %rdi
callq 0x9120
testl %eax, %eax
jle 0xdaf02
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
movl $0x1, %r11d
movl $0x1, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
xorl %esi, %esi
xorl %edi, %edi
movzbl (%r14,%rdx), %r9d
cmpl $0xd, %r9d
ja 0xdaf6d
movl $0x2401, %r8d           # imm = 0x2401
btl %r9d, %r8d
jb 0xdb098
cmpl $0x3, %edi
jg 0xdaf8d
xorl %r10d, %r10d
cmpl $0x2d, %r9d
je 0xdafce
cmpl $0x2b, %r9d
jne 0xdafd7
movl $0x1, -0x30(%rbp)
jmp 0xdb023
cmpb $0x20, %r9b
sete %r10b
cmpb $0x9, %r9b
sete %r8b
testl %r11d, %r11d
je 0xdafad
orb %r8b, %r10b
movl $0x1, %r10d
jne 0xdb023
movslq %esi, %rdi
leaq 0x1(%rdi), %rsi
movb %r9b, -0xd0(%rbp,%rdi)
movb $0x0, -0xcf(%rbp,%rdi)
xorl %r10d, %r10d
movl $0x4, %edi
jmp 0xdb023
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0xdb023
leal -0x30(%r9), %r8d
cmpb $0x9, %r8b
ja 0xdaff7
movq -0x38(%rbp), %r9
leal (%r9,%r9,4), %r9d
movzbl %r8b, %r8d
leal (%r8,%r9,2), %r8d
movq %r8, -0x38(%rbp)
jmp 0xdb023
cmpl $0x2c, %r9d
ja 0xdaf02
movl %r9d, %r8d
movabsq $0x100100000200, %r9    # imm = 0x100100000200
btq %r8, %r9
jae 0xdaf02
movl $0x1, %r10d
testl %r11d, %r11d
je 0xdb034
incq %rdx
movl %r10d, %r11d
cmpq %rdx, %rcx
jne 0xdaf52
jmp 0xdb098
testl %edi, %edi
je 0xdb056
cmpl $0x2, %edi
je 0xdb075
cmpl $0x1, %edi
jne 0xdb089
movl -0x30(%rbp), %r8d
imull -0x38(%rbp), %r8d
movl $0x2, %edi
movl %r8d, -0x3c(%rbp)
jmp 0xdb08b
movl -0x30(%rbp), %r8d
imull -0x38(%rbp), %r8d
movq $0x0, -0x38(%rbp)
movl $0x1, %edi
movl %r8d, -0x44(%rbp)
jmp 0xdaf81
movl -0x30(%rbp), %r8d
imull -0x38(%rbp), %r8d
movl $0x4, %edi
movl %r8d, -0x40(%rbp)
jmp 0xdb08b
incl %edi
movq $0x0, -0x38(%rbp)
jmp 0xdaf81
cmpl $0x4, %edi
jne 0xdaf02
incl %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x9230
testq %rax, %rax
je 0xdb108
movq %rax, %rdi
leaq -0xd0(%rbp), %rsi
movq %rax, -0x30(%rbp)
callq 0x9340
leaq 0x13d721(%rip), %rdx    # 0x2187f0
movslq (%rdx), %rax
leaq (%rax,%rax,2), %rcx
movl -0x44(%rbp), %esi
movl %esi, (%r13,%rcx,8)
movl -0x3c(%rbp), %esi
movl %esi, 0x4(%r13,%rcx,8)
movl -0x40(%rbp), %esi
movl %esi, 0x8(%r13,%rcx,8)
movq -0x30(%rbp), %rsi
movq %rsi, 0x10(%r13,%rcx,8)
leal 0x1(%rax), %ecx
movl %ecx, (%rdx)
cmpq $0x16d, %rax            # imm = 0x16D
jl 0xdaf02
movq %rbx, %rdi
callq 0x9370
callq 0xe5130
callq 0xe4a1f
xorl %eax, %eax
jmp 0xdb123
movl $0x1, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq