// File: /workspace/github_cpp_makefile_star2_O1/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 0xe0757
movsd 0x2a507(%rip), %xmm1    # 0x10b870
movsd -0x20(%rbp), %xmm2
addsd %xmm2, %xmm1
addsd 0x4a67e(%rip), %xmm1    # 0x12b9f8
movsd %xmm0, -0x28(%rbp)
addsd 0x4a3c9(%rip), %xmm2    # 0x12b750
movsd %xmm2, -0x20(%rbp)
movapd %xmm2, %xmm0
divsd 0x4a3c0(%rip), %xmm0    # 0x12b758
movsd 0x4a5c0(%rip), %xmm2    # 0x12b960
mulsd %xmm0, %xmm2
addsd 0x4a5bc(%rip), %xmm2    # 0x12b968
movsd 0x4a5bc(%rip), %xmm3    # 0x12b970
mulsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd 0x4a5b0(%rip), %xmm2    # 0x12b978
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movsd 0x3ccb0(%rip), %xmm4    # 0x11e090
movapd %xmm4, %xmm0
divsd %xmm2, %xmm0
xorpd %xmm3, %xmm3
cmpeqsd %xmm3, %xmm2
movsd 0x4a607(%rip), %xmm5    # 0x12ba00
andpd %xmm2, %xmm5
andnpd %xmm0, %xmm2
orpd %xmm2, %xmm5
mulsd %xmm1, %xmm5
ucomisd %xmm5, %xmm3
ja 0xe1419
ucomisd 0x3cc79(%rip), %xmm5    # 0x11e090
jbe 0xe1440
movapd %xmm5, %xmm0
divsd %xmm4, %xmm0
movapd %xmm5, -0x40(%rbp)
callq 0x9680
movapd -0x40(%rbp), %xmm5
movsd 0x3cc58(%rip), %xmm1    # 0x11e090
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm5
movapd %xmm5, -0x40(%rbp)
movsd 0x4a5bb(%rip), %xmm0    # 0x12ba08
addsd %xmm5, %xmm0
addsd 0x4a5b7(%rip), %xmm0    # 0x12ba10
movsd -0x20(%rbp), %xmm3
divsd 0x4a4c2(%rip), %xmm3    # 0x12b928
movsd 0x4a4c2(%rip), %xmm1    # 0x12b930
mulsd %xmm3, %xmm1
addsd 0x4a4be(%rip), %xmm1    # 0x12b938
movsd 0x4a4be(%rip), %xmm2    # 0x12b940
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x4a4b2(%rip), %xmm1    # 0x12b948
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd 0x4a4a2(%rip), %xmm2    # 0x12b950
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movsd 0x4a48e(%rip), %xmm1    # 0x12b958
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd 0x4a52e(%rip), %xmm1    # 0x12ba18
movsd %xmm1, -0x20(%rbp)
mulsd 0x2a321(%rip), %xmm0    # 0x10b818
divsd 0x2a321(%rip), %xmm0    # 0x10b820
callq 0x9080
mulsd -0x20(%rbp), %xmm0
addsd -0x40(%rbp), %xmm0
addsd 0x4a4fa(%rip), %xmm0    # 0x12ba10
movsd 0x4a4ca(%rip), %xmm1    # 0x12b9e8
addsd %xmm0, %xmm1
movsd 0x3cb66(%rip), %xmm2    # 0x11e090
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
mulsd 0x2a3c5(%rip), %xmm2    # 0x10b908
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 0x2a375(%rip), %xmm0    # 0x10b908
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 0x4a44b(%rip), %xmm0    # 0x12ba20
movsd -0x48(%rbp), %xmm1
mulsd -0x20(%rbp), %xmm1
addsd %xmm1, %xmm0
divsd -0x40(%rbp), %xmm0
callq 0x92d0
divsd 0x2a313(%rip), %xmm0    # 0x10b908
movsd 0x3ca93(%rip), %xmm2    # 0x11e090
addsd %xmm0, %xmm2
movapd %xmm0, %xmm1
xorpd %xmm3, %xmm3
cmpltsd %xmm3, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
divsd 0x3ce76(%rip), %xmm1    # 0x11e498
movsd %xmm1, (%rbx)
movsd (%r14), %xmm0
xorps 0x27b6e(%rip), %xmm0    # 0x1091a0
movlps %xmm0, (%r14)
movsd (%rbx), %xmm0
addsd 0x4a256(%rip), %xmm0    # 0x12b898
movsd 0x279f6(%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