// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b2151(%rip), %rax    # 0x30cfd0
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5aeb2
jp 0x5aeb2
leaq 0x2b2142(%rip), %rax    # 0x30cfd8
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jne 0x5aeb2
jp 0x5aeb2
leaq 0x2b296b(%rip), %rax    # 0x30d814
movl $0x0, (%rax)
xorl %eax, %eax
retq
leaq 0x2b28ff(%rip), %rax    # 0x30d7b8
movsd (%rax), %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
jbe 0x5afd0
leaq 0x2b2920(%rip), %rcx    # 0x30d7f0
movsd (%rcx), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x5afd0
subsd %xmm1, %xmm0
movapd 0xae2a2(%rip), %xmm1    # 0x109190
andpd %xmm0, %xmm1
ucomisd 0xc3246(%rip), %xmm1    # 0x11e140
ja 0x5af28
leaq 0x2b28cd(%rip), %rcx    # 0x30d7d0
movsd (%rcx), %xmm1
leaq 0x2b28da(%rip), %rcx    # 0x30d7e8
subsd (%rcx), %xmm1
movapd 0xae276(%rip), %xmm2    # 0x109190
andpd %xmm1, %xmm2
ucomisd 0xc321a(%rip), %xmm2    # 0x11e140
jbe 0x5af36
leaq 0x2b28e5(%rip), %rcx    # 0x30d814
movl $0x0, (%rcx)
retq
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq 0x2b28d5(%rip), %rbx    # 0x30d818
movl (%rbx), %eax
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
leaq 0x2b28c9(%rip), %rcx    # 0x30d828
movsd (%rcx), %xmm1
leaq 0x2b28b6(%rip), %rdx    # 0x30d820
movsd %xmm1, (%rdx)
leaq 0x2b28bb(%rip), %rdx    # 0x30d830
movsd (%rdx), %xmm1
movsd %xmm1, (%rcx)
movsd %xmm0, (%rdx)
testl %eax, %eax
jns 0x5afb3
movups 0xcb5e1(%rip), %xmm0    # 0x12656d
leaq 0x1e29cd(%rip), %rax    # 0x23d960
movups %xmm0, 0xd(%rax)
movupd 0xcb5c1(%rip), %xmm0    # 0x126560
movapd %xmm0, (%rax)
movl $0x1, %edi
callq 0xd244c
movl $0x1, (%rbx)
leaq 0x2b285a(%rip), %rcx    # 0x30d814
movl $0x1, %eax
movl %eax, (%rcx)
leaq 0x2b2848(%rip), %rcx    # 0x30d810
movl %eax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq