// File: jkingan[P]ladyheather/heathgps.cpp
// Function: eclipse()
int eclipse()
{
double el;
double dist;
int flag;

   // returns 1 if possible solar eclipse
   // returns 2 if possible lunar eclipse
   // return 0 if no eclipse
   if((lat == 0.0) && (lon == 0.0)) {
      eclipse_flag = 0;
      return 0;
   }

   flag = last_eclipse;
// last_eclipse = eclipse_flag;
   if((sun_el > 0.0) && (moon_el > 0.0)) {  // sun and moon are up
      if(fabs(sun_el - moon_el) > ECLIPSE) {  // elevation difference too bih
         eclipse_flag = 0;
         return 0;
      }
      if(fabs(sun_az - moon_az) > ECLIPSE) {  // azimuth difference too big
         eclipse_flag = 0;
         return 0;
      }

      dist = (sun_el - moon_el) * (sun_el - moon_el);     // used to calculate closest sun/moon point
      dist += ((sun_az - moon_az) * (sun_az - moon_az));
      dist = sqrt(dist);

      eclipse_d1 = eclipse_d2;
      eclipse_d2 = eclipse_d3;
      eclipse_d3 = dist;
//if(log_file) fprintf(log_file, "dist:%.10f  d1:%.10f d2:%.10f d3:%.10f\n", dist, eclipse_d1,eclipse_d2,eclipse_d3);
//if(log_file) fprintf(log_file, "dist:%.10f  az:%g  el:%g \n", dist, sun_az-moon_az,  sun_el-moon_el);

      if(flag < 0) {   // program started up during an eclipse condition
         sprintf(log_text, "#! solar eclipse in progress");
         write_log_tow(1);
         last_eclipse = 1;
      }
      eclipse_flag = 1;
      eclipsed = 1;
      return 1;
   }
   return 0;  // note: lunar code needs work... so we skip it for now

   if(1 || ((moon_el > 0.0) && (sun_el < 0.0))) {  // moon up, sun set
//    el = fabs(sun_el); // fabs(sun_el);
//    if(fabs(el - moon_el) > ECLIPSE) return 0;
//    return 2;

      el = fabs(sun_el) - fabs(moon_el);
      el = fabs(el);
      if(el > ECLIPSE) {
         eclipse_flag = 0;
         return 0;
      }

      el = fabs(sun_az - moon_az) - 180.0;
      if(fabs(el) > ECLIPSE) {
         eclipse_flag = 0;
         return 0;
      }

      if(flag < 0) {
         sprintf(log_text, "#! lunar eclipse in progress");
         write_log_tow(1);
         last_eclipse = 2;
      }
      eclipse_flag = 2;
      return 2;
   }

   eclipse_flag = 0;
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
leaq 0x2ee951(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x7d89d
jp 0x7d89d
leaq 0x2ee943(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x7d89d
jp 0x7d89d
leaq 0x2ef169(%rip), %rax    # 0x36c9f4
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x7da83
leaq 0x2ef154(%rip), %rax    # 0x36c9f8
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
leaq 0x2ef0e8(%rip), %rax    # 0x36c998
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x7da7c
leaq 0x2ef108(%rip), %rax    # 0x36c9d0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x7da7c
leaq 0x2ef0b8(%rip), %rax    # 0x36c998
movsd (%rax), %xmm0
leaq 0x2ef0e5(%rip), %rax    # 0x36c9d0
subsd (%rax), %xmm0
movaps 0xf199a(%rip), %xmm1    # 0x16f290
pand %xmm1, %xmm0
movsd 0x105236(%rip), %xmm1   # 0x182b38
ucomisd %xmm1, %xmm0
jbe 0x7d921
leaq 0x2ef0e5(%rip), %rax    # 0x36c9f4
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x7da83
leaq 0x2ef088(%rip), %rax    # 0x36c9b0
movsd (%rax), %xmm0
leaq 0x2ef095(%rip), %rax    # 0x36c9c8
subsd (%rax), %xmm0
movaps 0xf1952(%rip), %xmm1    # 0x16f290
pand %xmm1, %xmm0
movsd 0x1051ee(%rip), %xmm1   # 0x182b38
ucomisd %xmm1, %xmm0
jbe 0x7d969
leaq 0x2ef09d(%rip), %rax    # 0x36c9f4
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x7da83
leaq 0x2ef028(%rip), %rax    # 0x36c998
movsd (%rax), %xmm0
leaq 0x2ef055(%rip), %rax    # 0x36c9d0
subsd (%rax), %xmm0
leaq 0x2ef012(%rip), %rax    # 0x36c998
movsd (%rax), %xmm1
leaq 0x2ef03f(%rip), %rax    # 0x36c9d0
subsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0x2ef00b(%rip), %rax    # 0x36c9b0
movsd (%rax), %xmm0
leaq 0x2ef018(%rip), %rax    # 0x36c9c8
subsd (%rax), %xmm0
leaq 0x2eeff5(%rip), %rax    # 0x36c9b0
movsd (%rax), %xmm2
leaq 0x2ef002(%rip), %rax    # 0x36c9c8
subsd (%rax), %xmm2
movsd -0x18(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
callq 0x9280
movsd %xmm0, -0x18(%rbp)
leaq 0x2ef016(%rip), %rax    # 0x36ca08
movsd (%rax), %xmm0
leaq 0x2ef003(%rip), %rax    # 0x36ca00
movsd %xmm0, (%rax)
leaq 0x2ef008(%rip), %rax    # 0x36ca10
movsd (%rax), %xmm0
leaq 0x2eeff5(%rip), %rax    # 0x36ca08
movsd %xmm0, (%rax)
movsd -0x18(%rbp), %xmm0
leaq 0x2eefed(%rip), %rax    # 0x36ca10
movsd %xmm0, (%rax)
cmpl $0x0, -0x1c(%rbp)
jge 0x7da59
leaq 0x21f10c(%rip), %rdi    # 0x29cb40
leaq 0x10bebe(%rip), %rsi    # 0x1898f9
movb $0x0, %al
callq 0x9060
movl $0x1, %edi
callq 0x11f500
leaq 0x2eefa5(%rip), %rax    # 0x36c9f8
movl $0x1, (%rax)
leaq 0x2eef94(%rip), %rax    # 0x36c9f4
movl $0x1, (%rax)
leaq 0x2eef83(%rip), %rax    # 0x36c9f0
movl $0x1, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x7da83
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)