// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathmsc.cpp
// Function: sunxyz_(int*, double*, double*)
int sunxyz_(int *mjd, double *fmjd, double *rs)
{
    /* Local variables */
    static double cobe, ghar, sobe, opod, slon, emdeg, r, t, cslon, slond,
                  tjdtt, sslon, em;
    static double fmjdtt, em2, tsectt, rs1, rs2, rs3, obe;
    static double tsecgps;

    if(mjd == 0) return (-1); 
    if(fmjd == 0) return (-1); 
    if(rs == 0) return (-1); 

    /* get low-precision, geocentric coordinates for sun (ECEF) */
    /*** input, mjd/fmjd, is Modified Julian Date (and fractional) in GPS time */
    /* output, rs, is geocentric solar position vector [m] in ECEF */
    /*** 1."satellite orbits: models, methods, applications" montenbruck & gill(2000) */
    /* section 3.3.2, pg. 70-71 */
    /*** 2."astronomy on the personal computer, 4th ed." montenbruck & pfleger (2005) */
    /* section 3.2, pg. 39  routine MiniSun */
    /* mean elements for year 2000, sun ecliptic orbit wrt. Earth */

    /* Function Body */
    if((tide_options & LOW_RES_TIDES) == 0) {  // use more accurate values from moon_posn()
       slond = sun_hlon;
       r = earth_sun_dist(jd_utc) * 1000.0;
       obe = obliquity(jd_utc, 1);
       cobe = cos(obe);
       sobe = sin(obe);
    }
    else {
       obe = 23.43929111 / stuff_1.rad;
       /* *** obliquity of the J2000 ecliptic */
       sobe = sin(obe);
       cobe = cos(obe);
       opod = 282.94;

       /* use TT for solar ephemerides */
       /* *** RAAN + arg.peri.  (deg.) */
       tsecgps = *fmjd * 86400.;
       /* *** GPS time (sec of */
       tsectt = gps2tt_(&tsecgps);
       /* *** TT  time (sec of */
       fmjdtt = tsectt / 86400.;
       /* julian centuries since 1.5 january 2000 (J2000) */
       /*   (note: also low precision use of mjd --> tjd) */
       /* *** TT  time (fract. */
       tjdtt = *mjd + fmjdtt + 2400000.5;
       /* *** Julian Date, TT */
       t = (tjdtt - 2451545.) / 36525.;
       /* *** julian centuries, */
       emdeg = t * 35999.049 + 357.5256;
       /* *** degrees */
       em = emdeg / stuff_1.rad;
       /* *** radians */
       em2 = em + em;
       /* series expansions in mean anomaly, em   (eq. 3.43, p.71) */
       /* *** radians */
       r = (149.619 - cos(em) * 2.499 - cos(em2) * .021) * 1.0e9;
       /* *** m. */
       slond = opod + emdeg + (sin(em) * 6892. + sin(em2) * 72.) / 3600.;
       /* precession of equinox wrt. J2000   (p.71) */
       slond += t * 1.3972;
    }

    /*** position vector of sun (mean equinox & ecliptic of J2000) (EME2000, ICRF)*/
    /***                        (plus long. advance due to precession -- eq. above)*/
    /* *** degrees */

    slon = slond / stuff_1.rad;
//sprintf(plot_title, "slond:%.9f  r:%.9f  sunhlon:%.9f  erad:%.9f  mjd:%d fmjd:%f", 
//fmod(slond,360.0),r, sun_hlon,earth_sun_dist(jd_utc)*1000.0, *mjd,*fmjd);
    /* *** radians */
    sslon = sin(slon);
    cslon = cos(slon);
    rs1 = r * cslon;
    /* *** meters             !*** eq. 3.46, */
    rs2 = r * sslon * cobe;
    /* *** meters             !*** eq. 3.46, */
    rs3 = r * sslon * sobe;
    /* convert position vector of sun to ECEF  (ignore polar motion/LOD) */

    /* *** meters             !*** eq. 3.46, */
    getghar_(mjd, fmjd, &ghar);
    /* *** sec 2.3.1, */
    rot3_(&ghar, &rs1, &rs2, &rs3, &rs[0], &rs[1], &rs[2]);
    /* *** eq. 2.89, */
    return 0;
}

// Assembly:
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testq %rdx, %rdx
sete %al
orb %cl, %al
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0xea9a2
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x2229d3(%rip), %rax    # 0x30d08c
testb $0x1, (%rax)
jne 0xea72f
movsd 0x28f6a2(%rip), %xmm0   # 0x379d68
movsd %xmm0, 0x2911ba(%rip)   # 0x37b888
leaq 0x222e5b(%rip), %r12    # 0x30d530
movsd (%r12), %xmm0
callq 0xe8ef0
mulsd 0x1e950(%rip), %xmm0    # 0x109038
movsd %xmm0, 0x291188(%rip)   # 0x37b878
movsd (%r12), %xmm0
movl $0x1, %edi
callq 0xe0757
movsd %xmm0, 0x2911b8(%rip)   # 0x37b8c0
callq 0x9710
movsd %xmm0, 0x29113b(%rip)   # 0x37b850
movsd 0x2911a3(%rip), %xmm0   # 0x37b8c0
callq 0x9080
movsd %xmm0, 0x291136(%rip)   # 0x37b860
jmp 0xea8a4
movsd 0x41a41(%rip), %xmm0    # 0x12c178
divsd 0x290d31(%rip), %xmm0   # 0x37b470
movsd %xmm0, 0x291179(%rip)   # 0x37b8c0
callq 0x9080
movsd %xmm0, 0x29110c(%rip)   # 0x37b860
movsd 0x291164(%rip), %xmm0   # 0x37b8c0
callq 0x9710
movsd %xmm0, 0x2910e7(%rip)   # 0x37b850
movsd 0x1e8a7(%rip), %xmm0    # 0x109018
movsd (%r14), %xmm1
mulsd %xmm0, %xmm1
addsd 0x419fe(%rip), %xmm1    # 0x12c180
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
addsd %xmm1, %xmm0
addsd 0x33f7e(%rip), %xmm0    # 0x11e718
addsd 0x40fae(%rip), %xmm0    # 0x12b750
divsd 0x40fae(%rip), %xmm0    # 0x12b758
movsd %xmm0, 0x2910ce(%rip)   # 0x37b880
mulsd 0x419ce(%rip), %xmm0    # 0x12c188
addsd 0x419ce(%rip), %xmm0    # 0x12c190
movsd %xmm0, 0x2910a6(%rip)   # 0x37b870
divsd 0x290c9e(%rip), %xmm0   # 0x37b470
movsd %xmm0, 0x2910be(%rip)   # 0x37b898
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x2910b6(%rip)   # 0x37b8a0
callq 0x9710
mulsd 0x419a1(%rip), %xmm0    # 0x12c198
addsd 0x419a1(%rip), %xmm0    # 0x12c1a0
movsd %xmm0, -0x28(%rbp)
movsd 0x291094(%rip), %xmm0   # 0x37b8a0
callq 0x9710
mulsd 0x4198f(%rip), %xmm0    # 0x12c1a8
addsd -0x28(%rbp), %xmm0
mulsd 0x1e802(%rip), %xmm0    # 0x109028
movsd %xmm0, 0x29104a(%rip)   # 0x37b878
movsd 0x29103a(%rip), %xmm0   # 0x37b870
addsd 0x41972(%rip), %xmm0    # 0x12c1b0
movsd %xmm0, -0x28(%rbp)
movsd 0x29104d(%rip), %xmm0   # 0x37b898
callq 0x9080
movsd %xmm0, -0x30(%rbp)
movsd 0x291043(%rip), %xmm0   # 0x37b8a0
callq 0x9080
mulsd 0x33fa6(%rip), %xmm0    # 0x11e810
movsd -0x30(%rbp), %xmm1
mulsd 0x41941(%rip), %xmm1    # 0x12c1b8
addsd %xmm0, %xmm1
divsd 0x1e78d(%rip), %xmm1    # 0x109010
addsd -0x28(%rbp), %xmm1
movsd 0x290ff0(%rip), %xmm0   # 0x37b880
mulsd 0x41928(%rip), %xmm0    # 0x12c1c0
addsd %xmm1, %xmm0
movsd %xmm0, 0x290fe4(%rip)   # 0x37b888
movsd 0x290fdc(%rip), %xmm0   # 0x37b888
divsd 0x290bbc(%rip), %xmm0   # 0x37b470
movsd %xmm0, 0x290fac(%rip)   # 0x37b868
callq 0x9080
movsd %xmm0, 0x290fc7(%rip)   # 0x37b890
movsd 0x290f97(%rip), %xmm0   # 0x37b868
callq 0x9710
movsd 0x290f9a(%rip), %xmm1   # 0x37b878
mulsd %xmm1, %xmm0
movsd %xmm0, 0x290fbe(%rip)   # 0x37b8a8
mulsd 0x290f9e(%rip), %xmm1   # 0x37b890
movsd 0x290f56(%rip), %xmm0   # 0x37b850
mulsd %xmm1, %xmm0
movsd %xmm0, 0x290faa(%rip)   # 0x37b8b0
mulsd 0x290f52(%rip), %xmm1   # 0x37b860
movsd %xmm1, 0x290fa2(%rip)   # 0x37b8b8
leaq 0x290f3b(%rip), %rdx    # 0x37b858
movq %r15, %rdi
movq %r14, %rsi
callq 0xed864
movsd 0x290f28(%rip), %xmm0   # 0x37b858
callq 0x9080
movsd %xmm0, 0x290fd3(%rip)   # 0x37b910
movsd 0x290f13(%rip), %xmm0   # 0x37b858
callq 0x9710
movsd 0x290f56(%rip), %xmm1   # 0x37b8a8
movsd 0x290fb6(%rip), %xmm2   # 0x37b910
movsd 0x290f4e(%rip), %xmm3   # 0x37b8b0
movapd %xmm0, %xmm4
mulsd %xmm1, %xmm4
mulsd %xmm2, %xmm1
mulsd %xmm3, %xmm2
addsd %xmm2, %xmm4
movsd %xmm4, (%rbx)
mulsd %xmm3, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rbx)
movsd 0x290f29(%rip), %xmm0   # 0x37b8b8
movsd %xmm0, 0x10(%rbx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq