// File: 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
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
cmpl $0x2, -0x6c(%rbp)
jge 0x11e03b
movsd -0x68(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x11dd3e
jp 0x11dd3e
jmp 0x11dd58
movsd -0x68(%rbp), %xmm0
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x122210
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x51330(%rip), %xmm0    # 0x16f090
addsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x18(%rbp)
cvtsi2sdq -0x18(%rbp), %xmm0
movsd 0x70584(%rip), %xmm1    # 0x18e300
subsd %xmm1, %xmm0
movsd 0x70570(%rip), %xmm1    # 0x18e2f8
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
addq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x5f4, %rax            # imm = 0x5F4
movq %rax, -0x38(%rbp)
cvtsi2sdq -0x38(%rbp), %xmm0
movsd 0x70519(%rip), %xmm1    # 0x18e2f0
subsd %xmm1, %xmm0
movsd 0x70505(%rip), %xmm1    # 0x18e2e8
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x40(%rbp)
cvtsi2sdq -0x40(%rbp), %xmm0
movsd 0x704ea(%rip), %xmm1    # 0x18e2e8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
subq -0x48(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x704c0(%rip), %xmm1    # 0x18e2e0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x50(%rbp)
cvtsi2sdq -0x50(%rbp), %xmm0
movsd 0x704a5(%rip), %xmm1    # 0x18e2e0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
subq -0x48(%rbp), %rax
subq -0x58(%rbp), %rax
movl %eax, %ecx
leaq 0x24ea23(%rip), %rax    # 0x36c880
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
subq $0x1, %rax
movl %eax, %ecx
leaq 0x24ea0c(%rip), %rax    # 0x36c87c
movl %ecx, (%rax)
leaq 0x24ea03(%rip), %rax    # 0x36c87c
cmpl $0xc, (%rax)
jle 0x11de91
movq -0x50(%rbp), %rax
subq $0xd, %rax
movl %eax, %ecx
leaq 0x24e9ed(%rip), %rax    # 0x36c87c
movl %ecx, (%rax)
leaq 0x24e9e4(%rip), %rax    # 0x36c87c
cmpl $0x3, (%rax)
jge 0x11deb4
movq -0x40(%rbp), %rax
subq $0x126b, %rax           # imm = 0x126B
movl %eax, %ecx
leaq 0x24e9d4(%rip), %rax    # 0x36c884
movl %ecx, (%rax)
jmp 0x11dec9
movq -0x40(%rbp), %rax
subq $0x126c, %rax           # imm = 0x126C
movl %eax, %ecx
leaq 0x24e9bd(%rip), %rax    # 0x36c884
movl %ecx, (%rax)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
leaq 0x24e9aa(%rip), %rax    # 0x36c884
movl (%rax), %edi
leaq 0x24e999(%rip), %rax    # 0x36c87c
movl (%rax), %esi
leaq 0x24e994(%rip), %rax    # 0x36c880
movl (%rax), %edx
callq 0x122140
movaps %xmm0, %xmm1
movsd -0x78(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x5112c(%rip), %xmm0    # 0x16f038
mulsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
cvttsd2si -0x60(%rbp), %ecx
leaq 0x24e966(%rip), %rax    # 0x36c888
movl %ecx, (%rax)
movsd -0x60(%rbp), %xmm0
leaq 0x24e958(%rip), %rax    # 0x36c888
cvtsi2sdl (%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x510d3(%rip), %xmm0    # 0x16f018
mulsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
leaq 0x24e937(%rip), %rax    # 0x36c88c
movl %ecx, (%rax)
movsd -0x60(%rbp), %xmm0
leaq 0x24e929(%rip), %rax    # 0x36c88c
cvtsi2sdl (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x51092(%rip), %xmm2    # 0x16f018
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0x5107d(%rip), %xmm0    # 0x16f018
mulsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
leaq 0x24e8e5(%rip), %rax    # 0x36c890
movl %ecx, (%rax)
movsd -0x60(%rbp), %xmm0
leaq 0x24e8d7(%rip), %rax    # 0x36c890
cvtsi2sdl (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x5103c(%rip), %xmm2    # 0x16f018
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
leaq 0x24e8ad(%rip), %rax    # 0x36c898
movsd %xmm0, (%rax)
cmpl $0x0, -0x4(%rbp)
je 0x11dffa
jmp 0x11e0a7
leaq 0x24e897(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
movsd 0x51263(%rip), %xmm1    # 0x16f270
ucomisd %xmm1, %xmm0
jb 0x11e027
movsd 0x51175(%rip), %xmm0    # 0x16f190
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x11e029
jmp 0x11e03b
jmp 0x11e02b
jmp 0x11e02d
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x11dd22
leaq 0x24e83a(%rip), %rax    # 0x36c87c
cmpl $0x1, (%rax)
jge 0x11e056
leaq 0x24e82e(%rip), %rax    # 0x36c87c
movl $0x0, (%rax)
jmp 0x11e071
leaq 0x24e81f(%rip), %rax    # 0x36c87c
cmpl $0xc, (%rax)
jle 0x11e06f
leaq 0x24e813(%rip), %rax    # 0x36c87c
movl $0x0, (%rax)
jmp 0x11e071
leaq 0x24e808(%rip), %rax    # 0x36c880
cmpl $0x1, (%rax)
jge 0x11e08c
leaq 0x24e7fc(%rip), %rax    # 0x36c880
movl $0x0, (%rax)
jmp 0x11e0a7
leaq 0x24e7ed(%rip), %rax    # 0x36c880
cmpl $0x1f, (%rax)
jle 0x11e0a5
leaq 0x24e7e1(%rip), %rax    # 0x36c880
movl $0x0, (%rax)
jmp 0x11e0a7
addq $0x80, %rsp
popq %rbp
retq