// File: /workspace/github_cpp_makefile_star2_O3/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 $0x70, %rsp
incl 0x293aff(%rip)          # 0x37a5b4
leaq 0x226d8c(%rip), %rax    # 0x30d848
movabsq $0x403d87d4a8e43a52, %rcx # imm = 0x403D87D4A8E43A52
movq %rcx, (%rax)
movsd 0x44d5f(%rip), %xmm4    # 0x12b830
addsd %xmm0, %xmm4
movapd %xmm4, %xmm1
divsd 0x44f27(%rip), %xmm1    # 0x12ba08
movsd 0x44f27(%rip), %xmm2    # 0x12ba10
mulsd %xmm1, %xmm2
addsd 0x44f23(%rip), %xmm2    # 0x12ba18
movsd 0x44f23(%rip), %xmm3    # 0x12ba20
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd 0x44f17(%rip), %xmm2    # 0x12ba28
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm3, %xmm2
movsd 0x44f07(%rip), %xmm3    # 0x12ba30
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd 0x44ef3(%rip), %xmm2    # 0x12ba38
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm3, %xmm2
movapd %xmm2, -0x70(%rbp)
addsd 0x450fe(%rip), %xmm0    # 0x12bc68
divsd 0x44cc6(%rip), %xmm4    # 0x12b838
movsd 0x44ec6(%rip), %xmm1    # 0x12ba40
mulsd %xmm4, %xmm1
addsd 0x44ec2(%rip), %xmm1    # 0x12ba48
movsd 0x44ec2(%rip), %xmm2    # 0x12ba50
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm2
addsd %xmm1, %xmm2
movsd 0x44eb6(%rip), %xmm1    # 0x12ba58
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
movsd 0x3757e(%rip), %xmm2    # 0x11e138
movapd %xmm2, %xmm3
movapd %xmm2, %xmm4
divsd %xmm1, %xmm3
xorpd %xmm2, %xmm2
cmpeqsd %xmm1, %xmm2
movsd 0x44f09(%rip), %xmm1    # 0x12bae0
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm2, %xmm1
movsd %xmm0, -0x18(%rbp)
mulsd %xmm0, %xmm1
movapd %xmm1, -0x30(%rbp)
movapd %xmm1, %xmm0
divsd %xmm4, %xmm0
callq 0x9680
mulsd 0x44ec2(%rip), %xmm0    # 0x12bac8
addsd -0x30(%rbp), %xmm0
addsd 0x44edd(%rip), %xmm0    # 0x12baf0
addsd 0x44ecd(%rip), %xmm0    # 0x12bae8
movsd %xmm0, -0x30(%rbp)
divsd 0x37510(%rip), %xmm0    # 0x11e138
callq 0x9680
movapd %xmm0, %xmm3
mulsd 0x44e8f(%rip), %xmm3    # 0x12bac8
addsd -0x30(%rbp), %xmm3
mulsd 0x24cca(%rip), %xmm3    # 0x10b910
movapd 0x22562(%rip), %xmm1    # 0x1091b0
xorpd -0x70(%rbp), %xmm1
movapd %xmm1, -0x50(%rbp)
movl $0xb, %ebx
movsd %xmm3, -0x38(%rbp)
movsd %xmm3, -0x30(%rbp)
movapd %xmm3, %xmm0
callq 0x9080
mulsd -0x50(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
subsd -0x38(%rbp), %xmm0
movapd %xmm0, -0x60(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x9710
movapd -0x60(%rbp), %xmm2
movsd -0x30(%rbp), %xmm3
mulsd -0x50(%rbp), %xmm0
movsd 0x223cb(%rip), %xmm1    # 0x109070
addsd %xmm1, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
subsd %xmm1, %xmm3
decl %ebx
je 0xe6cd3
movapd %xmm2, %xmm0
xorpd 0x224eb(%rip), %xmm0    # 0x1091b0
maxsd %xmm2, %xmm0
ucomisd 0x37527(%rip), %xmm0    # 0x11e1f8
ja 0xe6c62
movapd -0x70(%rbp), %xmm2
movapd %xmm2, %xmm0
movsd 0x2238c(%rip), %xmm1    # 0x109070
addsd %xmm1, %xmm0
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xe6d00
sqrtsd %xmm0, %xmm0
jmp 0xe6d0f
movsd %xmm3, -0x30(%rbp)
callq 0x9270
movsd -0x30(%rbp), %xmm3
movsd %xmm0, -0x60(%rbp)
mulsd 0x2234c(%rip), %xmm3    # 0x109068
movapd %xmm3, %xmm0
callq 0x91b0
mulsd -0x60(%rbp), %xmm0
callq 0x92d0
mulsd 0x22429(%rip), %xmm0    # 0x109160
addsd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x44f38(%rip), %xmm1    # 0x12bc80
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movapd %xmm1, %xmm0
movsd 0x373db(%rip), %xmm1    # 0x11e138
divsd %xmm1, %xmm0
callq 0x9680
movapd %xmm0, %xmm1
movsd 0x44d56(%rip), %xmm0    # 0x12bac8
mulsd %xmm0, %xmm1
addsd -0x30(%rbp), %xmm1
movsd %xmm1, -0x30(%rbp)
movsd -0x60(%rbp), %xmm0
mulsd 0x24b83(%rip), %xmm0    # 0x10b910
callq 0x9710
movapd -0x70(%rbp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x222cd(%rip), %xmm3    # 0x109070
addsd %xmm3, %xmm0
movapd -0x50(%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 0x44f23(%rip), %xmm0    # 0x12bd00
divsd %xmm1, %xmm0
leaq 0x226a88(%rip), %rax    # 0x30d870
movsd %xmm0, (%rax)
mulsd 0x44f14(%rip), %xmm1    # 0x12bd08
leaq 0x226a6d(%rip), %rax    # 0x30d868
movsd %xmm1, (%rax)
movsd 0x44f09(%rip), %xmm0    # 0x12bd10
mulsd -0x18(%rbp), %xmm0
addsd 0x44e84(%rip), %xmm0    # 0x12bc98
movsd %xmm0, -0x50(%rbp)
divsd 0x37317(%rip), %xmm0    # 0x11e138
callq 0x9680
mulsd 0x44c9a(%rip), %xmm0    # 0x12bac8
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x44e60(%rip), %xmm1    # 0x12bca0
mulsd -0x18(%rbp), %xmm1
addsd %xmm0, %xmm1
addsd 0x44e57(%rip), %xmm1    # 0x12bca8
movsd %xmm1, -0x50(%rbp)
movapd %xmm1, %xmm0
divsd 0x372d6(%rip), %xmm0    # 0x11e138
callq 0x9680
mulsd 0x44c59(%rip), %xmm0    # 0x12bac8
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x18(%rbp), %xmm0
mulsd 0x44e92(%rip), %xmm0    # 0x12bd18
addsd 0x44e92(%rip), %xmm0    # 0x12bd20
movsd %xmm0, -0x18(%rbp)
divsd 0x3729d(%rip), %xmm0    # 0x11e138
callq 0x9680
mulsd 0x44c20(%rip), %xmm0    # 0x12bac8
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x70(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
addsd %xmm0, %xmm0
subsd -0x50(%rbp), %xmm0
mulsd 0x24a43(%rip), %xmm0    # 0x10b910
callq 0x9080
mulsd 0x44dd6(%rip), %xmm0    # 0x12bcb0
movsd %xmm0, -0x18(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x44dc7(%rip), %xmm0    # 0x12bcb8
movsd %xmm0, -0x78(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x44db8(%rip), %xmm0    # 0x12bcc0
movsd -0x50(%rbp), %xmm1
addsd -0x18(%rbp), %xmm1
subsd -0x78(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
mulsd 0x249e8(%rip), %xmm0    # 0x10b910
callq 0x9080
mulsd 0x44d93(%rip), %xmm0    # 0x12bcc8
movsd %xmm0, -0x60(%rbp)
movsd -0x50(%rbp), %xmm0
addsd %xmm0, %xmm0
mulsd 0x249c5(%rip), %xmm0    # 0x10b910
callq 0x9080
movapd %xmm0, %xmm1
mulsd 0x44d74(%rip), %xmm1    # 0x12bcd0
movsd -0x18(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
subsd -0x78(%rbp), %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, -0x18(%rbp)
subsd -0x30(%rbp), %xmm1
addsd %xmm1, %xmm1
mulsd 0x24986(%rip), %xmm1    # 0x10b910
movapd %xmm1, %xmm0
callq 0x9080
mulsd 0x44d3d(%rip), %xmm0    # 0x12bcd8
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x44d71(%rip), %xmm0    # 0x12bd28
addsd -0x80(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x24943(%rip), %xmm1    # 0x10b910
movsd %xmm1, -0x38(%rbp)
movapd %xmm1, %xmm0
callq 0x9080
mulsd 0x44d4d(%rip), %xmm0    # 0x12bd30
movsd %xmm0, -0x70(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9710
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
callq 0x9050
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x44d27(%rip), %xmm0    # 0x12bd38
callq 0x9660
movsd -0x18(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
leaq 0x226811(%rip), %r14    # 0x30d838
movsd %xmm0, (%r14)
mulsd 0x248dc(%rip), %xmm0    # 0x10b910
callq 0x9710
movsd 0x2202f(%rip), %xmm1    # 0x109070
subsd %xmm0, %xmm1
mulsd 0x2201b(%rip), %xmm1    # 0x109068
leaq 0x2267ec(%rip), %rbx    # 0x30d840
movsd %xmm1, (%rbx)
movsd -0x60(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
mulsd 0x248a6(%rip), %xmm0    # 0x10b910
callq 0x9710
mulsd 0x44cc9(%rip), %xmm0    # 0x12bd40
movsd 0x21ff1(%rip), %xmm3    # 0x109070
addsd %xmm3, %xmm0
movsd 0x44cbd(%rip), %xmm1    # 0x12bd48
divsd %xmm0, %xmm1
leaq 0x2267ba(%rip), %rax    # 0x30d850
movsd %xmm1, (%rax)
divsd 0x44cae(%rip), %xmm1    # 0x12bd50
xorpd %xmm2, %xmm2
cmpeqsd %xmm1, %xmm2
movapd %xmm2, %xmm0
andnpd %xmm1, %xmm0
andpd %xmm3, %xmm2
orpd %xmm0, %xmm2
movsd 0x44c95(%rip), %xmm0    # 0x12bd58
divsd %xmm2, %xmm0
leaq 0x22678a(%rip), %rax    # 0x30d858
movsd %xmm0, (%rax)
movsd 0x44c86(%rip), %xmm0    # 0x12bd60
divsd %xmm2, %xmm0
leaq 0x22677b(%rip), %rax    # 0x30d860
movsd %xmm0, (%rax)
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
divsd 0x3703d(%rip), %xmm0    # 0x11e138
callq 0x9680
mulsd 0x449c0(%rip), %xmm0    # 0x12bac8
leaq 0x226689(%rip), %rax    # 0x30d798
movsd (%rax), %xmm1
addsd -0x30(%rbp), %xmm0
divsd 0x37018(%rip), %xmm0    # 0x11e138
movsd 0x44bc0(%rip), %xmm2    # 0x12bce8
mulsd %xmm2, %xmm0
addsd 0x247d4(%rip), %xmm1    # 0x10b908
movsd %xmm0, (%r14)
addsd 0x44baf(%rip), %xmm1    # 0x12bcf0
divsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x9680
cvttsd2si %xmm0, %rax
incq %rax
leaq 0x22671b(%rip), %rcx    # 0x30d878
movq %rax, (%rcx)
movsd (%rbx), %xmm0
addq $0x70, %rsp
popq %rbx
popq %r14
popq %rbp
retq