// File: /workspace/github_cpp_makefile_star2_O3/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 0xeb415
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 0x221f60(%rip), %rax    # 0x30d08c
testb $0x1, (%rax)
jne 0xeb1aa
movsd 0x28ec2f(%rip), %xmm0   # 0x379d68
movsd %xmm0, 0x290677(%rip)   # 0x37b7b8
leaq 0x2223e8(%rip), %r12    # 0x30d530
movsd (%r12), %xmm0
callq 0xe9966
mulsd 0x1dedd(%rip), %xmm0    # 0x109038
movsd %xmm0, 0x290645(%rip)   # 0x37b7a8
movsd (%r12), %xmm0
movl $0x1, %edi
callq 0xe1215
movsd %xmm0, 0x290675(%rip)   # 0x37b7f0
callq 0x9710
movsd %xmm0, 0x2905f8(%rip)   # 0x37b780
movsd 0x290660(%rip), %xmm0   # 0x37b7f0
callq 0x9080
movsd %xmm0, 0x2905f3(%rip)   # 0x37b790
movsd 0x290613(%rip), %xmm0   # 0x37b7b8
jmp 0xeb31f
movsd 0x410a6(%rip), %xmm0    # 0x12c258
divsd 0x2902b6(%rip), %xmm0   # 0x37b470
movsd %xmm0, 0x29062e(%rip)   # 0x37b7f0
callq 0x9080
movsd %xmm0, 0x2905c1(%rip)   # 0x37b790
movsd 0x290619(%rip), %xmm0   # 0x37b7f0
callq 0x9710
movsd %xmm0, 0x29059c(%rip)   # 0x37b780
movsd 0x1de2c(%rip), %xmm0    # 0x109018
movsd (%r14), %xmm1
mulsd %xmm0, %xmm1
addsd 0x41063(%rip), %xmm1    # 0x12c260
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl (%r15), %xmm0
addsd %xmm1, %xmm0
addsd 0x335b3(%rip), %xmm0    # 0x11e7c8
addsd 0x40613(%rip), %xmm0    # 0x12b830
divsd 0x40613(%rip), %xmm0    # 0x12b838
movsd %xmm0, 0x290583(%rip)   # 0x37b7b0
mulsd 0x41033(%rip), %xmm0    # 0x12c268
addsd 0x41033(%rip), %xmm0    # 0x12c270
movsd %xmm0, 0x29055b(%rip)   # 0x37b7a0
divsd 0x290223(%rip), %xmm0   # 0x37b470
movsd %xmm0, 0x290573(%rip)   # 0x37b7c8
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x29056b(%rip)   # 0x37b7d0
callq 0x9710
mulsd 0x41006(%rip), %xmm0    # 0x12c278
addsd 0x41006(%rip), %xmm0    # 0x12c280
movsd %xmm0, -0x28(%rbp)
movsd 0x290549(%rip), %xmm0   # 0x37b7d0
callq 0x9710
mulsd 0x40ff4(%rip), %xmm0    # 0x12c288
addsd -0x28(%rbp), %xmm0
mulsd 0x1dd87(%rip), %xmm0    # 0x109028
movsd %xmm0, 0x2904ff(%rip)   # 0x37b7a8
movsd 0x2904ef(%rip), %xmm0   # 0x37b7a0
addsd 0x40fd7(%rip), %xmm0    # 0x12c290
movsd %xmm0, -0x28(%rbp)
movsd 0x290502(%rip), %xmm0   # 0x37b7c8
callq 0x9080
movsd %xmm0, -0x30(%rbp)
movsd 0x2904f8(%rip), %xmm0   # 0x37b7d0
callq 0x9080
mulsd 0x335db(%rip), %xmm0    # 0x11e8c0
movsd -0x30(%rbp), %xmm1
mulsd 0x40fa6(%rip), %xmm1    # 0x12c298
addsd %xmm0, %xmm1
divsd 0x1dd12(%rip), %xmm1    # 0x109010
addsd -0x28(%rbp), %xmm1
movsd 0x2904a5(%rip), %xmm0   # 0x37b7b0
mulsd 0x40f8d(%rip), %xmm0    # 0x12c2a0
addsd %xmm1, %xmm0
movsd %xmm0, 0x290499(%rip)   # 0x37b7b8
divsd 0x290149(%rip), %xmm0   # 0x37b470
movsd %xmm0, 0x290469(%rip)   # 0x37b798
callq 0x9080
movsd %xmm0, 0x290484(%rip)   # 0x37b7c0
movsd 0x290454(%rip), %xmm0   # 0x37b798
callq 0x9710
movsd 0x290457(%rip), %xmm1   # 0x37b7a8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x29047b(%rip)   # 0x37b7d8
mulsd 0x29045b(%rip), %xmm1   # 0x37b7c0
movsd 0x290413(%rip), %xmm0   # 0x37b780
mulsd %xmm1, %xmm0
movsd %xmm0, 0x290467(%rip)   # 0x37b7e0
mulsd 0x29040f(%rip), %xmm1   # 0x37b790
movsd %xmm1, 0x29045f(%rip)   # 0x37b7e8
leaq 0x2903f8(%rip), %rdx    # 0x37b788
movq %r15, %rdi
movq %r14, %rsi
callq 0xedecd
movsd 0x2903e5(%rip), %xmm0   # 0x37b788
callq 0x9080
movsd %xmm0, 0x290488(%rip)   # 0x37b838
movsd 0x2903d0(%rip), %xmm0   # 0x37b788
callq 0x9710
movsd 0x290413(%rip), %xmm1   # 0x37b7d8
movsd 0x29046b(%rip), %xmm2   # 0x37b838
movsd 0x29040b(%rip), %xmm3   # 0x37b7e0
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 0x2903e6(%rip), %xmm0   # 0x37b7e8
movsd %xmm0, 0x10(%rbx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq