// File: 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
subq $0x40, %rsp
leaq 0x233b11(%rip), %rax    # 0x36c700
cmpl $0x7d9, (%rax)          # imm = 0x7D9
jl 0x138c32
leaq 0x233b02(%rip), %rax    # 0x36c700
cmpl $0x834, (%rax)          # imm = 0x834
jg 0x138c32
leaq 0x233af3(%rip), %rax    # 0x36c700
movl (%rax), %eax
subl $0x7d9, %eax            # imm = 0x7D9
movslq %eax, %rcx
leaq 0x90f12(%rip), %rax     # 0x1c9b30
movss 0x4(%rax,%rcx,8), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x138de9
movsd 0x2a10c6(%rip), %xmm0   # 0x3d9d00
movsd 0x55ab6(%rip), %xmm1    # 0x18e6f8
subsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x2a1095(%rip), %xmm0   # 0x3d9ce8
addsd -0x10(%rbp), %xmm0
movsd 0x364f0(%rip), %xmm1    # 0x16f150
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0xfffffd00, -0x2c(%rbp) # imm = 0xFFFFFD00
cmpl $0x300, -0x2c(%rbp)     # imm = 0x300
jge 0x138d63
movsd -0x28(%rbp), %xmm0
cvtsi2sdl -0x2c(%rbp), %xmm1
movsd 0x36393(%rip), %xmm2    # 0x16f038
divsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x138cc7
movsd -0x10(%rbp), %xmm0
callq 0x138e00
movsd %xmm0, -0x20(%rbp)
movl $0x1, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x138e00
movsd %xmm0, -0x18(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x138d1d
movsd -0x18(%rbp), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x138d1d
movsd -0x10(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x138d0b
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x138d1b
movsd -0x10(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x138d19
jmp 0x138d63
jmp 0x138d1b
jmp 0x138d1d
movsd -0x18(%rbp), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0x138d32
movl $0x1, -0x34(%rbp)
jmp 0x138d4b
movsd -0x18(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x138d49
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
jmp 0x138d4b
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x138c86
leaq 0x233996(%rip), %rax    # 0x36c700
cmpl $0x7f2, (%rax)          # imm = 0x7F2
jne 0x138d7e
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x138dcd
leaq 0x23397b(%rip), %rax    # 0x36c700
cmpl $0x805, (%rax)          # imm = 0x805
jne 0x138d99
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x138dcb
movsd -0x10(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
subsd -0x40(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x138dbf
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x138dc9
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x138dcb
jmp 0x138dcd
movsd 0x5592b(%rip), %xmm0    # 0x18e700
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)