// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: heliocentric_ra_dec(double, double*, double*)
void heliocentric_ra_dec(double jd, double *ra, double *dec)
{
//const double eccentricity = 0.016718;  /* Eccentricity of the Earth's orbit*/
const double ecliptic_long = 278.833540; /* The longitude of the ecliptic at 1 Jan 1980 0:00 UT */
const double perigee_long = 282.596403;  /* The longitude of perigee at 1 Jan 1980 00:00 UT */
const double deg_to_rad = PI / 180.0;    /* A degrees to radians converion */
const double mjd_1980 = 44238.0;         /* The MJD on 1 Jan 1980 00:00 UT */
double tropical_year = 365.242190402;    /* The length of the tropical year in days */
double obliq = 23.441884*PI/180.0;       /* The obliquity of the orbit */

double mean_anomoly;        /* The mean anomoly of the sun */
double days_from_1980;      /* The number of days from 1 Jan 1980 */
double solar_longitude;     /* The longitude of the sun */
double number_of_deg;       /* The number of degrees in longitude the sun has travelled */
double equation_of_centres; /* The value for the equation of centres */
double x;                   /* An X position */
double y;                   /* A  Y position */
double beta;                /* The ecliptic longitude */ 
double number_of_rotations; /* An integer number of solar orbits */
double mjd;

   /* Calculate the number of days from 1 Jan 1980 */
   
   obliq = obliquity(jd, 1);
   mjd = jd - JD_MJD;  // modified julian date
   days_from_1980 = (mjd - mjd_1980);

   /* Calculate the number of degrees around in the orbit travelled in
      this time */

   tropical_year = solar_year(jd);
   number_of_deg = (360.0 / tropical_year) * days_from_1980;

   /* Adjust so the number of degrees is between 0 and 360 */
   
   if((number_of_deg < 0.0) || (number_of_deg > 360.0)) {
     number_of_rotations = number_of_deg / 360.0;
     number_of_rotations = floor(number_of_rotations);
     number_of_deg -= number_of_rotations * 360.0;
   }

   /* Calculate the mean anomoly */

   mean_anomoly = number_of_deg - perigee_long + ecliptic_long;

   /* Since the orbit is elliptical and not circular, calculate the
      equation of centres */

   equation_of_centres = (360.0 / PI) * orbit_eccentricity(jd) * sin(mean_anomoly * PI/180.0);

   /* Calculate the solar longitude */

   solar_longitude = number_of_deg + equation_of_centres + ecliptic_long;
   if(solar_longitude > 360.0) solar_longitude -= 360.0;
   solar_longitude *= (PI/180.0);

   /* The ecliptic latitude is zero for the Sun. */

   beta = 0.0*PI/180.0;

   /* Calculate the RA and Dec of the sun */
   
   *dec = asin( (sin(beta) * cos(obliq)) +
                (cos(beta) * sin(obliq) *
                 sin(solar_longitude)) );
   
   *dec /= deg_to_rad;
   x = cos(solar_longitude);
   y = (sin(solar_longitude) * cos(obliq)) -
       (tan(beta) * sin(obliq));
   *ra = atan(y/x);
   *ra /= deg_to_rad;

   if(*ra < 0.0) *ra += 360.0;
   *ra /= 15.0;

   /* Convert from geocentric to heliocentric co-ordinates for the Earth*/

   *dec *= -1.0;
   *ra  -= 12.0;
   if(*ra < 0.0) *ra += 24.0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movsd %xmm0, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movsd 0x59cc8(%rip), %xmm0    # 0x18e618
movsd %xmm0, -0x20(%rbp)
movsd 0x59cb3(%rip), %xmm0    # 0x18e610
movsd %xmm0, -0x28(%rbp)
movsd 0x3cd26(%rip), %xmm0    # 0x171690
movsd %xmm0, -0x30(%rbp)
movsd 0x59c81(%rip), %xmm0    # 0x18e5f8
movsd %xmm0, -0x38(%rbp)
movsd 0x59c84(%rip), %xmm0    # 0x18e608
movsd %xmm0, -0x40(%rbp)
movsd 0x59c6f(%rip), %xmm0    # 0x18e600
movsd %xmm0, -0x48(%rbp)
movsd -0x8(%rbp), %xmm0
movl $0x1, %edi
callq 0x133790
movsd %xmm0, -0x48(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x3cc59(%rip), %xmm1    # 0x171610
subsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
movsd 0x59c25(%rip), %xmm1    # 0x18e5f8
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x8(%rbp), %xmm0
callq 0x134310
movsd %xmm0, -0x40(%rbp)
movsd 0x4e13d(%rip), %xmm0    # 0x182b30
divsd -0x40(%rbp), %xmm0
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x68(%rbp), %xmm0
ja 0x134a1f
movsd -0x68(%rbp), %xmm0
movsd 0x4e117(%rip), %xmm1    # 0x182b30
ucomisd %xmm1, %xmm0
jbe 0x134a86
movsd -0x68(%rbp), %xmm0
movsd 0x4e104(%rip), %xmm1    # 0x182b30
divsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
callq 0x9660
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x4e0b7(%rip), %xmm2    # 0x182b30
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd 0x59b7d(%rip), %xmm1    # 0x18e610
subsd %xmm1, %xmm0
movsd 0x59b79(%rip), %xmm1    # 0x18e618
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x8(%rbp), %xmm0
callq 0x134200
movaps %xmm0, %xmm1
movsd 0x59b63(%rip), %xmm0    # 0x18e620
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd 0x3caf7(%rip), %xmm0    # 0x1715c8
mulsd -0x50(%rbp), %xmm0
movsd 0x3a59a(%rip), %xmm1    # 0x16f078
divsd %xmm1, %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd -0xa0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd 0x59b0b(%rip), %xmm1    # 0x18e618
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd 0x4e00d(%rip), %xmm1    # 0x182b30
ucomisd %xmm1, %xmm0
jbe 0x134b3f
movsd -0x60(%rbp), %xmm0
movsd 0x4dffa(%rip), %xmm1    # 0x182b30
subsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x3cb49(%rip), %xmm0    # 0x171690
mulsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0xc0(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x96f0
movsd %xmm0, -0xc8(%rbp)
movsd -0x88(%rbp), %xmm0
callq 0x96f0
movsd %xmm0, -0xd8(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x60(%rbp), %xmm0
callq 0x9080
movsd -0xd0(%rbp), %xmm1
movsd -0xc8(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xc0(%rbp), %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x9640
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x3ca89(%rip), %xmm1    # 0x171690
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm0
callq 0x96f0
movsd %xmm0, -0x78(%rbp)
movsd -0x60(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0xa8(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x96f0
movsd %xmm0, -0xb0(%rbp)
movsd -0x88(%rbp), %xmm0
callq 0x91b0
movsd %xmm0, -0xb8(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x9080
movsd -0xb8(%rbp), %xmm1
movsd -0xb0(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xa8(%rbp), %xmm0
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
divsd -0x78(%rbp), %xmm0
callq 0x92e0
movq -0x10(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x3c9c5(%rip), %xmm1    # 0x171690
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jbe 0x134cf4
movq -0x10(%rbp), %rax
movsd 0x4de44(%rip), %xmm0    # 0x182b30
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x4e244(%rip), %xmm1    # 0x182f48
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rax
movsd 0x3a400(%rip), %xmm0    # 0x16f118
mulsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
movsd 0x4e420(%rip), %xmm1    # 0x183150
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jbe 0x134d59
movq -0x10(%rbp), %rax
movsd 0x3a2e7(%rip), %xmm0    # 0x16f038
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)