// File: /workspace/github_cpp_makefile_star2_O1/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:
leaq 0x2b209a(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x5af69
jp 0x5af69
leaq 0x2b208b(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5af69
jp 0x5af69
leaq 0x2b28b4(%rip), %rax    # 0x30d814
movl $0x0, (%rax)
xorl %eax, %eax
retq
leaq 0x2b2848(%rip), %rax    # 0x30d7b8
movsd (%rax), %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
jbe 0x5b096
leaq 0x2b2869(%rip), %rcx    # 0x30d7f0
movsd (%rcx), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x5b096
subsd %xmm0, %xmm1
movapd 0xae1db(%rip), %xmm0    # 0x109180
andpd %xmm1, %xmm0
ucomisd 0xc30e7(%rip), %xmm0    # 0x11e098
ja 0x5afdf
leaq 0x2b2816(%rip), %rcx    # 0x30d7d0
movsd (%rcx), %xmm0
leaq 0x2b2823(%rip), %rcx    # 0x30d7e8
subsd (%rcx), %xmm0
movapd 0xae1af(%rip), %xmm2    # 0x109180
andpd %xmm0, %xmm2
ucomisd 0xc30bb(%rip), %xmm2    # 0x11e098
jbe 0x5afed
leaq 0x2b282e(%rip), %rcx    # 0x30d814
movl $0x0, (%rcx)
retq
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
leaq 0x2b281d(%rip), %rbx    # 0x30d818
movl (%rbx), %r14d
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x5b01a
sqrtsd %xmm0, %xmm0
jmp 0x5b01f
callq 0x9270
leaq 0x2b2802(%rip), %rax    # 0x30d828
movsd (%rax), %xmm1
leaq 0x2b27ef(%rip), %rcx    # 0x30d820
movsd %xmm1, (%rcx)
leaq 0x2b27f4(%rip), %rcx    # 0x30d830
movsd (%rcx), %xmm1
movsd %xmm1, (%rax)
movsd %xmm0, (%rcx)
testl %r14d, %r14d
jns 0x5b07b
movups 0xcb439(%rip), %xmm0    # 0x12648d
leaq 0x1e2905(%rip), %rax    # 0x23d960
movups %xmm0, 0xd(%rax)
movupd 0xcb419(%rip), %xmm0    # 0x126480
movapd %xmm0, (%rax)
movl $0x1, %edi
callq 0xd1d97
movl $0x1, (%rbx)
leaq 0x2b2792(%rip), %rcx    # 0x30d814
movl $0x1, %eax
movl %eax, (%rcx)
leaq 0x2b2780(%rip), %rcx    # 0x30d810
movl %eax, (%rcx)
popq %rbx
popq %r14
popq %rbp
retq