// File: 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
subq $0xd0, %rsp
leaq 0x22ec06(%rip), %rax    # 0x36c9c8
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
leaq 0x22ebfb(%rip), %rax    # 0x36c9d0
movsd (%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
leaq 0x22e9c8(%rip), %rax    # 0x36c7b0
movsd (%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
leaq 0x22e9c0(%rip), %rax    # 0x36c7b8
movsd (%rax), %xmm0
movsd %xmm0, -0x10(%rbp)
leaq 0x22e9b0(%rip), %rax    # 0x36c7b8
movsd 0x31390(%rip), %xmm0    # 0x16f1a0
movsd %xmm0, (%rax)
leaq 0x22e995(%rip), %rax    # 0x36c7b0
movsd 0x3137d(%rip), %xmm0    # 0x16f1a0
movsd %xmm0, (%rax)
leaq 0x22e8fa(%rip), %rax    # 0x36c728
movsd (%rax), %xmm0
xorl %edi, %edi
callq 0x11dd00
leaq 0x22ea44(%rip), %rax    # 0x36c884
movl (%rax), %edi
leaq 0x22ea33(%rip), %rax    # 0x36c87c
movl (%rax), %esi
leaq 0x22ea2e(%rip), %rax    # 0x36c880
movl (%rax), %edx
callq 0x122140
movsd %xmm0, -0x98(%rbp)
callq 0x133f80
movaps %xmm0, %xmm1
movsd -0x98(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd 0x311e1(%rip), %xmm1    # 0x16f068
subsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0x311d0(%rip), %xmm0    # 0x16f068
addsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x3126e(%rip), %xmm0    # 0x16f118
movl $0x1, %edi
callq 0x13e3b0
movl %eax, -0x5c(%rbp)
leaq 0x22e91a(%rip), %rax    # 0x36c7d8
movsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0x22e972(%rip), %rax    # 0x36c840
movsd (%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x22e92a(%rip), %rax    # 0x36c808
movsd (%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x31179(%rip), %xmm0    # 0x16f068
movl $0x2, %edi
callq 0x13e3b0
movl %eax, -0x64(%rbp)
leaq 0x22e8d5(%rip), %rax    # 0x36c7d8
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x22e92d(%rip), %rax    # 0x36c840
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x22e8e5(%rip), %rax    # 0x36c808
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
xorps %xmm0, %xmm0
movl $0x3, %edi
callq 0x13e3b0
movl %eax, -0x60(%rbp)
leaq 0x22e895(%rip), %rax    # 0x36c7d8
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x22e8ed(%rip), %rax    # 0x36c840
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x22e8a5(%rip), %rax    # 0x36c808
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq 0x22e8b5(%rip), %rax    # 0x36c828
movl $0x7, (%rax)
movsd -0x30(%rbp), %xmm1
movsd -0x78(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13dfbe
leaq 0x15f5e0(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13dfae
leaq 0x15f5d3(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x59786(%rip), %rsi     # 0x19772d
movb $0x0, %al
callq 0x9550
movsd -0x48(%rbp), %xmm0
leaq 0x22e81e(%rip), %rax    # 0x36c7d8
movsd %xmm0, (%rax)
movsd -0x30(%rbp), %xmm0
ucomisd -0x80(%rbp), %xmm0
jb 0x13e014
leaq 0x15f59f(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13dfef
leaq 0x15f592(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x59757(%rip), %rsi     # 0x19773f
movb $0x0, %al
callq 0x9550
movsd -0x18(%rbp), %xmm0
leaq 0x22e7dd(%rip), %rax    # 0x36c7d8
movsd %xmm0, (%rax)
leaq 0x22e822(%rip), %rax    # 0x36c828
movl (%rax), %ecx
andl $-0x2, %ecx
leaq 0x22e816(%rip), %rax    # 0x36c828
movl %ecx, (%rax)
movsd -0x38(%rbp), %xmm1
movsd -0x78(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13e06e
leaq 0x15f545(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13e049
leaq 0x15f538(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x5970e(%rip), %rsi     # 0x197750
movb $0x0, %al
callq 0x9550
movsd -0x50(%rbp), %xmm0
leaq 0x22e7eb(%rip), %rax    # 0x36c840
movsd %xmm0, (%rax)
leaq 0x22e7c8(%rip), %rax    # 0x36c828
movl (%rax), %ecx
andl $-0x3, %ecx
leaq 0x22e7bc(%rip), %rax    # 0x36c828
movl %ecx, (%rax)
movsd -0x38(%rbp), %xmm0
ucomisd -0x80(%rbp), %xmm0
jb 0x13e0c4
leaq 0x15f4ef(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13e09f
leaq 0x15f4e2(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x596c9(%rip), %rsi     # 0x197761
movb $0x0, %al
callq 0x9550
movsd -0x20(%rbp), %xmm0
leaq 0x22e795(%rip), %rax    # 0x36c840
movsd %xmm0, (%rax)
leaq 0x22e772(%rip), %rax    # 0x36c828
movl (%rax), %ecx
andl $-0x3, %ecx
leaq 0x22e766(%rip), %rax    # 0x36c828
movl %ecx, (%rax)
movsd -0x40(%rbp), %xmm1
movsd -0x78(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13e11e
leaq 0x15f495(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13e0f9
leaq 0x15f488(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x59680(%rip), %rsi     # 0x197772
movb $0x0, %al
callq 0x9550
movsd -0x58(%rbp), %xmm0
leaq 0x22e703(%rip), %rax    # 0x36c808
movsd %xmm0, (%rax)
leaq 0x22e718(%rip), %rax    # 0x36c828
movl (%rax), %ecx
andl $-0x5, %ecx
leaq 0x22e70c(%rip), %rax    # 0x36c828
movl %ecx, (%rax)
movsd -0x40(%rbp), %xmm0
ucomisd -0x80(%rbp), %xmm0
jb 0x13e15f
leaq 0x15f43f(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x13e14f
leaq 0x15f432(%rip), %rax    # 0x29d570
movq (%rax), %rdi
leaq 0x5963a(%rip), %rsi     # 0x197782
movb $0x0, %al
callq 0x9550
movsd -0x28(%rbp), %xmm0
leaq 0x22e6ad(%rip), %rax    # 0x36c808
movsd %xmm0, (%rax)
leaq 0x22e672(%rip), %rax    # 0x36c7d8
movsd (%rax), %xmm0
movsd %xmm0, -0xc8(%rbp)
callq 0x133f80
movaps %xmm0, %xmm1
movsd -0xc8(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
xorl %edx, %edx
movsd 0x30ef8(%rip), %xmm0    # 0x16f090
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0xc0(%rbp), %xmm0
addsd %xmm1, %xmm0
xorl %edi, %edi
callq 0x11dd00
leaq 0x22e6ca(%rip), %rax    # 0x36c888
movl (%rax), %ecx
leaq 0x22e619(%rip), %rax    # 0x36c7e0
movl %ecx, (%rax)
leaq 0x22e6bc(%rip), %rax    # 0x36c88c
movl (%rax), %ecx
leaq 0x22e60b(%rip), %rax    # 0x36c7e4
movl %ecx, (%rax)
leaq 0x22e6ae(%rip), %rax    # 0x36c890
movl (%rax), %ecx
leaq 0x22e5fd(%rip), %rax    # 0x36c7e8
movl %ecx, (%rax)
leaq 0x22e6a4(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
leaq 0x22e5f1(%rip), %rax    # 0x36c7f0
movsd %xmm0, (%rax)
leaq 0x22e636(%rip), %rax    # 0x36c840
movsd (%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
callq 0x133f80
movaps %xmm0, %xmm1
movsd -0xb8(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
xorl %edx, %edx
movsd 0x30e54(%rip), %xmm0    # 0x16f090
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0xb0(%rbp), %xmm0
addsd %xmm1, %xmm0
xorl %edi, %edi
callq 0x11dd00
leaq 0x22e626(%rip), %rax    # 0x36c888
movl (%rax), %ecx
leaq 0x22e5dd(%rip), %rax    # 0x36c848
movl %ecx, (%rax)
leaq 0x22e618(%rip), %rax    # 0x36c88c
movl (%rax), %ecx
leaq 0x22e5cf(%rip), %rax    # 0x36c84c
movl %ecx, (%rax)
leaq 0x22e60a(%rip), %rax    # 0x36c890
movl (%rax), %ecx
leaq 0x22e5c1(%rip), %rax    # 0x36c850
movl %ecx, (%rax)
leaq 0x22e600(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
leaq 0x22e5b5(%rip), %rax    # 0x36c858
movsd %xmm0, (%rax)
leaq 0x22e55a(%rip), %rax    # 0x36c808
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0x133f80
movaps %xmm0, %xmm1
movsd -0xa8(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
xorl %edx, %edx
movsd 0x30db0(%rip), %xmm0    # 0x16f090
movl %edx, %edi
movl %edx, %esi
callq 0x122210
movaps %xmm0, %xmm1
movsd -0xa0(%rbp), %xmm0
addsd %xmm1, %xmm0
xorl %edi, %edi
callq 0x11dd00
leaq 0x22e582(%rip), %rax    # 0x36c888
movl (%rax), %ecx
leaq 0x22e501(%rip), %rax    # 0x36c810
movl %ecx, (%rax)
leaq 0x22e574(%rip), %rax    # 0x36c88c
movl (%rax), %ecx
leaq 0x22e4f3(%rip), %rax    # 0x36c814
movl %ecx, (%rax)
leaq 0x22e566(%rip), %rax    # 0x36c890
movl (%rax), %ecx
leaq 0x22e4e5(%rip), %rax    # 0x36c818
movl %ecx, (%rax)
leaq 0x22e55c(%rip), %rax    # 0x36c898
movsd (%rax), %xmm0
leaq 0x22e4d9(%rip), %rax    # 0x36c820
movsd %xmm0, (%rax)
callq 0x13dda0
movsd -0x8(%rbp), %xmm0
leaq 0x22e454(%rip), %rax    # 0x36c7b0
movsd %xmm0, (%rax)
movsd -0x10(%rbp), %xmm0
leaq 0x22e44c(%rip), %rax    # 0x36c7b8
movsd %xmm0, (%rax)
movsd -0x88(%rbp), %xmm0
leaq 0x22e649(%rip), %rax    # 0x36c9c8
movsd %xmm0, (%rax)
movsd -0x90(%rbp), %xmm0
leaq 0x22e63e(%rip), %rax    # 0x36c9d0
movsd %xmm0, (%rax)
leaq 0x22e48b(%rip), %rax    # 0x36c828
movl (%rax), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)