// File: /workspace/github_cpp_makefile_star2_O2/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 0x2a32c0(%rip), %rax    # 0x2f6fd0
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x53d40
jp 0x53d40
leaq 0x2a32b1(%rip), %rax    # 0x2f6fd8
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jne 0x53d40
jp 0x53d40
leaq 0x2a3ada(%rip), %rax    # 0x2f7814
andl $0x0, (%rax)
xorl %eax, %eax
retq
leaq 0x2a3a71(%rip), %rax    # 0x2f77b8
movsd (%rax), %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
jbe 0x53e54
leaq 0x2a3a92(%rip), %rcx    # 0x2f77f0
movsd (%rcx), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jbe 0x53e54
subsd %xmm1, %xmm0
movapd 0x9f414(%rip), %xmm1    # 0xf3190
andpd %xmm0, %xmm1
ucomisd 0xb4430(%rip), %xmm1    # 0x1081b8
ja 0x53db6
leaq 0x2a3a3f(%rip), %rcx    # 0x2f77d0
movsd (%rcx), %xmm1
leaq 0x2a3a4c(%rip), %rcx    # 0x2f77e8
subsd (%rcx), %xmm1
movapd 0x9f3e8(%rip), %xmm2    # 0xf3190
andpd %xmm1, %xmm2
ucomisd 0xb4404(%rip), %xmm2    # 0x1081b8
jbe 0x53dc1
leaq 0x2a3a57(%rip), %rcx    # 0x2f7814
andl $0x0, (%rcx)
retq
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq 0x2a3a4a(%rip), %rbx    # 0x2f7818
movl (%rbx), %eax
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm0
leaq 0x2a3a41(%rip), %rcx    # 0x2f7828
movsd (%rcx), %xmm1
leaq 0x2a3a2e(%rip), %rdx    # 0x2f7820
movsd %xmm1, (%rdx)
leaq 0x2a3a33(%rip), %rdx    # 0x2f7830
movsd (%rdx), %xmm1
movsd %xmm1, (%rcx)
movsd %xmm0, (%rdx)
testl %eax, %eax
jns 0x53e39
movups 0xbc69e(%rip), %xmm0    # 0x1104b2
leaq 0x1d3b45(%rip), %rax    # 0x227960
movups %xmm0, 0xd(%rax)
movupd 0xbc67e(%rip), %xmm0    # 0x1104a5
movapd %xmm0, (%rax)
pushq $0x1
popq %rdi
callq 0xc0b76
movl $0x1, (%rbx)
leaq 0x2a39d4(%rip), %rcx    # 0x2f7814
pushq $0x1
popq %rax
movl %eax, (%rcx)
leaq 0x2a39c4(%rip), %rcx    # 0x2f7810
movl %eax, (%rcx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq