// File: /workspace/github_cpp_makefile_star2_O2/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 0x222f73(%rip), %rax    # 0x2f77e8
movsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
leaq 0x222f68(%rip), %rax    # 0x2f77f0
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
leaq 0x222d35(%rip), %rcx    # 0x2f75d0
movsd (%rcx), %xmm0
movsd %xmm0, -0x90(%rbp)
leaq 0x222d2a(%rip), %rdx    # 0x2f75d8
movsd (%rdx), %xmm0
movsd %xmm0, -0x88(%rbp)
movabsq $-0x4015555555555555, %rax # imm = 0xBFEAAAAAAAAAAAAB
movq %rax, (%rdx)
movq %rax, (%rcx)
leaq 0x222c77(%rip), %rax    # 0x2f7548
movsd (%rax), %xmm0
xorl %edi, %edi
callq 0xbfac2
leaq 0x222dc1(%rip), %rax    # 0x2f76a4
movl (%rax), %edi
leaq 0x222db0(%rip), %rax    # 0x2f769c
movl (%rax), %esi
leaq 0x222dab(%rip), %rax    # 0x2f76a0
movl (%rax), %edx
callq 0xc2f07
leaq 0x222f7d(%rip), %rbx    # 0x2f7880
leaq 0x222f96(%rip), %r14    # 0x2f78a0
cvtsi2sdl (%r14), %xmm1
divsd 0x1e729(%rip), %xmm1    # 0xf3040
addsd (%rbx), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movapd %xmm0, %xmm1
addsd 0x1e740(%rip), %xmm1    # 0xf3070
movsd %xmm1, -0x40(%rbp)
movsd 0x1e7bb(%rip), %xmm0    # 0xf30f8
pushq $0x1
popq %rdi
callq 0xd4cfa
leaq 0x222cac(%rip), %r13    # 0x2f75f8
movsd (%r13), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x222d02(%rip), %r15    # 0x2f7660
movsd (%r15), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq 0x222cb9(%rip), %r12    # 0x2f7628
movsd (%r12), %xmm0
movsd %xmm0, -0x80(%rbp)
pushq $0x2
popq %rdi
movsd 0x1e6eb(%rip), %xmm0    # 0xf3070
callq 0xd4cfa
movsd (%r13), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd (%r15), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd (%r12), %xmm0
movsd %xmm0, -0x78(%rbp)
pushq $0x3
popq %rdi
xorps %xmm0, %xmm0
callq 0xd4cfa
movsd (%r13), %xmm2
movsd (%r15), %xmm1
movsd (%r12), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x222c76(%rip), %r15    # 0x2f7648
movl $0x7, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd %xmm2, %xmm0
movsd %xmm1, -0x30(%rbp)
jbe 0xd4a24
leaq 0x1539a0(%rip), %rax    # 0x228390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xd4a19
leaq 0x4a0bc(%rip), %rdi     # 0x11eabb
pushq $0x11
popq %rsi
pushq $0x1
popq %rdx
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 0xd4a60
leaq 0x15395e(%rip), %rax    # 0x228390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xd4a51
leaq 0x4a08c(%rip), %rdi     # 0x11eacd
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
movsd -0x30(%rbp), %xmm1
movsd -0x60(%rbp), %xmm0
movsd %xmm0, (%r13)
andb $-0x2, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xd4aa5
leaq 0x15391e(%rip), %rax    # 0x228390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xd4a91
leaq 0x4a05d(%rip), %rdi     # 0x11eade
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
movsd -0x30(%rbp), %xmm1
leaq 0x222bc8(%rip), %rax    # 0x2f7660
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
andb $-0x3, (%r15)
ucomisd -0x40(%rbp), %xmm1
jb 0xd4ae1
leaq 0x1538dd(%rip), %rax    # 0x228390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xd4acd
leaq 0x4a02d(%rip), %rdi     # 0x11eaef
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
leaq 0x222b8c(%rip), %rax    # 0x2f7660
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
andb $-0x3, (%r15)
movsd -0x38(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0xd4b1d
leaq 0x15389c(%rip), %rax    # 0x228390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xd4b0e
leaq 0x49ffd(%rip), %rdi     # 0x11eb00
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
movsd -0x78(%rbp), %xmm0
movsd %xmm0, (%r12)
andb $-0x5, (%r15)
movsd -0x48(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jb 0xd4b55
leaq 0x153860(%rip), %rax    # 0x228390
movq (%rax), %rcx
testq %rcx, %rcx
je 0xd4b4a
leaq 0x49fd1(%rip), %rdi     # 0x11eb10
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x9750
movsd -0x80(%rbp), %xmm0
movsd %xmm0, (%r12)
cvtsi2sdl (%r14), %xmm0
divsd 0x1e4de(%rip), %xmm0    # 0xf3040
addsd (%rbx), %xmm0
addsd (%r13), %xmm0
addsd 0x41424(%rip), %xmm0    # 0x115f98
xorl %edi, %edi
callq 0xbfac2
leaq 0x222b26(%rip), %r13    # 0x2f76a8
movl (%r13), %eax
leaq 0x222a73(%rip), %rcx    # 0x2f7600
movl %eax, (%rcx)
movq %rbx, %rdx
leaq 0x222b13(%rip), %rbx    # 0x2f76ac
movl (%rbx), %eax
leaq 0x222a62(%rip), %rcx    # 0x2f7604
movl %eax, (%rcx)
leaq 0x222b05(%rip), %r12    # 0x2f76b0
movl (%r12), %eax
leaq 0x222b02(%rip), %r15    # 0x2f76b8
movsd (%r15), %xmm0
leaq 0x222a4e(%rip), %rcx    # 0x2f7610
movsd %xmm0, (%rcx)
cvtsi2sdl (%r14), %xmm0
leaq 0x222a36(%rip), %rcx    # 0x2f7608
divsd 0x1e466(%rip), %xmm0    # 0xf3040
addsd (%rdx), %xmm0
movl %eax, (%rcx)
leaq 0x222a79(%rip), %rax    # 0x2f7660
addsd (%rax), %xmm0
addsd 0x413a5(%rip), %xmm0    # 0x115f98
xorl %edi, %edi
callq 0xbfac2
movl (%r13), %eax
leaq 0x222a63(%rip), %rcx    # 0x2f7668
movl %eax, (%rcx)
movl (%rbx), %eax
leaq 0x222a5c(%rip), %rcx    # 0x2f766c
movl %eax, (%rcx)
movl (%r12), %eax
leaq 0x222a53(%rip), %rcx    # 0x2f7670
movl %eax, (%rcx)
cvtsi2sdl (%r14), %xmm0
divsd 0x1e414(%rip), %xmm0    # 0xf3040
movsd (%r15), %xmm1
leaq 0x222a40(%rip), %rax    # 0x2f7678
leaq 0x222c41(%rip), %rcx    # 0x2f7880
addsd (%rcx), %xmm0
movsd %xmm1, (%rax)
leaq 0x2229da(%rip), %rax    # 0x2f7628
addsd (%rax), %xmm0
addsd 0x4133e(%rip), %xmm0    # 0x115f98
xorl %edi, %edi
callq 0xbfac2
movl (%r13), %eax
leaq 0x2229c4(%rip), %rcx    # 0x2f7630
movl %eax, (%rcx)
movl (%rbx), %eax
leaq 0x2229bd(%rip), %rcx    # 0x2f7634
movl %eax, (%rcx)
movl (%r12), %eax
leaq 0x2229b4(%rip), %rcx    # 0x2f7638
movl %eax, (%rcx)
movsd (%r15), %xmm0
leaq 0x2229ae(%rip), %rax    # 0x2f7640
movsd %xmm0, (%rax)
leaq 0x222933(%rip), %rax    # 0x2f75d0
movsd -0x90(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x222928(%rip), %rax    # 0x2f75d8
movsd -0x88(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x222b25(%rip), %rax    # 0x2f77e8
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x222b1a(%rip), %rax    # 0x2f77f0
movsd -0x98(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x22295f(%rip), %rax    # 0x2f7648
movl (%rax), %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq