// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1410f7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x141509
cmpq $0x0, -0x18(%rbp)
jne 0x14110a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x141509
cmpq $0x0, -0x20(%rbp)
jne 0x14111d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x141509
leaq 0x22b148(%rip), %rax    # 0x36c26c
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1411b2
movsd 0x297e6e(%rip), %xmm0   # 0x3d8fa8
movsd %xmm0, 0x299c0e(%rip)   # 0x3dad50
leaq 0x22b5c7(%rip), %rax    # 0x36c710
movsd (%rax), %xmm0
callq 0x13ed50
movsd 0x2ded6(%rip), %xmm1    # 0x16f030
mulsd %xmm1, %xmm0
movsd %xmm0, 0x299bd2(%rip)   # 0x3dad38
leaq 0x22b5a3(%rip), %rax    # 0x36c710
movsd (%rax), %xmm0
movl $0x1, %edi
callq 0x133790
movsd %xmm0, 0x299c1d(%rip)   # 0x3dada0
movsd 0x299c15(%rip), %xmm0   # 0x3dada0
callq 0x96f0
movsd %xmm0, 0x299b70(%rip)   # 0x3dad08
movsd 0x299c00(%rip), %xmm0   # 0x3dada0
callq 0x9080
movsd %xmm0, 0x299b6b(%rip)   # 0x3dad18
jmp 0x14141b
movsd 0x4db76(%rip), %xmm0    # 0x18ed30
divsd 0x29950e(%rip), %xmm0   # 0x3da6d0
movsd %xmm0, 0x299bd6(%rip)   # 0x3dada0
movsd 0x299bce(%rip), %xmm0   # 0x3dada0
callq 0x9080
movsd %xmm0, 0x299b39(%rip)   # 0x3dad18
movsd 0x299bb9(%rip), %xmm0   # 0x3dada0
callq 0x96f0
movsd %xmm0, 0x299b14(%rip)   # 0x3dad08
movsd 0x4db2c(%rip), %xmm0    # 0x18ed28
movsd %xmm0, 0x299b1c(%rip)   # 0x3dad20
movq -0x18(%rbp), %rax
movsd 0x2ddf8(%rip), %xmm0    # 0x16f008
mulsd (%rax), %xmm0
movsd %xmm0, 0x299b8c(%rip)   # 0x3dada8
leaq 0x299b85(%rip), %rdi    # 0x3dada8
callq 0x143260
movsd %xmm0, 0x299b50(%rip)   # 0x3dad80
movsd 0x299b48(%rip), %xmm0   # 0x3dad80
movsd 0x2ddc8(%rip), %xmm1    # 0x16f008
divsd %xmm1, %xmm0
movsd %xmm0, 0x299b24(%rip)   # 0x3dad70
movq -0x10(%rbp), %rax
cvtsi2sdl (%rax), %xmm0
addsd 0x299b14(%rip), %xmm0   # 0x3dad70
movsd 0x303ac(%rip), %xmm1    # 0x171610
addsd %xmm1, %xmm0
movsd %xmm0, 0x299ae8(%rip)   # 0x3dad58
movsd 0x299ae0(%rip), %xmm0   # 0x3dad58
movsd 0x4d108(%rip), %xmm1    # 0x18e388
subsd %xmm1, %xmm0
movsd 0x4d0f4(%rip), %xmm1    # 0x18e380
divsd %xmm1, %xmm0
movsd %xmm0, 0x299aa8(%rip)   # 0x3dad40
movsd 0x299aa0(%rip), %xmm0   # 0x3dad40
movsd 0x4da70(%rip), %xmm1    # 0x18ed18
mulsd %xmm1, %xmm0
movsd 0x4da6c(%rip), %xmm1    # 0x18ed20
addsd %xmm1, %xmm0
movsd %xmm0, 0x299a70(%rip)   # 0x3dad30
movsd 0x299a68(%rip), %xmm0   # 0x3dad30
divsd 0x299400(%rip), %xmm0   # 0x3da6d0
movsd %xmm0, 0x299a90(%rip)   # 0x3dad68
movsd 0x299a88(%rip), %xmm0   # 0x3dad68
addsd 0x299a80(%rip), %xmm0   # 0x3dad68
movsd %xmm0, 0x299a88(%rip)   # 0x3dad78
movsd 0x299a70(%rip), %xmm0   # 0x3dad68
callq 0x96f0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x4d9ec(%rip), %xmm1    # 0x18ed08
mulsd %xmm1, %xmm0
movsd 0x4d9e8(%rip), %xmm1    # 0x18ed10
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x299a3f(%rip), %xmm0   # 0x3dad78
callq 0x96f0
movsd -0x38(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x4d99e(%rip), %xmm2    # 0x18ed00
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x2dcb6(%rip), %xmm1    # 0x16f028
mulsd %xmm1, %xmm0
movsd %xmm0, 0x2999ba(%rip)   # 0x3dad38
movsd 0x29999a(%rip), %xmm0   # 0x3dad20
addsd 0x2999a2(%rip), %xmm0   # 0x3dad30
movsd %xmm0, -0x28(%rbp)
movsd 0x2999cd(%rip), %xmm0   # 0x3dad68
callq 0x9080
movsd %xmm0, -0x30(%rbp)
movsd 0x2999cb(%rip), %xmm0   # 0x3dad78
callq 0x9080
movsd -0x30(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x28(%rbp), %xmm0
movsd 0x41dc9(%rip), %xmm3    # 0x183190
mulsd %xmm3, %xmm2
movsd 0x4d925(%rip), %xmm3    # 0x18ecf8
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd 0x2dc2d(%rip), %xmm2    # 0x16f010
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x29995d(%rip)   # 0x3dad50
movsd 0x299945(%rip), %xmm0   # 0x3dad40
movsd 0x29994d(%rip), %xmm1   # 0x3dad50
movsd 0x4d8e5(%rip), %xmm2    # 0x18ecf0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x299935(%rip)   # 0x3dad50
movsd 0x29992d(%rip), %xmm0   # 0x3dad50
divsd 0x2992a5(%rip), %xmm0   # 0x3da6d0
movsd %xmm0, 0x2998f5(%rip)   # 0x3dad28
movsd 0x2998ed(%rip), %xmm0   # 0x3dad28
callq 0x9080
movsd %xmm0, 0x299918(%rip)   # 0x3dad60
movsd 0x2998d8(%rip), %xmm0   # 0x3dad28
callq 0x96f0
movsd %xmm0, 0x2998eb(%rip)   # 0x3dad48
movsd 0x2998d3(%rip), %xmm0   # 0x3dad38
mulsd 0x2998db(%rip), %xmm0   # 0x3dad48
movsd %xmm0, 0x299913(%rip)   # 0x3dad88
movsd 0x2998bb(%rip), %xmm0   # 0x3dad38
mulsd 0x2998db(%rip), %xmm0   # 0x3dad60
mulsd 0x29987b(%rip), %xmm0   # 0x3dad08
movsd %xmm0, 0x2998fb(%rip)   # 0x3dad90
movsd 0x29989b(%rip), %xmm0   # 0x3dad38
mulsd 0x2998bb(%rip), %xmm0   # 0x3dad60
mulsd 0x29986b(%rip), %xmm0   # 0x3dad18
movsd %xmm0, 0x2998e3(%rip)   # 0x3dad98
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq 0x29984c(%rip), %rdx    # 0x3dad10
callq 0x1469b0
movq -0x20(%rbp), %r8
movq -0x20(%rbp), %r9
addq $0x8, %r9
movq -0x20(%rbp), %rax
addq $0x10, %rax
leaq 0x29982c(%rip), %rdi    # 0x3dad10
leaq 0x29989d(%rip), %rsi    # 0x3dad88
leaq 0x29989e(%rip), %rdx    # 0x3dad90
leaq 0x29989f(%rip), %rcx    # 0x3dad98
movq %rax, (%rsp)
callq 0x146b70
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)