// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: get_hjd(double)
double get_hjd(double jd)
{
const double ausec = 499.01265;     /* Time it takes light to travel 1 AU */
const double degtorad = (PI/180.0); /* Conversion factor from degrees to radians */

struct coordinates {
  double ra;   /* The right ascension in degrees */
  double dec;  /* The declination in degrees */
  double x;    /* The X position in AU */
  double y;    /* The Y position in AU */
  double z;    /* The Z position in AU */
};

struct coordinates earth;  /* Earth co-ordinates */
struct coordinates source; /* Source co-ordinates */

double correction_secs; /* Correction factor in seconds from MJD to HMJD */
double cel;   /* intermediate calculation from spherical to cartesian co-ordinates */
  
   /* Defaults */
  
   earth.ra = earth.dec = 0.0;

   /* Enter the co-ordinates of the source */
   // !!!! Lady Heather uses 0,0 assuming the source is the sun


   /* Calculate the RA and declination in decimal degree notation */

   source.ra = 0.0 * 15.0;
   source.dec = 0.0;

   /* Attempt to find the RA and Dec of the earth using the astronomical
      calculator book. */

   heliocentric_ra_dec(jd, &earth.ra, &earth.dec);

   /* Calculate the heliocentric co-ordinates as X, Y and Z terms */
   cel = cos(earth.dec * degtorad);
   earth.x = cos(earth.ra * degtorad) * cel;
   earth.y = sin(earth.ra * degtorad) * cel;
   earth.z = sin(earth.dec * degtorad);

   /* Calculate the X,Y,Z co-ordinates of the source */
   cel = cos(source.dec * degtorad);
   source.x = cos(source.ra * degtorad) * cel;
   source.y = sin(source.ra * degtorad) * cel;
   source.z = sin(source.dec * degtorad);

   /* Calculate the correction in seconds for the light travel time
      between the source and the earth vectors in a heliocentric
      reference frame. */

   correction_secs = ausec * (earth.x * source.x + earth.y * source.y + earth.z * source.z);

   /* Modify the JD in a heliocentric reference frame */

   jd = jd + (correction_secs / (24.0*60.0*60.0));

   return jd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movsd %xmm0, -0x8(%rbp)
movsd 0x598a0(%rip), %xmm0    # 0x18e628
movsd %xmm0, -0x10(%rbp)
movsd 0x3c8fb(%rip), %xmm0    # 0x171690
movsd %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x8(%rbp), %xmm0
leaq -0x40(%rbp), %rdi
leaq -0x40(%rbp), %rsi
addq $0x8, %rsi
callq 0x134930
movsd 0x3c8b8(%rip), %xmm0    # 0x171690
mulsd -0x38(%rbp), %xmm0
callq 0x96f0
movsd %xmm0, -0x78(%rbp)
movsd 0x3c8a1(%rip), %xmm0    # 0x171690
mulsd -0x40(%rbp), %xmm0
callq 0x96f0
mulsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x3c885(%rip), %xmm0    # 0x171690
mulsd -0x40(%rbp), %xmm0
callq 0x9080
mulsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x3c869(%rip), %xmm0    # 0x171690
mulsd -0x38(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x20(%rbp)
movsd 0x3c852(%rip), %xmm0    # 0x171690
mulsd -0x60(%rbp), %xmm0
callq 0x96f0
movsd %xmm0, -0x78(%rbp)
movsd 0x3c83b(%rip), %xmm0    # 0x171690
mulsd -0x68(%rbp), %xmm0
callq 0x96f0
mulsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x3c81f(%rip), %xmm0    # 0x171690
mulsd -0x68(%rbp), %xmm0
callq 0x9080
mulsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x3c803(%rip), %xmm0    # 0x171690
mulsd -0x60(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x48(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x58(%rbp), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd -0x50(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd -0x20(%rbp), %xmm1
movsd -0x48(%rbp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x59756(%rip), %xmm0    # 0x18e628
mulsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x8(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
movsd 0x3a11b(%rip), %xmm2    # 0x16f008
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)