// File: /workspace/github_cpp_makefile_star2_O3/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 $0x40, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movsd %xmm0, -0x20(%rbp)
movl $0x1, %edi
callq 0xe1215
movsd 0x299ba(%rip), %xmm1    # 0x10b880
movsd -0x20(%rbp), %xmm2
addsd %xmm2, %xmm1
addsd 0x49c01(%rip), %xmm1    # 0x12bad8
movsd %xmm0, -0x28(%rbp)
addsd 0x4994c(%rip), %xmm2    # 0x12b830
movsd %xmm2, -0x20(%rbp)
movapd %xmm2, %xmm0
divsd 0x49943(%rip), %xmm0    # 0x12b838
movsd 0x49b43(%rip), %xmm2    # 0x12ba40
mulsd %xmm0, %xmm2
addsd 0x49b3f(%rip), %xmm2    # 0x12ba48
movsd 0x49b3f(%rip), %xmm3    # 0x12ba50
mulsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd 0x49b33(%rip), %xmm2    # 0x12ba58
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movsd 0x3c1fb(%rip), %xmm4    # 0x11e138
movapd %xmm4, %xmm0
divsd %xmm2, %xmm0
xorpd %xmm3, %xmm3
cmpeqsd %xmm3, %xmm2
movsd 0x49b8a(%rip), %xmm5    # 0x12bae0
andpd %xmm2, %xmm5
andnpd %xmm0, %xmm2
orpd %xmm2, %xmm5
mulsd %xmm1, %xmm5
ucomisd %xmm5, %xmm3
ja 0xe1f76
ucomisd 0x3c1c4(%rip), %xmm5    # 0x11e138
jbe 0xe1f9d
movapd %xmm5, %xmm0
divsd %xmm4, %xmm0
movapd %xmm5, -0x40(%rbp)
callq 0x9680
movapd -0x40(%rbp), %xmm5
movsd 0x3c1a3(%rip), %xmm1    # 0x11e138
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm5
movapd %xmm5, -0x40(%rbp)
movsd 0x49b3e(%rip), %xmm0    # 0x12bae8
addsd %xmm5, %xmm0
addsd 0x49b3a(%rip), %xmm0    # 0x12baf0
movsd -0x20(%rbp), %xmm3
divsd 0x49a45(%rip), %xmm3    # 0x12ba08
movsd 0x49a45(%rip), %xmm1    # 0x12ba10
mulsd %xmm3, %xmm1
addsd 0x49a41(%rip), %xmm1    # 0x12ba18
movsd 0x49a41(%rip), %xmm2    # 0x12ba20
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x49a35(%rip), %xmm1    # 0x12ba28
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd 0x49a25(%rip), %xmm2    # 0x12ba30
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x49a11(%rip), %xmm1    # 0x12ba38
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd 0x49ab1(%rip), %xmm1    # 0x12baf8
movsd %xmm1, -0x20(%rbp)
mulsd 0x297d4(%rip), %xmm0    # 0x10b828
divsd 0x297d4(%rip), %xmm0    # 0x10b830
callq 0x9080
mulsd -0x20(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
addsd 0x49a7d(%rip), %xmm0    # 0x12baf0
movsd 0x49a4d(%rip), %xmm1    # 0x12bac8
addsd %xmm0, %xmm1
movsd 0x3c0b1(%rip), %xmm2    # 0x11e138
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
mulsd 0x29870(%rip), %xmm2    # 0x10b910
movapd %xmm2, -0x20(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9710
movsd %xmm0, -0x40(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x48(%rbp)
movapd -0x20(%rbp), %xmm0
callq 0x9080
mulsd -0x48(%rbp), %xmm0
xorpd %xmm1, %xmm1
movsd -0x40(%rbp), %xmm2
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm0
callq 0x9660
divsd 0x29820(%rip), %xmm0    # 0x10b910
movsd %xmm0, (%r14)
movaps -0x20(%rbp), %xmm0
callq 0x9710
movsd %xmm0, -0x40(%rbp)
movaps -0x20(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x20(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9710
movsd %xmm0, -0x48(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9080
mulsd 0x499ce(%rip), %xmm0    # 0x12bb00
movsd -0x48(%rbp), %xmm1
mulsd -0x20(%rbp), %xmm1
addsd %xmm1, %xmm0
divsd -0x40(%rbp), %xmm0
callq 0x92d0
divsd 0x297be(%rip), %xmm0    # 0x10b910
movsd 0x3bfde(%rip), %xmm2    # 0x11e138
addsd %xmm0, %xmm2
movapd %xmm0, %xmm1
xorpd %xmm3, %xmm3
cmpltsd %xmm3, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
divsd 0x3c3b9(%rip), %xmm1    # 0x11e538
movsd %xmm1, (%rbx)
movsd (%r14), %xmm0
xorps 0x27021(%rip), %xmm0    # 0x1091b0
movlps %xmm0, (%r14)
movsd (%rbx), %xmm0
addsd 0x497d9(%rip), %xmm0    # 0x12b978
movsd 0x26e99(%rip), %xmm1    # 0x109040
addsd %xmm0, %xmm1
movapd %xmm0, %xmm2
cmpltsd %xmm3, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movlpd %xmm2, (%rbx)
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq