// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: interp_solar_noon(double, double, int)
double interp_solar_noon(double start, double end, int do_moon)
{
double start_el, mid_el, end_el;
double mid;
double pct, delta;

// return (start+end) / 2.0;

   if((lat > (0.0-PEAK_THRESH1)) && (lat < PEAK_THRESH1)) return (start+end)/2.0;
   else if(lat > PEAK_THRESH2) return (start+end)/2.0; 
   else if(lat < (0.0-PEAK_THRESH2)) return (start+end)/2.0; 

   start_el = sun_peak(start, do_moon);
   end_el = 360.0 - sun_peak(end, do_moon);
   delta = end_el - start_el;
   if(delta == 0.0) return (start+end) / 2.0;

   pct = (180.0 - start_el) / delta;
   mid = start + (end-start) * pct;


if(0 && debug_file) {
   mid_el = sun_peak(mid, do_moon);
   fprintf(debug_file, "\ninterp noon: start:%f mid:%f end:%f\n", start,mid,end);
   fprintf(debug_file, "start_el:%f mid_el:%f end_el:%f  pct:%f\n", start_el,mid_el,end_el, pct);
   gregorian(0, mid+time_zone());
   fprintf(debug_file, "noon (utc): %02d:%02d:%02d %f  %04d/%02d/%02d  tz:%f\n\n", g_hours,g_minutes,g_seconds,g_frac, g_year,g_month,g_day, time_zone());
}
   return mid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movl %edi, -0x1c(%rbp)
leaq 0x22e964(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
movsd 0x51130(%rip), %xmm1    # 0x18e988
ucomisd %xmm1, %xmm0
jbe 0x13d893
movsd 0x5112a(%rip), %xmm0    # 0x18e990
leaq 0x22e943(%rip), %rax    # 0x36c1b0
ucomisd (%rax), %xmm0
jbe 0x13d893
movsd -0x10(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd 0x318cb(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13d9b6
leaq 0x22e916(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
movsd 0x510f2(%rip), %xmm1    # 0x18e998
ucomisd %xmm1, %xmm0
jbe 0x13d8cc
movsd -0x10(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd 0x31892(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13d9b6
movsd 0x4585c(%rip), %xmm0    # 0x183130
leaq 0x22e8d5(%rip), %rax    # 0x36c1b0
ucomisd (%rax), %xmm0
jbe 0x13d901
movsd -0x10(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd 0x3185d(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13d9b6
jmp 0x13d903
jmp 0x13d905
movsd -0x10(%rbp), %xmm0
movl -0x1c(%rbp), %edi
callq 0x13cbf0
movsd %xmm0, -0x28(%rbp)
movsd -0x18(%rbp), %xmm0
movl -0x1c(%rbp), %edi
callq 0x13cbf0
movaps %xmm0, %xmm1
movsd 0x45201(%rip), %xmm0    # 0x182b30
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13d974
jp 0x13d974
movsd -0x10(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd 0x317e7(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x13d9b6
movsd 0x316fc(%rip), %xmm0    # 0x16f078
subsd -0x28(%rbp), %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x10(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
subsd -0x10(%rbp), %xmm0
movsd -0x48(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)