// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: gregorian(int, double)
void gregorian(int no_tweak, double jd)
{
long z;
long w;
long x;
long a,b,c,d,e,f;
double t;
double tweak;
int i;


   // convert Julian date to Gregorian
   // The results are returned in the g_xxxx global variables.

   tweak = 0.0;  // used to compensate for subtle round-off errors;
   for(i=0; i<2; i++) {
      if(tweak) jd += jtime(0,0,0, tweak);  // tweak time to prevent round-down errors

      z = (long) (jd + 0.50);
      w = (long) (((double) z - 1867216.25) / 36524.25);
      x = w / 4;
      a = z + 1 + w - x;
      b = a + 1524;
      c = (long) ((((double) b) - 122.1) / 365.25);
      d = (long) (((double) c) * 365.25);
      e = (long) (((double) (b-d)) / 30.6001);
      f = (long) (((double) e) * 30.6001);

      g_day   = (int) (b - d - f);
      g_month = (int) (e - 1);
      if(g_month > 12) g_month = (int) (e - 13);

      if(g_month < 3) g_year = (int) (c - 4715);
      else            g_year = (int) (c - 4716);

      t = jd - jdate(g_year,g_month,g_day); 

      t *= 24.0;          // convert fractional day to hours
      g_hours = (int) t;  // convert decimal hours to hh:mm:ss

      t = (t - g_hours);
      g_minutes = (int) (t * 60.0);

      t = (t * 60.0) - g_minutes;
      g_seconds = (int) (t * 60.0);

      g_frac = (t * 60.0) - g_seconds;

      if(no_tweak) return;
      else if(g_frac >= 0.999) tweak += 0.001;
      else break;
   }

   if(g_month < 1) g_month = 0;        // invalid month, protect against possible array indexing errors
   else if(g_month > 12) g_month = 0;
   if(g_day < 1) g_day = 0;            // invalid day, protect against possible array indexing errors
   else if(g_day > 31) g_day = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
movb $0x1, %r13b
xorpd %xmm4, %xmm4
movapd %xmm4, %xmm1
divsd 0x37d10(%rip), %xmm1    # 0x109010
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
movsd 0x37d30(%rip), %xmm3    # 0x109040
divsd %xmm3, %xmm1
addsd %xmm0, %xmm1
movsd %xmm4, -0x30(%rbp)
cmpneqsd %xmm2, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm4
orpd %xmm1, %xmm4
movapd %xmm4, -0x40(%rbp)
movapd %xmm4, %xmm0
addsd 0x37d29(%rip), %xmm0    # 0x109068
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
addsd 0x5a434(%rip), %xmm0    # 0x12b788
divsd 0x5a434(%rip), %xmm0    # 0x12b790
cvttsd2si %xmm0, %rax
leaq 0x3(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x2, %rcx
addq %rax, %r14
subq %rcx, %r14
addq $0x5f5, %r14            # imm = 0x5F5
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
addsd 0x5a40b(%rip), %xmm0    # 0x12b798
movsd 0x5a40b(%rip), %xmm1    # 0x12b7a0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
subq %rcx, %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
movsd 0x5a3e6(%rip), %xmm1    # 0x12b7a8
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %r15
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
subl %ecx, %r14d
leal -0x1(%r15), %ecx
addl $-0xd, %r15d
cmpl $0xd, %ecx
cmovll %ecx, %r15d
xorl %ecx, %ecx
cmpl $0x3, %r15d
setl %cl
leal -0x126c(%rax,%rcx), %r12d
movl %r12d, %edi
movl %r15d, %esi
movl %r14d, %edx
callq 0xd485e
movapd -0x40(%rbp), %xmm3
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
mulsd 0x37c1e(%rip), %xmm1    # 0x109040
cvttsd2si %xmm1, %eax
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
movsd 0x37bce(%rip), %xmm2    # 0x109008
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %edx
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
testl %ebx, %ebx
jne 0xd14fe
ucomisd 0x37cfe(%rip), %xmm1    # 0x109170
setae %sil
movsd -0x30(%rbp), %xmm4
addsd 0x3a4ad(%rip), %xmm4    # 0x10b930
movapd %xmm3, %xmm0
testb %r13b, %sil
movl $0x0, %r13d
jne 0xd12f4
leaq 0x23c203(%rip), %rsi    # 0x30d6a0
movl %r14d, (%rsi)
leaq 0x23c1f5(%rip), %rdi    # 0x30d69c
movl %r15d, (%rdi)
leaq 0x23c1f3(%rip), %r8     # 0x30d6a4
movl %r12d, (%r8)
leaq 0x23c1ed(%rip), %r8     # 0x30d6a8
movl %eax, (%r8)
leaq 0x23c1e7(%rip), %rax    # 0x30d6ac
movl %ecx, (%rax)
leaq 0x23c1e2(%rip), %rax    # 0x30d6b0
movl %edx, (%rax)
leaq 0x23c1e1(%rip), %rax    # 0x30d6b8
movsd %xmm1, (%rax)
addl $-0xd, %r15d
cmpl $-0xd, %r15d
ja 0xd14eb
movl $0x0, (%rdi)
testl %r14d, %r14d
jle 0xd14f6
cmpl $0x20, %r14d
jb 0xd1542
movl $0x0, (%rsi)
jmp 0xd1542
leaq 0x23c19b(%rip), %rsi    # 0x30d6a0
movl %r14d, (%rsi)
leaq 0x23c18d(%rip), %rsi    # 0x30d69c
movl %r15d, (%rsi)
leaq 0x23c18b(%rip), %rsi    # 0x30d6a4
movl %r12d, (%rsi)
leaq 0x23c185(%rip), %rsi    # 0x30d6a8
movl %eax, (%rsi)
leaq 0x23c180(%rip), %rax    # 0x30d6ac
movl %ecx, (%rax)
leaq 0x23c17b(%rip), %rax    # 0x30d6b0
movl %edx, (%rax)
leaq 0x23c17a(%rip), %rax    # 0x30d6b8
movsd %xmm1, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq