// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathmsc.cpp
// Function: chinese_ny()
double chinese_ny()
{
double jd;
double p, last_p;
double li_chun;
int hour;
int new_moons;
int rising;
double first_new;
  
   // calculate the date of the Chinese new year as the closest new moon
   // to the midpoint between winter and spring (li chun)

   if((this_year >= 2009) && (this_year <= 2100)) {  // we cheat, get date from table
      return china_data[this_year-2009].jd;
   }

   jd = winter - 365.24274306;      // previous winter solstice
   li_chun = (spring + jd) / 2.0;   // li chun is midway between winter and spring

   rising  = 0;
   new_moons = 0;
   first_new = 0.0;
   for(hour= (-24*32); hour<24*32; hour++) {  // look for new moon closet to li chun
      jd = li_chun + ((double) hour)/24.0;
      if(new_moons == 0) last_p = moon_phase(jd);
      new_moons = 1;
      p = moon_phase(jd);

      if((rising < 0) && (p > last_p)) {  // new moon
         if(jd < li_chun) first_new = jd; // before li_chun
         else if(jd > li_chun) break;     // first moon after li chun
      }

      if     (p > last_p) rising = (+1);
      else if(p < last_p) rising = (-1);
      last_p = p;
   }

   if     (this_year == 2034) p = jd; 
   else if(this_year == 2053) p = jd;
   else if((jd-li_chun) > (li_chun - first_new)) p = first_new;
   else                                          p = jd;

   p += 7.0/24.0;   // china time ahead of GMT
   return p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x225dda(%rip), %rbx    # 0x2f7520
movl $0xfffff827, %eax       # imm = 0xFFFFF827
addl (%rbx), %eax
cmpl $0x5b, %eax
ja 0xd1766
movl %eax, %eax
leaq 0x833c5(%rip), %rcx     # 0x154b20
cvtss2sd 0x4(%rcx,%rax,8), %xmm2
jmp 0xd18a4
movsd 0x293332(%rip), %xmm2   # 0x364aa0
addsd 0x443ba(%rip), %xmm2    # 0x115b30
movsd 0x29330a(%rip), %xmm0   # 0x364a88
addsd %xmm2, %xmm0
mulsd 0x218de(%rip), %xmm0    # 0xf3068
movapd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
movb $0x1, %al
movl $0xfffffd00, %r14d      # imm = 0xFFFFFD00
pushq $0x1
popq %r15
pushq $-0x1
popq %r12
cmpl $0x300, %r14d           # imm = 0x300
je 0xd1862
movapd %xmm1, -0x40(%rbp)
cvtsi2sd %r14d, %xmm1
divsd 0x2187b(%rip), %xmm1    # 0xf3040
addsd -0x50(%rbp), %xmm1
testb $0x1, %al
movapd %xmm1, -0x60(%rbp)
je 0xd17e1
movapd %xmm1, %xmm0
callq 0xd18b7
movapd -0x60(%rbp), %xmm1
movsd %xmm0, -0x30(%rbp)
movapd %xmm1, %xmm0
callq 0xd18b7
testl %r13d, %r13d
jns 0xd182d
movsd -0x30(%rbp), %xmm3
ucomisd %xmm3, %xmm0
jbe 0xd1821
movapd -0x60(%rbp), %xmm2
movapd -0x50(%rbp), %xmm1
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm1
ja 0xd183c
ucomisd -0x50(%rbp), %xmm2
ja 0xd185e
movapd -0x40(%rbp), %xmm1
jmp 0xd183c
movapd -0x40(%rbp), %xmm1
movapd -0x60(%rbp), %xmm2
jmp 0xd183c
movapd -0x40(%rbp), %xmm1
movapd -0x60(%rbp), %xmm2
movsd -0x30(%rbp), %xmm3
ucomisd %xmm3, %xmm0
movl %r15d, %ecx
ja 0xd1851
ucomisd %xmm0, %xmm3
movl %r13d, %ecx
jbe 0xd1851
movl %r12d, %ecx
incl %r14d
xorl %eax, %eax
movl %ecx, %r13d
jmp 0xd17a6
movaps -0x40(%rbp), %xmm1
movl (%rbx), %eax
cmpl $0x7f2, %eax            # imm = 0x7F2
je 0xd189c
cmpl $0x805, %eax            # imm = 0x805
je 0xd189c
movapd %xmm2, %xmm0
movapd %xmm1, %xmm3
movapd -0x50(%rbp), %xmm1
subsd %xmm1, %xmm0
subsd %xmm3, %xmm1
cmpltsd %xmm0, %xmm1
andpd %xmm1, %xmm3
andnpd %xmm2, %xmm1
orpd %xmm3, %xmm1
movapd %xmm1, %xmm2
addsd 0x44294(%rip), %xmm2    # 0x115b38
movapd %xmm2, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq