// File: /workspace/github_cpp_makefile_star2_O2/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
je 0xd6b0b
pushq $-0x1
popq %rax
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x220560(%rip), %rax    # 0x2f708c
testb $0x1, (%rax)
jne 0xd6ba8
movsd 0x28d22f(%rip), %xmm0   # 0x363d68
movsd %xmm0, 0x28ec77(%rip)   # 0x3657b8
leaq 0x2209e8(%rip), %r12    # 0x2f7530
movsd (%r12), %xmm0
callq 0xd5405
mulsd 0x1c4dd(%rip), %xmm0    # 0xf3038
movsd %xmm0, 0x28ec45(%rip)   # 0x3657a8
movsd (%r12), %xmm0
pushq $0x1
popq %rdi
callq 0xce0e1
movsd %xmm0, 0x28ec77(%rip)   # 0x3657f0
callq 0x9710
movsd %xmm0, 0x28ebfa(%rip)   # 0x365780
movsd 0x28ec62(%rip), %xmm0   # 0x3657f0
callq 0x9080
movsd %xmm0, 0x28ebf5(%rip)   # 0x365790
movsd 0x28ec15(%rip), %xmm0   # 0x3657b8
jmp 0xd6d1a
movsd 0x3f5d8(%rip), %xmm0    # 0x116188
divsd 0x28e8b8(%rip), %xmm0   # 0x365470
movsd %xmm0, 0x28ec30(%rip)   # 0x3657f0
callq 0x9080
movsd %xmm0, 0x28ebc3(%rip)   # 0x365790
movsd 0x28ec1b(%rip), %xmm0   # 0x3657f0
callq 0x9710
movsd %xmm0, 0x28eb9e(%rip)   # 0x365780
movsd 0x1c42e(%rip), %xmm0    # 0xf3018
movsd (%r14), %xmm1
mulsd %xmm0, %xmm1
addsd 0x3f595(%rip), %xmm1    # 0x116190
divsd %xmm0, %xmm1
cvtsi2sdl (%r15), %xmm0
addsd %xmm1, %xmm0
addsd 0x31b30(%rip), %xmm0    # 0x108740
addsd 0x3eb58(%rip), %xmm0    # 0x115770
divsd 0x3eb58(%rip), %xmm0    # 0x115778
movsd %xmm0, 0x28eb88(%rip)   # 0x3657b0
mulsd 0x3f568(%rip), %xmm0    # 0x116198
addsd 0x3f568(%rip), %xmm0    # 0x1161a0
movsd %xmm0, 0x28eb60(%rip)   # 0x3657a0
divsd 0x28e828(%rip), %xmm0   # 0x365470
movsd %xmm0, 0x28eb78(%rip)   # 0x3657c8
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x28eb70(%rip)   # 0x3657d0
callq 0x9710
mulsd 0x3f53b(%rip), %xmm0    # 0x1161a8
addsd 0x3f53b(%rip), %xmm0    # 0x1161b0
movsd %xmm0, -0x30(%rbp)
movsd 0x28eb4e(%rip), %xmm0   # 0x3657d0
callq 0x9710
mulsd 0x3f529(%rip), %xmm0    # 0x1161b8
addsd -0x30(%rbp), %xmm0
mulsd 0x1c38c(%rip), %xmm0    # 0xf3028
movsd %xmm0, 0x28eb04(%rip)   # 0x3657a8
movsd 0x28eaf4(%rip), %xmm0   # 0x3657a0
addsd 0x3f50c(%rip), %xmm0    # 0x1161c0
movsd %xmm0, -0x30(%rbp)
movsd 0x28eb07(%rip), %xmm0   # 0x3657c8
callq 0x9080
movsd %xmm0, -0x38(%rbp)
movsd 0x28eafd(%rip), %xmm0   # 0x3657d0
callq 0x9080
mulsd 0x31b58(%rip), %xmm0    # 0x108838
movsd -0x38(%rbp), %xmm1
mulsd 0x3f4db(%rip), %xmm1    # 0x1161c8
addsd %xmm0, %xmm1
divsd 0x1c317(%rip), %xmm1    # 0xf3010
addsd -0x30(%rbp), %xmm1
movsd 0x28eaaa(%rip), %xmm0   # 0x3657b0
mulsd 0x3f4c2(%rip), %xmm0    # 0x1161d0
addsd %xmm1, %xmm0
movsd %xmm0, 0x28ea9e(%rip)   # 0x3657b8
divsd 0x28e74e(%rip), %xmm0   # 0x365470
movsd %xmm0, 0x28ea6e(%rip)   # 0x365798
callq 0x9080
movsd %xmm0, 0x28ea89(%rip)   # 0x3657c0
movsd 0x28ea59(%rip), %xmm0   # 0x365798
callq 0x9710
movsd 0x28ea5c(%rip), %xmm1   # 0x3657a8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28ea80(%rip)   # 0x3657d8
mulsd 0x28ea60(%rip), %xmm1   # 0x3657c0
movsd 0x28ea18(%rip), %xmm0   # 0x365780
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28ea6c(%rip)   # 0x3657e0
mulsd 0x28ea14(%rip), %xmm1   # 0x365790
movsd %xmm1, 0x28ea64(%rip)   # 0x3657e8
leaq 0x28ea5d(%rip), %r12    # 0x3657e8
leaq 0x28e9f6(%rip), %r13    # 0x365788
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xd97d6
leaq 0x8(%rbx), %r9
leaq 0x10(%rbx), %rax
movq %rax, (%rsp)
movq %r13, %rdi
leaq 0x28ea22(%rip), %rsi    # 0x3657d8
leaq 0x28ea23(%rip), %rdx    # 0x3657e0
movq %r12, %rcx
movq %rbx, %r8
callq 0xd989e
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq