// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: calc_precise_lla()
void calc_precise_lla()
{
u08 have_lla;

   // calculate simple average of all surveyed points

   have_lla = 0;
   if(precision_samples) {
      xlat = lat_sum / (double)precision_samples;
      xlon = lon_sum / (double)precision_samples;
      xalt = alt_sum / (double)precision_samples;
      precise_lat = xlat;
      precise_lon = xlon;
      precise_alt = xalt;
      have_precise_lla = 2;
      ref_lat = precise_lat;
      ref_lon = precise_lon;
      ref_alt = precise_alt;
      cos_factor = cos(ref_lat);
      if(cos_factor == 0.0) cos_factor = 0.001;
      lla_to_ecef(xlat,xlon,xalt);

      xlat *= RAD_TO_DEG;
      xlon *= RAD_TO_DEG;
      if(lla_file) {
         fprintf(lla_file, "# Simple average of %.0f points:\n", (double)precision_samples);
         fprintf(lla_file, "#   lat:%14.10f  %.10f  ecef_x:%.5f  dms:%s\n",  xlat, (xlat-LAT_REF)/ANGLE_SCALE, ecef_x, dms_fmt(xlat));
         fprintf(lla_file, "#   lon:%14.10f  %.10f  ecef_y:%.5f  dms:%s\n",  xlon, (xlon-LON_REF)/ANGLE_SCALE*COS_FACTOR(xlat), ecef_y, dms_fmt(xlon));
         fprintf(lla_file, "#   alt:%14.10f  %.10f  ecef_z:%.5f\n",  xalt, (xalt-ALT_REF), ecef_z);
         fprintf(lla_file, "#\n");
      }
      have_lla |= 0x01;
   }


   // calculate average of all 24 hour median intervals
   if(best_count && best_lat && best_lon && best_alt) {
      xlat = best_lat / best_count;
      xlon = best_lon / best_count;
      xalt = best_alt / best_count;
      precise_lat = xlat;
      precise_lon = xlon;
      precise_alt = xalt;
      have_precise_lla = 3;
      ref_lat = xlat;
      ref_lon = xlon;
      ref_alt = xalt;
      cos_factor = cos(ref_lat);
      if(cos_factor == 0.0) cos_factor = 0.001;
      lla_to_ecef(xlat,xlon,xalt);

      xlat *= RAD_TO_DEG;
      xlon *= RAD_TO_DEG;
      if(lla_file) {
         fprintf(lla_file, "# REF: %.10f  %.10f  %.10f  cos=%.10f\n", LAT_REF, LON_REF, ALT_REF, COS_FACTOR(xlat));
         fprintf(lla_file, "# Average of %.0f 24 hour medians:\n", best_count);
         fprintf(lla_file, "#   lat:%14.10f  %.10f  ecef_x:%.5f  dms:%s\n",  xlat, (xlat-LAT_REF)/ANGLE_SCALE, ecef_x, dms_fmt(xlat));
         fprintf(lla_file, "#   lon:%14.10f  %.10f  ecef_y:%.5f  dms:%s\n",  xlon, (xlon-LON_REF)/ANGLE_SCALE*COS_FACTOR(xlat), ecef_y, dms_fmt(xlon));
         fprintf(lla_file, "#   alt:%14.10f  %.10f  ecef_z:%.5f\n",  xalt, (xalt-ALT_REF), ecef_z);
      }
      have_lla |= 0x02;
   }

   if(have_lla) {            // we have a good idea where we are
      save_precise_posn(-1);  // save it in the receiver (directly or via repeated single point surveys)
   }
//if(lla_file) {
//   fprintf(lla_file, "### calc_precise_lla: have:%d  ps:%d bc:%d bla:%d blo:%d bal:%d\n", 
//   have_lla, precision_samples, best_count,best_lat,best_lon,best_alt);
//}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x23eac3(%rip), %rbx    # 0x33b2e4
movl (%rbx), %r14d
testl %r14d, %r14d
je 0xfcab6
movsd 0x35608b(%rip), %xmm0   # 0x4528c0
movl %r14d, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x35605f(%rip)   # 0x4528a8
movsd 0x356077(%rip), %xmm2   # 0x4528c8
divsd %xmm1, %xmm2
movsd %xmm2, 0x356053(%rip)   # 0x4528b0
movsd 0x35606b(%rip), %xmm3   # 0x4528d0
divsd %xmm1, %xmm3
movsd %xmm3, 0x356047(%rip)   # 0x4528b8
leaq 0x23ea78(%rip), %r15    # 0x33b2f0
movsd %xmm0, (%r15)
leaq 0x23ea74(%rip), %r13    # 0x33b2f8
movsd %xmm2, (%r13)
leaq 0x23ea6f(%rip), %rax    # 0x33b300
movsd %xmm3, (%rax)
leaq 0x23ea6c(%rip), %rax    # 0x33b308
movl $0x2, (%rax)
leaq 0x23ea67(%rip), %rax    # 0x33b310
movsd %xmm0, (%rax)
leaq 0x23ea64(%rip), %rax    # 0x33b318
movsd %xmm2, (%rax)
leaq 0x23ea61(%rip), %rax    # 0x33b320
movsd %xmm3, (%rax)
callq 0x9710
xorpd %xmm1, %xmm1
cmpeqsd %xmm0, %xmm1
movsd 0xf057(%rip), %xmm2     # 0x10b930
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm1, %xmm2
leaq 0x2106dc(%rip), %rax    # 0x30cfc8
movlpd %xmm2, (%rax)
movsd 0x355fb0(%rip), %xmm0   # 0x4528a8
movsd 0x355fb0(%rip), %xmm1   # 0x4528b0
movsd 0x355fb0(%rip), %xmm2   # 0x4528b8
callq 0x5c8c0
movsd 0xc84b(%rip), %xmm1     # 0x109160
movsd 0x355f8b(%rip), %xmm0   # 0x4528a8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x355f7f(%rip)   # 0x4528a8
movsd 0x355f7f(%rip), %xmm0   # 0x4528b0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x355f73(%rip)   # 0x4528b0
leaq 0x141a5c(%rip), %r12    # 0x23e3a0
movq (%r12), %rdi
testq %rdi, %rdi
je 0xfcab6
movl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
leaq 0x38de2(%rip), %rsi     # 0x135744
movb $0x1, %al
callq 0x9560
movq (%r12), %rbx
movsd 0x355f33(%rip), %xmm0   # 0x4528a8
movsd %xmm0, -0x38(%rbp)
movsd (%r15), %xmm1
mulsd 0xc7d9(%rip), %xmm1     # 0x109160
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
leaq 0x210622(%rip), %r15    # 0x30cfb8
divsd (%r15), %xmm2
movsd %xmm2, -0x30(%rbp)
leaq 0x210641(%rip), %rax    # 0x30cfe8
movsd (%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
callq 0xb4219
leaq 0x38daa(%rip), %rsi     # 0x135766
movq %rbx, %rdi
movsd -0x38(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movq %rax, %rdx
movb $0x3, %al
callq 0x9560
movq (%r12), %rbx
movsd 0x355ecc(%rip), %xmm2   # 0x4528b0
movsd %xmm2, -0x40(%rbp)
movsd (%r13), %xmm0
movsd 0xc769(%rip), %xmm1     # 0x109160
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm2
divsd (%r15), %xmm2
movsd %xmm2, -0x30(%rbp)
movsd 0x355e97(%rip), %xmm0   # 0x4528a8
divsd %xmm1, %xmm0
callq 0x9710
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
leaq 0x2105c1(%rip), %rax    # 0x30cff0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x355e70(%rip), %xmm0   # 0x4528b0
callq 0xb4219
leaq 0x38d47(%rip), %rsi     # 0x135793
movq %rbx, %rdi
movsd -0x40(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
movq %rax, %rdx
movb $0x3, %al
callq 0x9560
movq (%r12), %rdi
movsd 0x355e44(%rip), %xmm0   # 0x4528b8
movapd %xmm0, %xmm1
leaq 0x23e881(%rip), %rax    # 0x33b300
subsd (%rax), %xmm1
leaq 0x21056e(%rip), %rax    # 0x30cff8
movsd (%rax), %xmm2
leaq 0x38d2b(%rip), %rsi     # 0x1357c0
movb $0x3, %al
callq 0x9560
movq (%r12), %rcx
leaq 0x34ec6(%rip), %rdi     # 0x13196d
movl $0x2, %esi
movl $0x1, %edx
callq 0x9750
movsd 0x355e32(%rip), %xmm1   # 0x4528f0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jne 0xfcace
jnp 0xfcdb2
movsd 0x355e02(%rip), %xmm0   # 0x4528d8
ucomisd %xmm2, %xmm0
jne 0xfcae2
jnp 0xfcdb2
movsd 0x355df6(%rip), %xmm2   # 0x4528e0
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm2
jne 0xfcafa
jnp 0xfcdb2
movsd 0x355de6(%rip), %xmm3   # 0x4528e8
ucomisd %xmm4, %xmm3
jne 0xfcb0e
jnp 0xfcdb2
divsd %xmm1, %xmm0
movsd %xmm0, 0x355d8e(%rip)   # 0x4528a8
divsd %xmm1, %xmm2
movsd %xmm2, 0x355d8a(%rip)   # 0x4528b0
divsd %xmm1, %xmm3
movsd %xmm3, 0x355d86(%rip)   # 0x4528b8
leaq 0x23e7b7(%rip), %r13    # 0x33b2f0
movsd %xmm0, (%r13)
leaq 0x23e7b2(%rip), %r15    # 0x33b2f8
movsd %xmm2, (%r15)
leaq 0x23e7ae(%rip), %r14    # 0x33b300
movsd %xmm3, (%r14)
leaq 0x23e7aa(%rip), %rax    # 0x33b308
movl $0x3, (%rax)
leaq 0x23e7a5(%rip), %rax    # 0x33b310
movsd %xmm0, (%rax)
leaq 0x23e7a2(%rip), %rax    # 0x33b318
movsd %xmm2, (%rax)
leaq 0x23e79f(%rip), %rax    # 0x33b320
movsd %xmm3, (%rax)
callq 0x9710
xorpd %xmm1, %xmm1
cmpeqsd %xmm0, %xmm1
movsd 0xed95(%rip), %xmm2     # 0x10b930
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm1, %xmm2
leaq 0x21041a(%rip), %rax    # 0x30cfc8
movlpd %xmm2, (%rax)
movsd 0x355cee(%rip), %xmm0   # 0x4528a8
movsd 0x355cee(%rip), %xmm1   # 0x4528b0
movsd 0x355cee(%rip), %xmm2   # 0x4528b8
callq 0x5c8c0
movsd 0xc589(%rip), %xmm2     # 0x109160
movsd 0x355cc9(%rip), %xmm0   # 0x4528a8
mulsd %xmm2, %xmm0
movsd %xmm0, 0x355cbd(%rip)   # 0x4528a8
movsd 0x355cbd(%rip), %xmm1   # 0x4528b0
mulsd %xmm2, %xmm1
movsd %xmm1, 0x355cb1(%rip)   # 0x4528b0
leaq 0x14179a(%rip), %r12    # 0x23e3a0
movq (%r12), %rbx
testq %rbx, %rbx
je 0xfcdb7
movsd (%r13), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd (%r15), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, -0x38(%rbp)
movsd (%r14), %xmm1
movsd %xmm1, -0x40(%rbp)
divsd %xmm2, %xmm0
callq 0x9710
movapd %xmm0, %xmm3
leaq 0x38b97(%rip), %rsi     # 0x1357e5
movq %rbx, %rdi
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movb $0x4, %al
callq 0x9560
movq (%r12), %rdi
movsd 0x355c7d(%rip), %xmm0   # 0x4528f0
leaq 0x38b92(%rip), %rsi     # 0x13580c
movb $0x1, %al
callq 0x9560
movq (%r12), %rbx
movsd 0x355c1b(%rip), %xmm0   # 0x4528a8
movsd %xmm0, -0x38(%rbp)
movsd (%r13), %xmm1
mulsd 0xc4c0(%rip), %xmm1     # 0x109160
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
leaq 0x210309(%rip), %r13    # 0x30cfb8
divsd (%r13), %xmm2
movsd %xmm2, -0x30(%rbp)
leaq 0x210327(%rip), %rax    # 0x30cfe8
movsd (%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
callq 0xb4219
leaq 0x38a90(%rip), %rsi     # 0x135766
movq %rbx, %rdi
movsd -0x38(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movq %rax, %rdx
movb $0x3, %al
callq 0x9560
movq (%r12), %rbx
movsd 0x355bb2(%rip), %xmm2   # 0x4528b0
movsd %xmm2, -0x40(%rbp)
movsd (%r15), %xmm0
movsd 0xc450(%rip), %xmm1     # 0x109160
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm2
divsd (%r13), %xmm2
movsd %xmm2, -0x30(%rbp)
movsd 0x355b7d(%rip), %xmm0   # 0x4528a8
divsd %xmm1, %xmm0
callq 0x9710
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
leaq 0x2102a7(%rip), %rax    # 0x30cff0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x355b56(%rip), %xmm0   # 0x4528b0
callq 0xb4219
leaq 0x38a2d(%rip), %rsi     # 0x135793
movq %rbx, %rdi
movsd -0x40(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
movq %rax, %rdx
movb $0x3, %al
callq 0x9560
movq (%r12), %rdi
movsd 0x355b2a(%rip), %xmm0   # 0x4528b8
movapd %xmm0, %xmm1
subsd (%r14), %xmm1
leaq 0x21025a(%rip), %rax    # 0x30cff8
movsd (%rax), %xmm2
leaq 0x38a17(%rip), %rsi     # 0x1357c0
movb $0x3, %al
callq 0x9560
jmp 0xfcdb7
testl %r14d, %r14d
je 0xfcdcf
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xfb5cf
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq