// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: moon_info(double)
double moon_info(double jd)
{
double Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
       mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon, BetaM, F;
double MoonDFrac;
double mage2;
double eccent;


    // calculate moon info based upon John Walker's moontool.c

    /* Calculation of the Sun's position */
    ++sp_count;

    MoonSynod = synmonth;
    eccent = orbit_eccentricity(jd);

    Day = jd - MOON_EPOCH;                  /* Date within epoch */
//  N = fixangle((360.0 / 365.2422) * Day);       /* Mean anomaly of the Sun */
    N = fixangle((360.0 / solar_year(jd)) * 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.0 + eccent) / (1.0 - eccent)) * tan(Ec / 2.0);
    Ec = 2.0 * todeg(atan(Ec));               /* True anomaly */
    Lambdasun = fixangle(Ec + elongp);      /* Sun's geocentric ecliptic longitude */

    /* Orbital distance factor */
    F = ((1 + eccent * cos(torad(Ec))) / (1.0 - eccent * eccent));
    if(F == 0.0) F = 1.0;
    SunDist = sunsmax / F;                  /* Distance to Sun in km */
    SunDisk = F * sunangsiz;                /* Sun's angular size in degrees */

    /* 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 */
    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;

    /* Corrected longitude of the node */
    NP = MN - 0.16 * sin(torad(M));

    /* Y inclination coordinate */
    y = sin(torad(lPP - NP)) * cos(torad(minc));

    /* X inclination coordinate */
    x = cos(torad(lPP - NP));

    /* Ecliptic longitude */
    Lambdamoon = todeg(atan2(y, x));
    Lambdamoon += NP;

    /* Ecliptic latitude */
    BetaM = todeg(asin(sin(torad(lPP - NP)) * sin(torad(minc))));

    /* Calculation of the phase of the Moon */

    /* Age of the Moon in degrees */
    MoonAge = lPP - Lambdasun;

    /* Phase of the Moon */
    MoonPhase = (1.0 - cos(torad(MoonAge))) / 2.0;

    /* Calculate distance of moon from the centre of the Earth */

    MoonDist = (msmax * (1 - mecc * mecc)) /
               (1.0 + mecc * cos(torad(MmP + mEc)));

    /* Calculate Moon's angular diameter */

    MoonDFrac = MoonDist / msmax;
    if(MoonDFrac == 0.0) MoonDFrac = 1.0;
    MoonDisk = mangsiz / MoonDFrac;

    /* Calculate Moon's parallax */

    MoonPar = mparallax / MoonDFrac;

    mage2 = fixangle(MoonAge) / 360.0;
    MoonAge = synmonth * (fixangle(MoonAge) / 360.0);

    lunation = (long) floor(((new_moon_jd + 7.0) - lunatbase) / synmonth) + 1;

//gregorian(0, new_moon_jd);
//sprintf(plot_title, "new moon: %04d/%02d/%02d  %02d:%02d:%02d", g_year,g_month,g_day, g_hours,g_minutes,g_seconds);

// sprintf(debug_text2, "phasex:%f  sdiam:%f  sdist:%f  synod:%f  luna:%ld", moon_phase(jd), sun_diam(jd), earth_sun_dist(jd), synmonth, lunation);
///sprintf(debug_text, "phase:%f mage:%f %f  mdist:%f mang:%f sdist:%f sang:%f",
///MoonPhase, MoonAge,mage2, MoonDist,MoonDisk, SunDist,SunDisk);
    return MoonPhase;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movsd %xmm0, -0x8(%rbp)
movl 0x29eece(%rip), %eax    # 0x3d97f4
addl $0x1, %eax
movl %eax, 0x29eec5(%rip)    # 0x3d97f4
leaq 0x2320f2(%rip), %rax    # 0x36ca28
movsd 0x53e92(%rip), %xmm0    # 0x18e7d0
movsd %xmm0, (%rax)
movsd -0x8(%rbp), %xmm0
callq 0x134200
movsd %xmm0, -0xd8(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x53de7(%rip), %xmm1    # 0x18e748
subsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x8(%rbp), %xmm0
callq 0x134310
movaps %xmm0, %xmm1
movsd 0x481b1(%rip), %xmm0    # 0x182b30
divsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x108(%rbp)
movsd -0x8(%rbp), %xmm0
callq 0x134310
movaps %xmm0, %xmm1
movsd 0x48183(%rip), %xmm0    # 0x182b30
divsd %xmm1, %xmm0
mulsd -0x10(%rbp), %xmm0
movsd 0x48172(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movsd -0x108(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0x100(%rbp), %xmm0
movsd 0x4814e(%rip), %xmm1    # 0x182b30
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd 0x53c06(%rip), %xmm0    # 0x18e618
addsd -0x18(%rbp), %xmm0
movsd 0x53bf1(%rip), %xmm1    # 0x18e610
subsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd 0x53be5(%rip), %xmm0    # 0x18e618
addsd -0x18(%rbp), %xmm0
movsd 0x53bd0(%rip), %xmm1    # 0x18e610
subsd %xmm1, %xmm0
movsd 0x480e4(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movsd -0xf8(%rbp), %xmm1
movsd 0x53cd3(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm1
callq 0x13b2b0
movsd %xmm0, -0x28(%rbp)
movsd 0x345d7(%rip), %xmm0    # 0x16f068
addsd -0xd8(%rbp), %xmm0
movsd 0x345c7(%rip), %xmm1    # 0x16f068
subsd -0xd8(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x9280
movsd %xmm0, -0xf0(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x34689(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
callq 0x91b0
movaps %xmm0, %xmm1
movsd -0xf0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x92e0
movaps %xmm0, %xmm1
movsd 0x34687(%rip), %xmm0    # 0x16f180
mulsd %xmm0, %xmm1
movsd 0x3464b(%rip), %xmm0    # 0x16f150
mulsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x53afa(%rip), %xmm0    # 0x18e610
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movsd 0x53ae5(%rip), %xmm0    # 0x18e610
addsd -0x28(%rbp), %xmm0
movsd 0x47ff8(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movsd -0xe8(%rbp), %xmm1
movsd 0x53be7(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd 0x36b1a(%rip), %xmm0    # 0x171690
mulsd -0x28(%rbp), %xmm0
callq 0x96f0
movaps %xmm0, %xmm1
movsd -0xe0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x344d1(%rip), %xmm1    # 0x16f068
addsd %xmm1, %xmm0
movsd -0xd8(%rbp), %xmm1
movsd -0xd8(%rbp), %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
movsd 0x3449a(%rip), %xmm2    # 0x16f068
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xc0(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13ac01
jp 0x13ac01
movsd 0x3446f(%rip), %xmm0    # 0x16f068
movsd %xmm0, -0xc0(%rbp)
movsd 0x53c1f(%rip), %xmm0    # 0x18e828
divsd -0xc0(%rbp), %xmm0
leaq 0x231e38(%rip), %rax    # 0x36ca50
movsd %xmm0, (%rax)
movsd 0x53bfc(%rip), %xmm0    # 0x18e820
mulsd -0xc0(%rbp), %xmm0
leaq 0x231e15(%rip), %rax    # 0x36ca48
movsd %xmm0, (%rax)
movsd -0x10(%rbp), %xmm0
movsd 0x53bd4(%rip), %xmm1    # 0x18e818
mulsd %xmm1, %xmm0
movsd 0x53b20(%rip), %xmm1    # 0x18e770
addsd %xmm1, %xmm0
movsd %xmm0, -0x138(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x53baf(%rip), %xmm1    # 0x18e818
mulsd %xmm1, %xmm0
movsd 0x53afb(%rip), %xmm1    # 0x18e770
addsd %xmm1, %xmm0
movsd 0x47eaf(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movsd -0x138(%rbp), %xmm1
movsd 0x53a9e(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm1
movsd -0x10(%rbp), %xmm0
movsd 0x53b07(%rip), %xmm2    # 0x18e7c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x53aef(%rip), %xmm1    # 0x18e7b8
subsd %xmm1, %xmm0
movsd %xmm0, -0x130(%rbp)
movsd -0x38(%rbp), %xmm1
movsd -0x10(%rbp), %xmm0
movsd 0x53ad9(%rip), %xmm2    # 0x18e7c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x53ac1(%rip), %xmm1    # 0x18e7b8
subsd %xmm1, %xmm0
movsd 0x47e2d(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movsd -0x130(%rbp), %xmm1
movsd 0x53a1c(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x53a72(%rip), %xmm1    # 0x18e7a8
mulsd %xmm1, %xmm0
movsd 0x53a6e(%rip), %xmm1    # 0x18e7b0
addsd %xmm1, %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x53a4d(%rip), %xmm1    # 0x18e7a8
mulsd %xmm1, %xmm0
movsd 0x53a49(%rip), %xmm1    # 0x18e7b0
addsd %xmm1, %xmm0
movsd 0x47dbd(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movsd -0x128(%rbp), %xmm1
movsd 0x539ac(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd 0x368c1(%rip), %xmm1    # 0x171690
mulsd %xmm1, %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd 0x539bd(%rip), %xmm0    # 0x18e7a0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x3689c(%rip), %xmm0    # 0x171690
mulsd -0x20(%rbp), %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd 0x5398f(%rip), %xmm0    # 0x18e798
mulsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x36876(%rip), %xmm0    # 0x171690
mulsd -0x20(%rbp), %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd 0x539e1(%rip), %xmm0    # 0x18e810
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
subsd -0x58(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x36837(%rip), %xmm0    # 0x171690
mulsd -0x68(%rbp), %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd 0x5391a(%rip), %xmm0    # 0x18e788
mulsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x342d1(%rip), %xmm0    # 0x16f150
mulsd -0x68(%rbp), %xmm0
movsd 0x36804(%rip), %xmm1    # 0x171690
mulsd %xmm1, %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd 0x538e0(%rip), %xmm0    # 0x18e780
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x38(%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 -0x30(%rbp), %xmm1
movsd 0x34277(%rip), %xmm0    # 0x16f150
mulsd %xmm1, %xmm0
movsd 0x367ab(%rip), %xmm1    # 0x171690
mulsd %xmm1, %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd 0x5387f(%rip), %xmm0    # 0x18e778
mulsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x80(%rbp), %xmm0
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
movsd 0x36761(%rip), %xmm0    # 0x171690
mulsd -0x20(%rbp), %xmm0
callq 0x9080
movsd -0x120(%rbp), %xmm1
movsd 0x538bf(%rip), %xmm2    # 0x18e808
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x90(%rbp), %xmm0
subsd -0x98(%rbp), %xmm0
movsd 0x3671f(%rip), %xmm1    # 0x171690
mulsd %xmm1, %xmm0
callq 0x9080
movsd %xmm0, -0x118(%rbp)
movsd 0x53876(%rip), %xmm0    # 0x18e800
callq 0x96f0
movaps %xmm0, %xmm1
movsd -0x118(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x90(%rbp), %xmm0
subsd -0x98(%rbp), %xmm0
movsd 0x366d2(%rip), %xmm1    # 0x171690
mulsd %xmm1, %xmm0
callq 0x96f0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
callq 0x9050
movsd 0x34194(%rip), %xmm1    # 0x16f180
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x98(%rbp), %xmm0
addsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x90(%rbp), %xmm0
subsd -0x98(%rbp), %xmm0
movsd 0x36668(%rip), %xmm1    # 0x171690
mulsd %xmm1, %xmm0
callq 0x9080
movsd %xmm0, -0x110(%rbp)
movsd 0x537bf(%rip), %xmm0    # 0x18e800
callq 0x9080
movaps %xmm0, %xmm1
movsd -0x110(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x9640
movsd 0x3411e(%rip), %xmm1    # 0x16f180
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x90(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
leaq 0x231996(%rip), %rax    # 0x36ca18
movsd %xmm0, (%rax)
movsd 0x36602(%rip), %xmm0    # 0x171690
leaq 0x231983(%rip), %rax    # 0x36ca18
mulsd (%rax), %xmm0
callq 0x96f0
movaps %xmm0, %xmm1
movsd 0x33fbf(%rip), %xmm0    # 0x16f068
subsd %xmm1, %xmm0
movsd 0x3409b(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
leaq 0x231960(%rip), %rax    # 0x36ca20
movsd %xmm0, (%rax)
movsd -0x68(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd 0x365ba(%rip), %xmm1    # 0x171690
mulsd %xmm1, %xmm0
callq 0x96f0
movaps %xmm0, %xmm1
movsd 0x5370e(%rip), %xmm0    # 0x18e7f8
mulsd %xmm0, %xmm1
movsd 0x33f72(%rip), %xmm0    # 0x16f068
addsd %xmm0, %xmm1
movsd 0x536ee(%rip), %xmm0    # 0x18e7f0
divsd %xmm1, %xmm0
leaq 0x231923(%rip), %rax    # 0x36ca30
movsd %xmm0, (%rax)
leaq 0x231918(%rip), %rax    # 0x36ca30
movsd (%rax), %xmm0
movsd 0x536c4(%rip), %xmm1    # 0x18e7e8
divsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xc8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13b153
jp 0x13b153
movsd 0x33f1d(%rip), %xmm0    # 0x16f068
movsd %xmm0, -0xc8(%rbp)
movsd 0x536dd(%rip), %xmm0    # 0x18e838
divsd -0xc8(%rbp), %xmm0
leaq 0x2318ce(%rip), %rax    # 0x36ca38
movsd %xmm0, (%rax)
movsd 0x536ba(%rip), %xmm0    # 0x18e830
divsd -0xc8(%rbp), %xmm0
leaq 0x2318bb(%rip), %rax    # 0x36ca40
movsd %xmm0, (%rax)
leaq 0x231888(%rip), %rax    # 0x36ca18
movsd (%rax), %xmm0
movsd %xmm0, -0x148(%rbp)
leaq 0x231875(%rip), %rax    # 0x36ca18
movsd (%rax), %xmm0
movsd 0x47981(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movsd -0x148(%rbp), %xmm1
movsd 0x53570(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x47958(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
leaq 0x23182d(%rip), %rax    # 0x36ca18
movsd (%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
leaq 0x23181a(%rip), %rax    # 0x36ca18
movsd (%rax), %xmm0
movsd 0x47926(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
callq 0x9660
movaps %xmm0, %xmm1
movsd -0x140(%rbp), %xmm0
movsd 0x53512(%rip), %xmm2    # 0x18e738
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x478fa(%rip), %xmm0    # 0x182b30
divsd %xmm0, %xmm1
movsd 0x5358e(%rip), %xmm0    # 0x18e7d0
mulsd %xmm1, %xmm0
leaq 0x2317cb(%rip), %rax    # 0x36ca18
movsd %xmm0, (%rax)
movsd 0x3642f(%rip), %xmm0    # 0x171688
leaq 0x231718(%rip), %rax    # 0x36c978
addsd (%rax), %xmm0
movsd 0x5356c(%rip), %xmm1    # 0x18e7d8
subsd %xmm1, %xmm0
movsd 0x53558(%rip), %xmm1    # 0x18e7d0
divsd %xmm1, %xmm0
callq 0x9660
cvttsd2si %xmm0, %rcx
addq $0x1, %rcx
leaq 0x2317c7(%rip), %rax    # 0x36ca58
movq %rcx, (%rax)
leaq 0x231785(%rip), %rax    # 0x36ca20
movsd (%rax), %xmm0
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopl (%rax,%rax)