// File: /workspace/github_c_makefile_star2_O0/mmayer[P]pcal/src/moonphas.c
// Function: calc_phase
double calc_phase (int month, int inday, int year)
{
   double Day, N, M, Ec, Lambdasun, ml, MM;
   double Ev, Ae, A3, MmP, mEc, A4, lP, V, lPP, MoonAge, pdate, moon_phase;
   static int first = TRUE;
   static double utc_offset_days;

   /* Get the UTC offset on the first pass. 

      The original code used to normalize the UTC offset to +/- 12 hours.  But
      it was bug-ridden and also failed to take into account that some parts
      of the world have offsets from UTC greater than 12 hours!  Therefore,
      beginning with v2.0.0, we don't attempt to normalize the user-specified
      UTC timezone offset at all.
   */
   if (first) {
      
      utc_offset_days = atof(time_zone) / 24.0;
      
      if (DEBUG(DEBUG_MOON)) {
         fprintf(stderr, "time_zone='%s'  utc_offset_days = %.5lf\n", time_zone, utc_offset_days);
      }
      
      first = FALSE;
   }
   
   /*  need to convert month, day, year into a Julian pdate */
   pdate = julday(month, inday, year) + utc_offset_days;
   
   /*  Calculation of the Sun's position. */
   
   Day = pdate - epoch;   /* date within epoch */
   N = fixangle((360 / 365.2422) * Day);   /* mean anomaly of the Sun */
   M = fixangle(N + elonge - elongp);      /* convert from perigee
                                              co-ordinates to epoch 1980.0 */
   Ec = kepler(M, eccent);   /* solve equation of Kepler */
   Ec = sqrt((1 + eccent) / (1 - eccent)) * tan(Ec / 2);
   Ec = 2 * todeg(atan(Ec));   /* true anomaly */
   Lambdasun = fixangle(Ec + elongp);   /* Sun's geocentric ecliptic longitude */
   
   /*  Calculation of the Moon's position. */
   
   /*  Moon's mean longitude. */
   ml = fixangle(13.1763966 * Day + mmlong);
   
   /*  Moon's mean anomaly. */
   MM = fixangle(ml - 0.1114041 * Day - mmlongp);
   
   /*  Moon's ascending node mean longitude. */
   /*  Not used -- commented out. */
   /* MN = fixangle(mlnode - 0.0529539 * Day); */
   
   /*  Evection. */
   Ev = 1.2739 * sin(torad(2 * (ml - Lambdasun) - MM));
   
   /*  Annual equation. */
   Ae = 0.1858 * sin(torad(M));
   
   /*  Correction term. */
   A3 = 0.37 * sin(torad(M));
   
   /*  Corrected anomaly. */
   MmP = MM + Ev - Ae - A3;
   
   /*  Correction for the equation of the centre. */
   mEc = 6.2886 * sin(torad(MmP));
   
   /*  Another correction term. */
   A4 = 0.214 * sin(torad(2 * MmP));
   
   /*  Corrected longitude. */
   lP = ml + Ev + mEc - Ae + A4;
   
   /*  Variation. */
   V = 0.6583 * sin(torad(2 * (lP - Lambdasun)));
   
   /*  True longitude. */
   lPP = lP + V;
   
   /*  Calculation of the phase of the Moon. */
   
   /*  Age of the Moon in degrees. */
   MoonAge = lPP - Lambdasun;
   
   moon_phase = fixangle(MoonAge) / 360.0;
   if (moon_phase < 0.0) moon_phase += 1.0;

   /* fprintf(stderr, "Moon phase on %04d-%02d-%02d: %.5lf\n", year, month, inday, moon_phase); */

   return (moon_phase);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
cmpl $0x0, 0x254f5(%rip)     # 0x2fba0
je 0xa70f
leaq 0x23eec(%rip), %rdi     # 0x2e5a0
callq 0x50a0
movsd 0x19e2f(%rip), %xmm1    # 0x244f0
divsd %xmm1, %xmm0
movsd %xmm0, 0x28fa3(%rip)    # 0x33670
leaq 0x28088(%rip), %rax     # 0x3275c
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xa705
movq 0x23913(%rip), %rax     # 0x2dff8
movq (%rax), %rdi
movsd 0x28f80(%rip), %xmm0    # 0x33670
leaq 0x19f09(%rip), %rsi     # 0x24600
leaq 0x23ea2(%rip), %rdx     # 0x2e5a0
movb $0x1, %al
callq 0x51b0
movl $0x0, 0x25491(%rip)     # 0x2fba0
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0xac00
addsd 0x28f4b(%rip), %xmm0    # 0x33670
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd 0x19e5b(%rip), %xmm1    # 0x24598
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd 0x19e35(%rip), %xmm0    # 0x24590
mulsd -0x18(%rbp), %xmm0
movsd 0x19d90(%rip), %xmm1    # 0x244f8
divsd %xmm1, %xmm0
callq 0x5270
movaps %xmm0, %xmm2
movsd -0xe0(%rbp), %xmm0
movsd 0x19d74(%rip), %xmm1    # 0x244f8
mulsd %xmm2, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x19de9(%rip), %xmm2    # 0x24590
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd 0x19dcc(%rip), %xmm0    # 0x24588
addsd -0x20(%rbp), %xmm0
movsd 0x19d9f(%rip), %xmm1    # 0x24568
subsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd 0x19dab(%rip), %xmm0    # 0x24588
addsd -0x20(%rbp), %xmm0
movsd 0x19d7e(%rip), %xmm1    # 0x24568
subsd %xmm1, %xmm0
movsd 0x19d02(%rip), %xmm1    # 0x244f8
divsd %xmm1, %xmm0
callq 0x5270
movsd -0xd8(%rbp), %xmm1
movsd 0x19cf1(%rip), %xmm2    # 0x24500
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x19d57(%rip), %xmm1    # 0x24580
callq 0xae80
movsd %xmm0, -0x30(%rbp)
movsd 0x19d3d(%rip), %xmm0    # 0x24578
callq 0x52c0
movsd %xmm0, -0xd0(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0x19cc3(%rip), %xmm1    # 0x24518
divsd %xmm1, %xmm0
callq 0x5200
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x50b0
movaps %xmm0, %xmm1
movsd 0x19ce9(%rip), %xmm0    # 0x24570
mulsd %xmm0, %xmm1
movsd 0x19c85(%rip), %xmm0    # 0x24518
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x19cc4(%rip), %xmm0    # 0x24568
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd 0x19caf(%rip), %xmm0    # 0x24568
addsd -0x30(%rbp), %xmm0
movsd 0x19c32(%rip), %xmm1    # 0x244f8
divsd %xmm1, %xmm0
callq 0x5270
movsd -0xc8(%rbp), %xmm1
movsd 0x19c21(%rip), %xmm2    # 0x24500
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x19c5f(%rip), %xmm1    # 0x24558
mulsd %xmm1, %xmm0
movsd 0x19c5b(%rip), %xmm1    # 0x24560
addsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x19c3a(%rip), %xmm1    # 0x24558
mulsd %xmm1, %xmm0
movsd 0x19c36(%rip), %xmm1    # 0x24560
addsd %xmm1, %xmm0
movsd 0x19bc2(%rip), %xmm1    # 0x244f8
divsd %xmm1, %xmm0
callq 0x5270
movsd -0xc0(%rbp), %xmm1
movsd 0x19bb1(%rip), %xmm2    # 0x24500
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
movsd 0x19be2(%rip), %xmm2    # 0x24550
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x19bca(%rip), %xmm1    # 0x24548
subsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x40(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
movsd 0x19bb4(%rip), %xmm2    # 0x24550
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x19b9c(%rip), %xmm1    # 0x24548
subsd %xmm1, %xmm0
movsd 0x19b40(%rip), %xmm1    # 0x244f8
divsd %xmm1, %xmm0
callq 0x5270
movsd -0xb8(%rbp), %xmm1
movsd 0x19b2f(%rip), %xmm2    # 0x24500
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
subsd -0x38(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0x19afc(%rip), %xmm1    # 0x24510
mulsd %xmm1, %xmm0
callq 0x5260
movaps %xmm0, %xmm1
movsd 0x19b18(%rip), %xmm0    # 0x24540
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x19ad7(%rip), %xmm0    # 0x24510
mulsd -0x28(%rbp), %xmm0
callq 0x5260
movaps %xmm0, %xmm1
movsd 0x19aea(%rip), %xmm0    # 0x24538
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x19ab1(%rip), %xmm0    # 0x24510
mulsd -0x28(%rbp), %xmm0
callq 0x5260
movaps %xmm0, %xmm1
movsd 0x19abc(%rip), %xmm0    # 0x24530
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x48(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
subsd -0x58(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x19a72(%rip), %xmm0    # 0x24510
mulsd -0x68(%rbp), %xmm0
callq 0x5260
movaps %xmm0, %xmm1
movsd 0x19a75(%rip), %xmm0    # 0x24528
mulsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x19a54(%rip), %xmm0    # 0x24518
mulsd -0x68(%rbp), %xmm0
movsd 0x19a3f(%rip), %xmm1    # 0x24510
mulsd %xmm1, %xmm0
callq 0x5260
movaps %xmm0, %xmm1
movsd 0x19a3b(%rip), %xmm0    # 0x24520
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
subsd -0x58(%rbp), %xmm0
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm1
subsd -0x38(%rbp), %xmm1
movsd 0x199fa(%rip), %xmm0    # 0x24518
mulsd %xmm1, %xmm0
movsd 0x199e6(%rip), %xmm1    # 0x24510
mulsd %xmm1, %xmm0
callq 0x5260
movaps %xmm0, %xmm1
movsd 0x199ca(%rip), %xmm0    # 0x24508
mulsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x80(%rbp), %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
subsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x98(%rbp), %xmm0
movsd 0x19964(%rip), %xmm1    # 0x244f8
divsd %xmm1, %xmm0
callq 0x5270
movsd -0xb0(%rbp), %xmm1
movsd 0x19953(%rip), %xmm2    # 0x24500
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x1993b(%rip), %xmm1    # 0x244f8
divsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0xa8(%rbp), %xmm0
jbe 0xabee
movsd 0x1042a(%rip), %xmm0    # 0x1b008
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
addq $0xe0, %rsp
popq %rbp
retq
nop