// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movsd %xmm0, -0x30(%rbp)
pushq $0x1
popq %rdi
callq 0xce0e1
movsd %xmm0, -0x38(%rbp)
movsd 0x26d23(%rip), %xmm1    # 0xf58f8
movsd -0x30(%rbp), %xmm0
addsd %xmm0, %xmm1
addsd 0x46e2a(%rip), %xmm1    # 0x115a10
movsd %xmm1, -0x18(%rbp)
callq 0xce82b
movsd 0x395b8(%rip), %xmm1    # 0x1081b0
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
mulsd -0x18(%rbp), %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
ja 0xcec19
ucomisd 0x39599(%rip), %xmm2    # 0x1081b0
jbe 0xcec40
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
movsd %xmm2, -0x18(%rbp)
callq 0x9680
movsd -0x18(%rbp), %xmm2
movsd 0x39578(%rip), %xmm1    # 0x1081b0
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm2
movsd %xmm2, -0x18(%rbp)
movsd 0x46dcb(%rip), %xmm0    # 0x115a18
addsd %xmm2, %xmm0
addsd 0x46dc7(%rip), %xmm0    # 0x115a20
movsd %xmm0, -0x20(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0xce799
mulsd 0x46db8(%rip), %xmm0    # 0x115a28
movsd %xmm0, -0x30(%rbp)
movsd -0x20(%rbp), %xmm0
mulsd 0x26c1e(%rip), %xmm0    # 0xf58a0
divsd 0x26c1e(%rip), %xmm0    # 0xf58a8
callq 0x9080
mulsd -0x30(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
addsd 0x46d7f(%rip), %xmm0    # 0x115a20
movsd 0x46d5f(%rip), %xmm1    # 0x115a08
addsd %xmm0, %xmm1
movsd 0x394fb(%rip), %xmm2    # 0x1081b0
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
mulsd 0x26cba(%rip), %xmm2    # 0xf5988
movapd %xmm2, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9710
movsd %xmm0, -0x18(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x20(%rbp)
movapd -0x30(%rbp), %xmm0
callq 0x9080
mulsd -0x20(%rbp), %xmm0
xorpd %xmm1, %xmm1
movsd -0x18(%rbp), %xmm2
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm0
callq 0x9660
divsd 0x26c6a(%rip), %xmm0    # 0xf5988
movsd %xmm0, (%r14)
movaps -0x30(%rbp), %xmm0
callq 0x9710
movsd %xmm0, -0x18(%rbp)
movaps -0x30(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9710
movsd %xmm0, -0x20(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd 0x46cd0(%rip), %xmm0    # 0x115a30
movsd -0x20(%rbp), %xmm1
mulsd -0x30(%rbp), %xmm1
addsd %xmm1, %xmm0
divsd -0x18(%rbp), %xmm0
callq 0x92c0
divsd 0x26c08(%rip), %xmm0    # 0xf5988
movsd 0x39428(%rip), %xmm2    # 0x1081b0
addsd %xmm0, %xmm2
movapd %xmm0, %xmm1
xorpd %xmm3, %xmm3
cmpltsd %xmm3, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
divsd 0x3977b(%rip), %xmm1    # 0x108528
movsd %xmm1, (%rbx)
movsd (%r14), %xmm0
xorps 0x243f3(%rip), %xmm0    # 0xf31b0
movlps %xmm0, (%r14)
movsd (%rbx), %xmm0
addsd 0x46aeb(%rip), %xmm0    # 0x1158b8
movsd 0x2426b(%rip), %xmm1    # 0xf3040
addsd %xmm0, %xmm1
movapd %xmm0, %xmm2
cmpltsd %xmm3, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movlpd %xmm2, (%rbx)
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq