// File: /workspace/github_cpp_makefile_star2_O1/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 0x225530(%rip), %rax    # 0x30d7e8
movsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
leaq 0x225525(%rip), %rax    # 0x30d7f0
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
leaq 0x2252f2(%rip), %rcx    # 0x30d5d0
movsd (%rcx), %xmm0
movsd %xmm0, -0x90(%rbp)
leaq 0x2252e7(%rip), %rdx    # 0x30d5d8
movsd (%rdx), %xmm0
movsd %xmm0, -0x88(%rbp)
movabsq $-0x4015555555555555, %rax # imm = 0xBFEAAAAAAAAAAAAB
movq %rax, (%rdx)
movq %rax, (%rcx)
leaq 0x225234(%rip), %rax    # 0x30d548
movsd (%rax), %xmm0
xorl %edi, %edi
callq 0xd0c46
leaq 0x22537e(%rip), %rax    # 0x30d6a4
movl (%rax), %edi
leaq 0x22536d(%rip), %rax    # 0x30d69c
movl (%rax), %esi
leaq 0x225368(%rip), %rax    # 0x30d6a0
movl (%rax), %edx
callq 0xd4110
leaq 0x22553a(%rip), %rbx    # 0x30d880
leaq 0x225553(%rip), %r14    # 0x30d8a0
cvtsi2sdl (%r14), %xmm1
divsd 0x20ce6(%rip), %xmm1    # 0x109040
addsd (%rbx), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movapd %xmm0, %xmm1
addsd 0x20cfd(%rip), %xmm1    # 0x109070
movsd %xmm1, -0x40(%rbp)
movsd 0x20d78(%rip), %xmm0    # 0x1090f8
movl $0x1, %edi
callq 0xe8764
leaq 0x225267(%rip), %r13    # 0x30d5f8
movsd (%r13), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x2252bd(%rip), %r15    # 0x30d660
movsd (%r15), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq 0x225274(%rip), %r12    # 0x30d628
movsd (%r12), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x20ca9(%rip), %xmm0    # 0x109070
movl $0x2, %edi
callq 0xe8764
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 0xe8764
movsd (%r13), %xmm2
movsd (%r15), %xmm1
movsd (%r12), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x22522d(%rip), %r15    # 0x30d648
movl $0x7, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd %xmm2, %xmm0
movsd %xmm1, -0x30(%rbp)
jbe 0xe8471
leaq 0x155f57(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe8466
leaq 0x4c663(%rip), %rdi     # 0x134aab
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 0xe84b1
leaq 0x155f11(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe84a2
leaq 0x4c62f(%rip), %rdi     # 0x134abd
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 0xe84fa
leaq 0x155ecd(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe84e6
leaq 0x4c5fc(%rip), %rdi     # 0x134ace
movl $0x10, %esi
movl $0x1, %edx
callq 0x9750
movsd -0x30(%rbp), %xmm1
leaq 0x225173(%rip), %rax    # 0x30d660
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
andb $-0x3, (%r15)
ucomisd -0x40(%rbp), %xmm1
jb 0xe853a
leaq 0x155e88(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe8526
leaq 0x4c5c8(%rip), %rdi     # 0x134adf
movl $0x10, %esi
movl $0x1, %edx
callq 0x9750
leaq 0x225133(%rip), %rax    # 0x30d660
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
andb $-0x3, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0xe857a
leaq 0x155e43(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe856b
leaq 0x4c594(%rip), %rdi     # 0x134af0
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 0xe85b6
leaq 0x155e03(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xe85ab
leaq 0x4c564(%rip), %rdi     # 0x134b00
movl $0xf, %esi
movl $0x1, %edx
callq 0x9750
movsd -0x80(%rbp), %xmm0
movsd %xmm0, (%r12)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
divsd 0x20a7a(%rip), %xmm0    # 0x109040
addsd (%rbx), %xmm0
addsd (%r13), %xmm0
addsd 0x439b0(%rip), %xmm0    # 0x12bf88
xorl %edi, %edi
callq 0xd0c46
leaq 0x2250c2(%rip), %r13    # 0x30d6a8
movl (%r13), %eax
leaq 0x22500f(%rip), %rcx    # 0x30d600
movl %eax, (%rcx)
movq %rbx, %rdx
leaq 0x2250af(%rip), %rbx    # 0x30d6ac
movl (%rbx), %eax
leaq 0x224ffe(%rip), %rcx    # 0x30d604
movl %eax, (%rcx)
leaq 0x2250a1(%rip), %r12    # 0x30d6b0
movl (%r12), %eax
leaq 0x22509e(%rip), %r15    # 0x30d6b8
movsd (%r15), %xmm0
leaq 0x224fea(%rip), %rcx    # 0x30d610
movsd %xmm0, (%rcx)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
leaq 0x224fcf(%rip), %rcx    # 0x30d608
divsd 0x209ff(%rip), %xmm0    # 0x109040
addsd (%rdx), %xmm0
movl %eax, (%rcx)
leaq 0x225012(%rip), %rax    # 0x30d660
addsd (%rax), %xmm0
addsd 0x4392e(%rip), %xmm0    # 0x12bf88
xorl %edi, %edi
callq 0xd0c46
movl (%r13), %eax
leaq 0x224ffc(%rip), %rcx    # 0x30d668
movl %eax, (%rcx)
movl (%rbx), %eax
leaq 0x224ff5(%rip), %rcx    # 0x30d66c
movl %eax, (%rcx)
movl (%r12), %eax
leaq 0x224fec(%rip), %rcx    # 0x30d670
movl %eax, (%rcx)
xorps %xmm0, %xmm0
cvtsi2sdl (%r14), %xmm0
divsd 0x209aa(%rip), %xmm0    # 0x109040
movsd (%r15), %xmm1
leaq 0x224fd6(%rip), %rax    # 0x30d678
leaq 0x2251d7(%rip), %rcx    # 0x30d880
addsd (%rcx), %xmm0
movsd %xmm1, (%rax)
leaq 0x224f70(%rip), %rax    # 0x30d628
addsd (%rax), %xmm0
addsd 0x438c4(%rip), %xmm0    # 0x12bf88
xorl %edi, %edi
callq 0xd0c46
movl (%r13), %eax
leaq 0x224f5a(%rip), %rcx    # 0x30d630
movl %eax, (%rcx)
movl (%rbx), %eax
leaq 0x224f53(%rip), %rcx    # 0x30d634
movl %eax, (%rcx)
movl (%r12), %eax
leaq 0x224f4a(%rip), %rcx    # 0x30d638
movl %eax, (%rcx)
movsd (%r15), %xmm0
leaq 0x224f44(%rip), %rax    # 0x30d640
movsd %xmm0, (%rax)
leaq 0x224ec9(%rip), %rax    # 0x30d5d0
movsd -0x90(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x224ebe(%rip), %rax    # 0x30d5d8
movsd -0x88(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x2250bb(%rip), %rax    # 0x30d7e8
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x2250b0(%rip), %rax    # 0x30d7f0
movsd -0x98(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x224ef5(%rip), %rax    # 0x30d648
movl (%rax), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq