// File: /workspace/github_cpp_makefile_star2_O1/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 0x29464d(%rip)          # 0x37a5b4
leaq 0x2278da(%rip), %rax    # 0x30d848
movabsq $0x403d87d4a8e43a52, %rcx # imm = 0x403D87D4A8E43A52
movq %rcx, (%rax)
movsd 0x457cd(%rip), %xmm4    # 0x12b750
addsd %xmm0, %xmm4
movapd %xmm4, %xmm1
divsd 0x45995(%rip), %xmm1    # 0x12b928
movsd 0x45995(%rip), %xmm2    # 0x12b930
mulsd %xmm1, %xmm2
addsd 0x45991(%rip), %xmm2    # 0x12b938
movsd 0x45991(%rip), %xmm3    # 0x12b940
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd 0x45985(%rip), %xmm2    # 0x12b948
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm3, %xmm2
movsd 0x45975(%rip), %xmm3    # 0x12b950
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd 0x45961(%rip), %xmm2    # 0x12b958
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm3, %xmm2
movapd %xmm2, -0x70(%rbp)
addsd 0x45b6c(%rip), %xmm0    # 0x12bb88
divsd 0x45734(%rip), %xmm4    # 0x12b758
movsd 0x45934(%rip), %xmm1    # 0x12b960
mulsd %xmm4, %xmm1
addsd 0x45930(%rip), %xmm1    # 0x12b968
movsd 0x45930(%rip), %xmm2    # 0x12b970
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm2
addsd %xmm1, %xmm2
movsd 0x45924(%rip), %xmm1    # 0x12b978
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
movsd 0x38024(%rip), %xmm2    # 0x11e090
movapd %xmm2, %xmm3
movapd %xmm2, %xmm4
divsd %xmm1, %xmm3
xorpd %xmm2, %xmm2
cmpeqsd %xmm1, %xmm2
movsd 0x45977(%rip), %xmm1    # 0x12ba00
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 0x45930(%rip), %xmm0    # 0x12b9e8
addsd -0x30(%rbp), %xmm0
addsd 0x4594b(%rip), %xmm0    # 0x12ba10
addsd 0x4593b(%rip), %xmm0    # 0x12ba08
movsd %xmm0, -0x30(%rbp)
divsd 0x37fb6(%rip), %xmm0    # 0x11e090
callq 0x9680
movapd %xmm0, %xmm3
mulsd 0x458fd(%rip), %xmm3    # 0x12b9e8
addsd -0x30(%rbp), %xmm3
mulsd 0x25810(%rip), %xmm3    # 0x10b908
movapd 0x230a0(%rip), %xmm1    # 0x1091a0
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 0x22f19(%rip), %xmm1    # 0x109070
addsd %xmm1, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
subsd %xmm1, %xmm3
decl %ebx
je 0xe6185
movapd %xmm2, %xmm0
xorpd 0x23029(%rip), %xmm0    # 0x1091a0
maxsd %xmm2, %xmm0
ucomisd 0x37fcd(%rip), %xmm0    # 0x11e150
ja 0xe6114
movapd -0x70(%rbp), %xmm2
movapd %xmm2, %xmm0
movsd 0x22eda(%rip), %xmm1    # 0x109070
addsd %xmm1, %xmm0
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xe61b2
sqrtsd %xmm0, %xmm0
jmp 0xe61c1
movsd %xmm3, -0x30(%rbp)
callq 0x9270
movsd -0x30(%rbp), %xmm3
movsd %xmm0, -0x60(%rbp)
mulsd 0x22e9a(%rip), %xmm3    # 0x109068
movapd %xmm3, %xmm0
callq 0x91b0
mulsd -0x60(%rbp), %xmm0
callq 0x92d0
mulsd 0x22f6f(%rip), %xmm0    # 0x109158
addsd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x459a6(%rip), %xmm1    # 0x12bba0
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movapd %xmm1, %xmm0
movsd 0x37e81(%rip), %xmm1    # 0x11e090
divsd %xmm1, %xmm0
callq 0x9680
movapd %xmm0, %xmm1
movsd 0x457c4(%rip), %xmm0    # 0x12b9e8
mulsd %xmm0, %xmm1
addsd -0x30(%rbp), %xmm1
movsd %xmm1, -0x30(%rbp)
movsd -0x60(%rbp), %xmm0
mulsd 0x256c9(%rip), %xmm0    # 0x10b908
callq 0x9710
movapd -0x70(%rbp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x22e1b(%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 0x45991(%rip), %xmm0    # 0x12bc20
divsd %xmm1, %xmm0
leaq 0x2275d6(%rip), %rax    # 0x30d870
movsd %xmm0, (%rax)
mulsd 0x45982(%rip), %xmm1    # 0x12bc28
leaq 0x2275bb(%rip), %rax    # 0x30d868
movsd %xmm1, (%rax)
movsd 0x45977(%rip), %xmm0    # 0x12bc30
mulsd -0x18(%rbp), %xmm0
addsd 0x458f2(%rip), %xmm0    # 0x12bbb8
movsd %xmm0, -0x50(%rbp)
divsd 0x37dbd(%rip), %xmm0    # 0x11e090
callq 0x9680
mulsd 0x45708(%rip), %xmm0    # 0x12b9e8
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x458ce(%rip), %xmm1    # 0x12bbc0
mulsd -0x18(%rbp), %xmm1
addsd %xmm0, %xmm1
addsd 0x458c5(%rip), %xmm1    # 0x12bbc8
movsd %xmm1, -0x50(%rbp)
movapd %xmm1, %xmm0
divsd 0x37d7c(%rip), %xmm0    # 0x11e090
callq 0x9680
mulsd 0x456c7(%rip), %xmm0    # 0x12b9e8
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x18(%rbp), %xmm0
mulsd 0x45900(%rip), %xmm0    # 0x12bc38
addsd 0x45900(%rip), %xmm0    # 0x12bc40
movsd %xmm0, -0x18(%rbp)
divsd 0x37d43(%rip), %xmm0    # 0x11e090
callq 0x9680
mulsd 0x4568e(%rip), %xmm0    # 0x12b9e8
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x70(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
addsd %xmm0, %xmm0
subsd -0x50(%rbp), %xmm0
mulsd 0x25589(%rip), %xmm0    # 0x10b908
callq 0x9080
mulsd 0x45844(%rip), %xmm0    # 0x12bbd0
movsd %xmm0, -0x18(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x45835(%rip), %xmm0    # 0x12bbd8
movsd %xmm0, -0x78(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x45826(%rip), %xmm0    # 0x12bbe0
movsd -0x50(%rbp), %xmm1
addsd -0x18(%rbp), %xmm1
subsd -0x78(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
mulsd 0x2552e(%rip), %xmm0    # 0x10b908
callq 0x9080
mulsd 0x45801(%rip), %xmm0    # 0x12bbe8
movsd %xmm0, -0x60(%rbp)
movsd -0x50(%rbp), %xmm0
addsd %xmm0, %xmm0
mulsd 0x2550b(%rip), %xmm0    # 0x10b908
callq 0x9080
movapd %xmm0, %xmm1
mulsd 0x457e2(%rip), %xmm1    # 0x12bbf0
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 0x254cc(%rip), %xmm1    # 0x10b908
movapd %xmm1, %xmm0
callq 0x9080
mulsd 0x457ab(%rip), %xmm0    # 0x12bbf8
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x457df(%rip), %xmm0    # 0x12bc48
addsd -0x80(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x25489(%rip), %xmm1    # 0x10b908
movsd %xmm1, -0x38(%rbp)
movapd %xmm1, %xmm0
callq 0x9080
mulsd 0x457bb(%rip), %xmm0    # 0x12bc50
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 0x45795(%rip), %xmm0    # 0x12bc58
callq 0x9660
movsd -0x18(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
leaq 0x22735f(%rip), %r14    # 0x30d838
movsd %xmm0, (%r14)
mulsd 0x25422(%rip), %xmm0    # 0x10b908
callq 0x9710
movsd 0x22b7d(%rip), %xmm1    # 0x109070
subsd %xmm0, %xmm1
mulsd 0x22b69(%rip), %xmm1    # 0x109068
leaq 0x22733a(%rip), %rbx    # 0x30d840
movsd %xmm1, (%rbx)
movsd -0x60(%rbp), %xmm0
addsd -0x50(%rbp), %xmm0
mulsd 0x253ec(%rip), %xmm0    # 0x10b908
callq 0x9710
mulsd 0x45737(%rip), %xmm0    # 0x12bc60
movsd 0x22b3f(%rip), %xmm3    # 0x109070
addsd %xmm3, %xmm0
movsd 0x4572b(%rip), %xmm1    # 0x12bc68
divsd %xmm0, %xmm1
leaq 0x227308(%rip), %rax    # 0x30d850
movsd %xmm1, (%rax)
divsd 0x4571c(%rip), %xmm1    # 0x12bc70
xorpd %xmm2, %xmm2
cmpeqsd %xmm1, %xmm2
movapd %xmm2, %xmm0
andnpd %xmm1, %xmm0
andpd %xmm3, %xmm2
orpd %xmm0, %xmm2
movsd 0x45703(%rip), %xmm0    # 0x12bc78
divsd %xmm2, %xmm0
leaq 0x2272d8(%rip), %rax    # 0x30d858
movsd %xmm0, (%rax)
movsd 0x456f4(%rip), %xmm0    # 0x12bc80
divsd %xmm2, %xmm0
leaq 0x2272c9(%rip), %rax    # 0x30d860
movsd %xmm0, (%rax)
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
divsd 0x37ae3(%rip), %xmm0    # 0x11e090
callq 0x9680
mulsd 0x4542e(%rip), %xmm0    # 0x12b9e8
leaq 0x2271d7(%rip), %rax    # 0x30d798
movsd (%rax), %xmm1
addsd -0x30(%rbp), %xmm0
divsd 0x37abe(%rip), %xmm0    # 0x11e090
movsd 0x4562e(%rip), %xmm2    # 0x12bc08
mulsd %xmm2, %xmm0
addsd 0x2531a(%rip), %xmm1    # 0x10b900
movsd %xmm0, (%r14)
addsd 0x4561d(%rip), %xmm1    # 0x12bc10
divsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x9680
cvttsd2si %xmm0, %rax
incq %rax
leaq 0x227269(%rip), %rcx    # 0x30d878
movq %rax, (%rcx)
movsd (%rbx), %xmm0
addq $0x70, %rsp
popq %rbx
popq %r14
popq %rbp
retq