// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x1, %r13d
xorpd %xmm4, %xmm4
movapd %xmm4, %xmm1
divsd 0x383a1(%rip), %xmm1    # 0x109010
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
movsd 0x383c1(%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 0x383ba(%rip), %xmm0    # 0x109068
cvttsd2si %xmm0, %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
addsd 0x5a9e5(%rip), %xmm0    # 0x12b6a8
divsd 0x5a9e5(%rip), %xmm0    # 0x12b6b0
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 0x5a9bc(%rip), %xmm0    # 0x12b6b8
movsd 0x5a9bc(%rip), %xmm1    # 0x12b6c0
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 0x5a997(%rip), %xmm1    # 0x12b6c8
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 0xd4110
movapd -0x40(%rbp), %xmm3
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
mulsd 0x382af(%rip), %xmm1    # 0x109040
cvttsd2si %xmm1, %eax
cvttpd2dq %xmm1, %xmm0
cvtdq2pd %xmm0, %xmm0
subsd %xmm0, %xmm1
movsd 0x3825f(%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 0xd0e65
ucomisd 0x38387(%rip), %xmm1    # 0x109168
movsd -0x30(%rbp), %xmm4
jb 0xd0dfd
addsd 0x3ab38(%rip), %xmm4    # 0x10b928
movapd %xmm3, %xmm0
decl %r13d
je 0xd0c63
leaq 0x23c89c(%rip), %rsi    # 0x30d6a0
movl %r14d, (%rsi)
leaq 0x23c88e(%rip), %rdi    # 0x30d69c
movl %r15d, (%rdi)
leaq 0x23c88c(%rip), %r8     # 0x30d6a4
movl %r12d, (%r8)
leaq 0x23c886(%rip), %r8     # 0x30d6a8
movl %eax, (%r8)
leaq 0x23c880(%rip), %rax    # 0x30d6ac
movl %ecx, (%rax)
leaq 0x23c87b(%rip), %rax    # 0x30d6b0
movl %edx, (%rax)
leaq 0x23c87a(%rip), %rax    # 0x30d6b8
movsd %xmm1, (%rax)
addl $-0xd, %r15d
cmpl $-0xd, %r15d
ja 0xd0e52
movl $0x0, (%rdi)
movl (%rsi), %eax
testl %eax, %eax
jle 0xd0e5d
cmpl $0x20, %eax
jl 0xd0ea9
movl $0x0, (%rsi)
jmp 0xd0ea9
leaq 0x23c834(%rip), %rsi    # 0x30d6a0
movl %r14d, (%rsi)
leaq 0x23c826(%rip), %rsi    # 0x30d69c
movl %r15d, (%rsi)
leaq 0x23c824(%rip), %rsi    # 0x30d6a4
movl %r12d, (%rsi)
leaq 0x23c81e(%rip), %rsi    # 0x30d6a8
movl %eax, (%rsi)
leaq 0x23c819(%rip), %rax    # 0x30d6ac
movl %ecx, (%rax)
leaq 0x23c814(%rip), %rax    # 0x30d6b0
movl %edx, (%rax)
leaq 0x23c813(%rip), %rax    # 0x30d6b8
movsd %xmm1, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq