// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: calc_moonrise()
int calc_moonrise()
{
double old_rise_horizon;
double old_set_horizon;
double r0,n0,s0;
double r1,n1,s1;
double r2,n2,s2;
int f0,f1,f2;
double jd0,jd1,jd2;
double old_az, old_el;

   old_az = moon_az;
   old_el = moon_el;

   old_rise_horizon = sunrise_horizon;
   old_set_horizon = sunset_horizon;
   sunrise_horizon = sunset_horizon = (-50.0/60.0);

   gregorian(0, jd_local);
   jd1 = jdate(g_year,g_month,g_day) - time_zone();   // jd1 is start (midnight) of the local day
// jd1 = jdate(pri_year,pri_month,pri_day) - time_zone();
   jd0 = jd1 - 1.0;
   jd2 = jd1 + 1.0;

   f0 = calc_sunrise(-1.0, 1);   // get info for previous day
   r0 = sunrise_time;
   n0 = solar_noon;
   s0 = sunset_time;

   f2 = calc_sunrise(1.0, 2);    // get info for next day
   r2 = sunrise_time;
   n2 = solar_noon;
   s2 = sunset_time;

   f1 = calc_sunrise(0.0, 3);    // get info for today
   r1 = sunrise_time;
   n1 = solar_noon;
   s1 = sunset_time;

   have_sun_times = 0x07;       // assume all is well

   if(r1 < jd1)  {  // usually an ok condition
if(debug_file) fprintf(debug_file, "# rise prev day!\n");
      sunrise_time = r2;
   }
   if(r1 >= jd2) {
if(debug_file)      fprintf(debug_file, "#rise next day!\n");
      sunrise_time = r0;
      have_sun_times &= (~0x01);
   }

   if(n1 < jd1) {
if(debug_file)      fprintf(debug_file, "#noon prev day!\n");
      solar_noon = n2;
      have_sun_times &= (~0x02);
   }
   if(n1 >= jd2) {
if(debug_file)      fprintf(debug_file, "#noon next day!\n");
      solar_noon = n0;
      have_sun_times &= (~0x02);
   }

   if(s1 < jd1)  {
if(debug_file)      fprintf(debug_file, "#set prev day!\n");
      sunset_time = s2;
      have_sun_times &= (~0x04);
   }
   if(s1 >= jd2) {    // usually an ok condition
if(debug_file)      fprintf(debug_file, "#set next day!\n");
      sunset_time = s0;
   }

   gregorian(0, sunrise_time+time_zone()+jtime(0,0,0,0.5));
   rise_hh = g_hours;
   rise_mm = g_minutes;
   rise_ss = g_seconds;
   rise_frac = g_frac;

   gregorian(0, solar_noon+time_zone()+jtime(0,0,0,0.5)); 
   noon_hh = g_hours;
   noon_mm = g_minutes;
   noon_ss = g_seconds;
   noon_frac = g_frac;

   gregorian(0, sunset_time+time_zone()+jtime(0,0,0,0.5)); 
   set_hh = g_hours;
   set_mm = g_minutes;
   set_ss = g_seconds;
   set_frac = g_frac;

   log_sun_times();

   sunrise_horizon = old_rise_horizon;
   sunset_horizon = old_set_horizon;

   moon_az = old_az;
   moon_el = old_el;

   return have_sun_times;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq 0x224aaf(%rip), %rax    # 0x30d7e8
movsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
leaq 0x224aa4(%rip), %rax    # 0x30d7f0
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
leaq 0x224871(%rip), %rcx    # 0x30d5d0
movsd (%rcx), %xmm0
movsd %xmm0, -0x90(%rbp)
leaq 0x224866(%rip), %rdx    # 0x30d5d8
movsd (%rdx), %xmm0
movsd %xmm0, -0x88(%rbp)
movabsq $-0x4015555555555555, %rax # imm = 0xBFEAAAAAAAAAAAAB
movq %rax, (%rdx)
movq %rax, (%rcx)
leaq 0x2247b3(%rip), %rax    # 0x30d548
movsd (%rax), %xmm0
xorl %edi, %edi
callq 0xd12da
leaq 0x2248fd(%rip), %rax    # 0x30d6a4
movl (%rax), %edi
leaq 0x2248ec(%rip), %rax    # 0x30d69c
movl (%rax), %esi
leaq 0x2248e7(%rip), %rax    # 0x30d6a0
movl (%rax), %edx
callq 0xd485e
leaq 0x224ab9(%rip), %rbx    # 0x30d880
leaq 0x224ad2(%rip), %r14    # 0x30d8a0
cvtsi2sdl (%r14), %xmm1
divsd 0x20265(%rip), %xmm1    # 0x109040
addsd (%rbx), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movapd %xmm0, %xmm1
addsd 0x2027c(%rip), %xmm1    # 0x109070
movsd %xmm1, -0x40(%rbp)
movsd 0x202f7(%rip), %xmm0    # 0x1090f8
movl $0x1, %edi
callq 0xe91e5
leaq 0x2247e6(%rip), %r13    # 0x30d5f8
movsd (%r13), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x22483c(%rip), %r15    # 0x30d660
movsd (%r15), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq 0x2247f3(%rip), %r12    # 0x30d628
movsd (%r12), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x20228(%rip), %xmm0    # 0x109070
movl $0x2, %edi
callq 0xe91e5
movsd (%r13), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd (%r15), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd (%r12), %xmm0
movsd %xmm0, -0x78(%rbp)
xorps %xmm0, %xmm0
movl $0x3, %edi
callq 0xe91e5
movsd (%r13), %xmm2
movsd (%r15), %xmm1
movsd (%r12), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x2247ac(%rip), %r15    # 0x30d648
movl $0x7, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd %xmm2, %xmm0
movsd %xmm1, -0x30(%rbp)
jbe 0xe8ef2
leaq 0x1554d6(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe8ee7
leaq 0x4bcd2(%rip), %rdi     # 0x134b9b
movl $0x11, %esi
movl $0x1, %edx
movsd %xmm2, -0x50(%rbp)
callq 0x9750
movsd -0x50(%rbp), %xmm2
movsd -0x30(%rbp), %xmm1
movsd -0x58(%rbp), %xmm0
movsd %xmm0, (%r13)
ucomisd -0x40(%rbp), %xmm2
jb 0xe8f32
leaq 0x155490(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe8f23
leaq 0x4bc9e(%rip), %rdi     # 0x134bad
movl $0x10, %esi
movl $0x1, %edx
callq 0x9750
movsd -0x30(%rbp), %xmm1
movsd -0x60(%rbp), %xmm0
movsd %xmm0, (%r13)
andb $-0x2, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xe8f7b
leaq 0x15544c(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe8f67
leaq 0x4bc6b(%rip), %rdi     # 0x134bbe
movl $0x10, %esi
movl $0x1, %edx
callq 0x9750
movsd -0x30(%rbp), %xmm1
leaq 0x2246f2(%rip), %rax    # 0x30d660
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
andb $-0x3, (%r15)
ucomisd -0x40(%rbp), %xmm1
jb 0xe8fbb
leaq 0x155407(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe8fa7
leaq 0x4bc37(%rip), %rdi     # 0x134bcf
movl $0x10, %esi
movl $0x1, %edx
callq 0x9750
leaq 0x2246b2(%rip), %rax    # 0x30d660
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
andb $-0x3, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0xe8ffb
leaq 0x1553c2(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe8fec
leaq 0x4bc03(%rip), %rdi     # 0x134be0
movl $0xf, %esi
movl $0x1, %edx
callq 0x9750
movsd -0x78(%rbp), %xmm0
movsd %xmm0, (%r12)
andb $-0x5, (%r15)
movsd -0x48(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jb 0xe9037
leaq 0x155382(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe902c
leaq 0x4bbd3(%rip), %rdi     # 0x134bf0
movl $0xf, %esi
movl $0x1, %edx
callq 0x9750
movsd -0x80(%rbp), %xmm0
movsd %xmm0, (%r12)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
divsd 0x1fff9(%rip), %xmm0    # 0x109040
addsd (%rbx), %xmm0
addsd (%r13), %xmm0
addsd 0x4300f(%rip), %xmm0    # 0x12c068
xorl %edi, %edi
callq 0xd12da
leaq 0x224641(%rip), %r13    # 0x30d6a8
movl (%r13), %eax
leaq 0x22458e(%rip), %rcx    # 0x30d600
movl %eax, (%rcx)
movq %rbx, %rdx
leaq 0x22462e(%rip), %rbx    # 0x30d6ac
movl (%rbx), %eax
leaq 0x22457d(%rip), %rcx    # 0x30d604
movl %eax, (%rcx)
leaq 0x224620(%rip), %r12    # 0x30d6b0
movl (%r12), %eax
leaq 0x22461d(%rip), %r15    # 0x30d6b8
movsd (%r15), %xmm0
leaq 0x224569(%rip), %rcx    # 0x30d610
movsd %xmm0, (%rcx)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
leaq 0x22454e(%rip), %rcx    # 0x30d608
divsd 0x1ff7e(%rip), %xmm0    # 0x109040
addsd (%rdx), %xmm0
movl %eax, (%rcx)
leaq 0x224591(%rip), %rax    # 0x30d660
addsd (%rax), %xmm0
addsd 0x42f8d(%rip), %xmm0    # 0x12c068
xorl %edi, %edi
callq 0xd12da
movl (%r13), %eax
leaq 0x22457b(%rip), %rcx    # 0x30d668
movl %eax, (%rcx)
movl (%rbx), %eax
leaq 0x224574(%rip), %rcx    # 0x30d66c
movl %eax, (%rcx)
movl (%r12), %eax
leaq 0x22456b(%rip), %rcx    # 0x30d670
movl %eax, (%rcx)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
divsd 0x1ff29(%rip), %xmm0    # 0x109040
movsd (%r15), %xmm1
leaq 0x224555(%rip), %rax    # 0x30d678
leaq 0x224756(%rip), %rcx    # 0x30d880
addsd (%rcx), %xmm0
movsd %xmm1, (%rax)
leaq 0x2244ef(%rip), %rax    # 0x30d628
addsd (%rax), %xmm0
addsd 0x42f23(%rip), %xmm0    # 0x12c068
xorl %edi, %edi
callq 0xd12da
movl (%r13), %eax
leaq 0x2244d9(%rip), %rcx    # 0x30d630
movl %eax, (%rcx)
movl (%rbx), %eax
leaq 0x2244d2(%rip), %rcx    # 0x30d634
movl %eax, (%rcx)
movl (%r12), %eax
leaq 0x2244c9(%rip), %rcx    # 0x30d638
movl %eax, (%rcx)
movsd (%r15), %xmm0
leaq 0x2244c3(%rip), %rax    # 0x30d640
movsd %xmm0, (%rax)
leaq 0x224448(%rip), %rax    # 0x30d5d0
movsd -0x90(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x22443d(%rip), %rax    # 0x30d5d8
movsd -0x88(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x22463a(%rip), %rax    # 0x30d7e8
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x22462f(%rip), %rax    # 0x30d7f0
movsd -0x98(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x224474(%rip), %rax    # 0x30d648
movl (%rax), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq