// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
subq $0x38, %rsp
leaq 0x229219(%rip), %rbx    # 0x30d520
movl $0xfffff827, %eax       # imm = 0xFFFFF827
addl (%rbx), %eax
cmpl $0x5b, %eax
ja 0xe4327
movl %eax, %eax
leaq 0x86804(%rip), %rcx     # 0x16ab20
cvtss2sd 0x4(%rcx,%rax,8), %xmm3
jmp 0xe4453
movsd 0x296771(%rip), %xmm0   # 0x37aaa0
addsd 0x477e9(%rip), %xmm0    # 0x12bb20
addsd 0x296749(%rip), %xmm0   # 0x37aa88
mulsd 0x24d21(%rip), %xmm0    # 0x109068
movapd %xmm0, -0x40(%rbp)
movl $0xfffffd00, %r14d      # imm = 0xFFFFFD00
movb $0x1, %al
xorl %r15d, %r15d
xorpd %xmm1, %xmm1
movsd %xmm1, -0x20(%rbp)
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
divsd 0x24cd0(%rip), %xmm1    # 0x109040
addsd -0x40(%rbp), %xmm1
testb $0x1, %al
movapd %xmm1, -0x50(%rbp)
je 0xe438c
movapd %xmm1, %xmm0
callq 0xe4462
movapd -0x50(%rbp), %xmm1
movsd %xmm0, -0x28(%rbp)
movapd %xmm1, %xmm0
callq 0xe4462
testl %r15d, %r15d
jns 0xe43d8
movsd -0x28(%rbp), %xmm2
ucomisd %xmm2, %xmm0
jbe 0xe43cc
movapd -0x40(%rbp), %xmm1
movapd -0x50(%rbp), %xmm3
ucomisd %xmm3, %xmm1
movapd %xmm3, %xmm1
ja 0xe43e7
ucomisd -0x40(%rbp), %xmm3
movsd -0x20(%rbp), %xmm1
jbe 0xe43e7
jmp 0xe4415
movsd -0x20(%rbp), %xmm1
movapd -0x50(%rbp), %xmm3
jmp 0xe43e7
movsd -0x20(%rbp), %xmm1
movapd -0x50(%rbp), %xmm3
movsd -0x28(%rbp), %xmm2
movl $0x1, %ecx
ucomisd %xmm2, %xmm0
ja 0xe4400
ucomisd %xmm0, %xmm2
movl %r15d, %ecx
jbe 0xe4400
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
incl %r14d
xorl %eax, %eax
movl %ecx, %r15d
cmpl $0x300, %r14d           # imm = 0x300
jne 0xe435b
movl (%rbx), %eax
cmpl $0x7f2, %eax            # imm = 0x7F2
je 0xe444b
cmpl $0x805, %eax            # imm = 0x805
je 0xe444b
movapd %xmm3, %xmm0
movapd -0x40(%rbp), %xmm2
subsd %xmm2, %xmm0
subsd %xmm1, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, %xmm3
addsd 0x476d5(%rip), %xmm3    # 0x12bb28
movapd %xmm3, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq