// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r14
pushq %rbx
subq $0x60, %rsp
incl 0x291a88(%rip)          # 0x3645b4
movsd %xmm0, -0x18(%rbp)
leaq 0x224d10(%rip), %rax    # 0x2f7848
movabsq $0x403d87d4a8e43a52, %rcx # imm = 0x403D87D4A8E43A52
movq %rcx, (%rax)
callq 0xce799
movaps %xmm0, -0x60(%rbp)
movsd 0x4303a(%rip), %xmm1    # 0x115b90
movsd -0x18(%rbp), %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, -0x20(%rbp)
callq 0xce82b
movsd 0x3563f(%rip), %xmm1    # 0x1081b0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
mulsd -0x20(%rbp), %xmm2
movsd %xmm2, -0x18(%rbp)
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x9680
mulsd 0x42e70(%rip), %xmm0    # 0x115a08
addsd -0x18(%rbp), %xmm0
addsd 0x42e7b(%rip), %xmm0    # 0x115a20
addsd 0x42e6b(%rip), %xmm0    # 0x115a18
movsd %xmm0, -0x18(%rbp)
divsd 0x355f6(%rip), %xmm0    # 0x1081b0
callq 0x9680
movapd %xmm0, %xmm3
mulsd 0x42e3d(%rip), %xmm3    # 0x115a08
addsd -0x18(%rbp), %xmm3
mulsd 0x22db0(%rip), %xmm3    # 0xf5988
movapd 0x205d0(%rip), %xmm1    # 0xf31b0
xorpd -0x60(%rbp), %xmm1
movapd %xmm1, -0x40(%rbp)
pushq $0xb
popq %rbx
movsd %xmm3, -0x28(%rbp)
movsd %xmm3, -0x18(%rbp)
movapd %xmm3, %xmm0
callq 0x9080
mulsd -0x40(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movapd %xmm0, -0x50(%rbp)
movsd -0x18(%rbp), %xmm0
callq 0x9710
movapd -0x50(%rbp), %xmm2
movsd -0x18(%rbp), %xmm3
mulsd -0x40(%rbp), %xmm0
movsd 0x2043b(%rip), %xmm1    # 0xf3070
addsd %xmm1, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
subsd %xmm1, %xmm3
decl %ebx
je 0xd2c63
movapd %xmm2, %xmm0
xorpd 0x2055b(%rip), %xmm0    # 0xf31b0
maxsd %xmm2, %xmm0
ucomisd 0x3560f(%rip), %xmm0    # 0x108270
ja 0xd2bf2
movapd -0x60(%rbp), %xmm2
movapd %xmm2, %xmm0
movsd 0x203fc(%rip), %xmm1    # 0xf3070
addsd %xmm1, %xmm0
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xd2c90
sqrtsd %xmm0, %xmm0
jmp 0xd2c9f
movsd %xmm3, -0x18(%rbp)
callq 0x9260
movsd -0x18(%rbp), %xmm3
movsd %xmm0, -0x50(%rbp)
mulsd 0x203bc(%rip), %xmm3    # 0xf3068
movapd %xmm3, %xmm0
callq 0x91a0
mulsd -0x50(%rbp), %xmm0
callq 0x92c0
mulsd 0x20499(%rip), %xmm0    # 0xf3160
addsd %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x42ed8(%rip), %xmm1    # 0x115bb0
addsd %xmm0, %xmm1
movsd %xmm1, -0x18(%rbp)
movapd %xmm1, %xmm0
movsd 0x354c3(%rip), %xmm1    # 0x1081b0
divsd %xmm1, %xmm0
callq 0x9680
movapd %xmm0, %xmm1
movsd 0x42d06(%rip), %xmm0    # 0x115a08
mulsd %xmm0, %xmm1
addsd -0x18(%rbp), %xmm1
movsd %xmm1, -0x18(%rbp)
movsd -0x50(%rbp), %xmm0
mulsd 0x22c6b(%rip), %xmm0    # 0xf5988
callq 0x9710
movapd -0x60(%rbp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x2033d(%rip), %xmm3    # 0xf3070
addsd %xmm3, %xmm0
movapd -0x40(%rbp), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm3, %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpeqsd %xmm2, %xmm1
movapd %xmm1, %xmm2
andnpd %xmm0, %xmm2
andpd %xmm3, %xmm1
orpd %xmm2, %xmm1
movsd 0x42ec3(%rip), %xmm0    # 0x115c30
divsd %xmm1, %xmm0
leaq 0x224af8(%rip), %rax    # 0x2f7870
movsd %xmm0, (%rax)
mulsd 0x42eb4(%rip), %xmm1    # 0x115c38
leaq 0x224add(%rip), %rax    # 0x2f7868
movsd %xmm1, (%rax)
movsd 0x42ea9(%rip), %xmm0    # 0x115c40
mulsd -0x20(%rbp), %xmm0
addsd 0x42e24(%rip), %xmm0    # 0x115bc8
movsd %xmm0, -0x40(%rbp)
divsd 0x353ff(%rip), %xmm0    # 0x1081b0
callq 0x9680
mulsd 0x42c4a(%rip), %xmm0    # 0x115a08
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x42e00(%rip), %xmm1    # 0x115bd0
mulsd -0x20(%rbp), %xmm1
addsd %xmm0, %xmm1
addsd 0x42df7(%rip), %xmm1    # 0x115bd8
movsd %xmm1, -0x40(%rbp)
movapd %xmm1, %xmm0
divsd 0x353be(%rip), %xmm0    # 0x1081b0
callq 0x9680
mulsd 0x42c09(%rip), %xmm0    # 0x115a08
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x20(%rbp), %xmm0
mulsd 0x42e32(%rip), %xmm0    # 0x115c48
addsd 0x42e32(%rip), %xmm0    # 0x115c50
movsd %xmm0, -0x20(%rbp)
divsd 0x35385(%rip), %xmm0    # 0x1081b0
callq 0x9680
mulsd 0x42bd0(%rip), %xmm0    # 0x115a08
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x60(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
addsd %xmm0, %xmm0
subsd -0x40(%rbp), %xmm0
mulsd 0x22b2b(%rip), %xmm0    # 0xf5988
callq 0x9080
mulsd 0x42d76(%rip), %xmm0    # 0x115be0
movsd %xmm0, -0x20(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9080
mulsd 0x42d67(%rip), %xmm0    # 0x115be8
movsd %xmm0, -0x68(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9080
mulsd 0x42d58(%rip), %xmm0    # 0x115bf0
movsd -0x40(%rbp), %xmm1
addsd -0x20(%rbp), %xmm1
subsd -0x68(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
mulsd 0x22ad0(%rip), %xmm0    # 0xf5988
callq 0x9080
mulsd 0x42d33(%rip), %xmm0    # 0x115bf8
movsd %xmm0, -0x50(%rbp)
movsd -0x40(%rbp), %xmm0
addsd %xmm0, %xmm0
mulsd 0x22aad(%rip), %xmm0    # 0xf5988
callq 0x9080
movapd %xmm0, %xmm1
mulsd 0x42d14(%rip), %xmm1    # 0x115c00
movsd -0x20(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, -0x20(%rbp)
subsd -0x18(%rbp), %xmm1
addsd %xmm1, %xmm1
mulsd 0x22a6e(%rip), %xmm1    # 0xf5988
movapd %xmm1, %xmm0
callq 0x9080
mulsd 0x42cdd(%rip), %xmm0    # 0x115c08
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9080
mulsd 0x42d11(%rip), %xmm0    # 0x115c58
addsd -0x70(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x22a2b(%rip), %xmm1    # 0xf5988
movsd %xmm1, -0x28(%rbp)
movapd %xmm1, %xmm0
callq 0x9080
mulsd 0x42ced(%rip), %xmm0    # 0x115c60
movsd %xmm0, -0x60(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9710
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
callq 0x9050
movsd -0x28(%rbp), %xmm0
callq 0x9080
mulsd 0x42cc7(%rip), %xmm0    # 0x115c68
callq 0x9660
movsd -0x20(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
leaq 0x224881(%rip), %r14    # 0x2f7838
movsd %xmm0, (%r14)
mulsd 0x229c4(%rip), %xmm0    # 0xf5988
callq 0x9710
movsd 0x2009f(%rip), %xmm1    # 0xf3070
subsd %xmm0, %xmm1
mulsd 0x2008b(%rip), %xmm1    # 0xf3068
leaq 0x22485c(%rip), %rbx    # 0x2f7840
movsd %xmm1, (%rbx)
movsd -0x50(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
mulsd 0x2298e(%rip), %xmm0    # 0xf5988
callq 0x9710
mulsd 0x42c69(%rip), %xmm0    # 0x115c70
movsd 0x20061(%rip), %xmm3    # 0xf3070
addsd %xmm3, %xmm0
movsd 0x42c5d(%rip), %xmm1    # 0x115c78
divsd %xmm0, %xmm1
leaq 0x22482a(%rip), %rax    # 0x2f7850
movsd %xmm1, (%rax)
divsd 0x42c4e(%rip), %xmm1    # 0x115c80
xorpd %xmm2, %xmm2
cmpeqsd %xmm1, %xmm2
movapd %xmm2, %xmm0
andnpd %xmm1, %xmm0
andpd %xmm3, %xmm2
orpd %xmm0, %xmm2
movsd 0x42c35(%rip), %xmm0    # 0x115c88
divsd %xmm2, %xmm0
leaq 0x2247fa(%rip), %rax    # 0x2f7858
movsd %xmm0, (%rax)
movsd 0x42c26(%rip), %xmm0    # 0x115c90
divsd %xmm2, %xmm0
leaq 0x2247eb(%rip), %rax    # 0x2f7860
movsd %xmm0, (%rax)
movsd (%r14), %xmm0
movsd %xmm0, -0x18(%rbp)
divsd 0x35125(%rip), %xmm0    # 0x1081b0
callq 0x9680
mulsd 0x42970(%rip), %xmm0    # 0x115a08
leaq 0x2246f9(%rip), %rax    # 0x2f7798
movsd (%rax), %xmm1
addsd -0x18(%rbp), %xmm0
divsd 0x35100(%rip), %xmm0    # 0x1081b0
movsd 0x42b60(%rip), %xmm2    # 0x115c18
mulsd %xmm2, %xmm0
addsd 0x228bc(%rip), %xmm1    # 0xf5980
movsd %xmm0, (%r14)
addsd 0x42b4f(%rip), %xmm1    # 0x115c20
divsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x9680
cvttsd2si %xmm0, %rax
incq %rax
leaq 0x22478b(%rip), %rcx    # 0x2f7878
movq %rax, (%rcx)
movsd (%rbx), %xmm0
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq