// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: gmst(double, int)
double gmst(double jd, int apparent)
{
double st;
double d;    // oh, my
double omega;
double epsilon;
double l;
double delta;
double eqeq;
double jc;

   // calculate Greenwich mean or apparent sidereal time

   d = jd - JD2000; 

   // from NREL SPA code
   jc = d / 36525.0;  // julian century
   st = (280.46061837 + 360.98564736629 * (jd - JD2000) +
         jc*jc*(0.000387933 - jc/38710000.0));
   st = fmod(st, 360.0);
   st /= 15.0;

   if(apparent) { // calculate nutation for apparent sidereal time
      omega = 125.04 - (0.052954 * d);
      l = 280.47 + (0.98565 * d); 
      epsilon = 23.4393 - (0.0000004 * d); 
      delta = (-0.000319*sin(omega)) - (0.000024*sin(l+l));
      eqeq = delta * cos(epsilon);
      st += eqeq;
      st = fmod(st, 24.0);
   }

   while(st < 0.0)   st += 24.0;
   while(st >= 24.0) st -= 24.0;
   return st;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movsd %xmm0, -0x8(%rbp)
movl %edi, -0xc(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0x5939b(%rip), %xmm1    # 0x18e388
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x5937d(%rip), %xmm1    # 0x18e380
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x8(%rbp), %xmm1
movsd 0x5936f(%rip), %xmm0    # 0x18e388
subsd %xmm0, %xmm1
movsd 0x5964b(%rip), %xmm0    # 0x18e670
mulsd %xmm0, %xmm1
movsd 0x59647(%rip), %xmm0    # 0x18e678
addsd %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movsd -0x50(%rbp), %xmm3
movsd 0x5961c(%rip), %xmm2    # 0x18e668
divsd %xmm2, %xmm3
movsd 0x59608(%rip), %xmm2    # 0x18e660
subsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x4daba(%rip), %xmm1    # 0x182b30
callq 0x94d0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x4debb(%rip), %xmm1    # 0x182f48
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x1351af
movsd -0x20(%rbp), %xmm0
movsd 0x59603(%rip), %xmm1    # 0x18e6b0
mulsd %xmm1, %xmm0
movsd 0x594e7(%rip), %xmm1    # 0x18e5a0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x595d1(%rip), %xmm1    # 0x18e6a0
mulsd %xmm1, %xmm0
movsd 0x595cd(%rip), %xmm1    # 0x18e6a8
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x5959f(%rip), %xmm1    # 0x18e690
mulsd %xmm1, %xmm0
movsd 0x5959b(%rip), %xmm1    # 0x18e698
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x28(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x60(%rbp)
movsd -0x38(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
callq 0x9080
movaps %xmm0, %xmm2
movsd -0x60(%rbp), %xmm0
movsd 0x59554(%rip), %xmm1    # 0x18e688
mulsd %xmm2, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x59529(%rip), %xmm2    # 0x18e680
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x96f0
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x39e93(%rip), %xmm1    # 0x16f038
callq 0x94d0
movsd %xmm0, -0x18(%rbp)
jmp 0x1351b1
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x1351cf
movsd 0x39e75(%rip), %xmm0    # 0x16f038
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x1351b1
jmp 0x1351d1
movsd -0x18(%rbp), %xmm0
movsd 0x39e5a(%rip), %xmm1    # 0x16f038
ucomisd %xmm1, %xmm0
jb 0x1351fc
movsd -0x18(%rbp), %xmm0
movsd 0x39e47(%rip), %xmm1    # 0x16f038
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x1351d1
movsd -0x18(%rbp), %xmm0
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)