// File: /workspace/github_cpp_makefile_star2_O1/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 0x23f219(%rip), %rbx    # 0x33b2e4
movl (%rbx), %eax
testl %eax, %eax
je 0xfc362
movsd 0x3568c3(%rip), %xmm0   # 0x4529a0
movl %eax, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x356898(%rip)   # 0x452988
movsd 0x3568b0(%rip), %xmm2   # 0x4529a8
divsd %xmm1, %xmm2
movsd %xmm2, 0x35688c(%rip)   # 0x452990
movsd 0x3568a4(%rip), %xmm3   # 0x4529b0
divsd %xmm1, %xmm3
movsd %xmm3, 0x356880(%rip)   # 0x452998
leaq 0x23f1d1(%rip), %r15    # 0x33b2f0
movsd %xmm0, (%r15)
leaq 0x23f1cd(%rip), %r13    # 0x33b2f8
movsd %xmm2, (%r13)
leaq 0x23f1c8(%rip), %rax    # 0x33b300
movsd %xmm3, (%rax)
leaq 0x23f1c5(%rip), %rax    # 0x33b308
movl $0x2, (%rax)
leaq 0x23f1c0(%rip), %rax    # 0x33b310
movsd %xmm0, (%rax)
leaq 0x23f1bd(%rip), %rax    # 0x33b318
movsd %xmm2, (%rax)
leaq 0x23f1ba(%rip), %rax    # 0x33b320
movsd %xmm3, (%rax)
callq 0x9710
xorpd %xmm1, %xmm1
cmpeqsd %xmm0, %xmm1
movsd 0xf7a8(%rip), %xmm2     # 0x10b928
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm1, %xmm2
leaq 0x210e35(%rip), %rax    # 0x30cfc8
movlpd %xmm2, (%rax)
movsd 0x3567e9(%rip), %xmm0   # 0x452988
movsd 0x3567e9(%rip), %xmm1   # 0x452990
movsd 0x3567e9(%rip), %xmm2   # 0x452998
callq 0x5c9da
movsd 0xcf9c(%rip), %xmm1     # 0x109158
movsd 0x3567c4(%rip), %xmm0   # 0x452988
mulsd %xmm1, %xmm0
movsd %xmm0, 0x3567b8(%rip)   # 0x452988
movsd 0x3567b8(%rip), %xmm0   # 0x452990
mulsd %xmm1, %xmm0
movsd %xmm0, 0x3567ac(%rip)   # 0x452990
leaq 0x1421b5(%rip), %r12    # 0x23e3a0
movq (%r12), %rdi
testq %rdi, %rdi
je 0xfc367
movl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
leaq 0x3944b(%rip), %rsi     # 0x135654
movb $0x1, %r14b
movb $0x1, %al
callq 0x9560
movq (%r12), %rbx
movsd 0x356769(%rip), %xmm0   # 0x452988
movsd %xmm0, -0x38(%rbp)
movsd (%r15), %xmm1
mulsd 0xcf27(%rip), %xmm1     # 0x109158
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
leaq 0x210d78(%rip), %r15    # 0x30cfb8
divsd (%r15), %xmm2
movsd %xmm2, -0x30(%rbp)
leaq 0x210d97(%rip), %rax    # 0x30cfe8
movsd (%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
callq 0xb3db9
leaq 0x39410(%rip), %rsi     # 0x135676
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 0x356702(%rip), %xmm2   # 0x452990
movsd %xmm2, -0x40(%rbp)
movsd (%r13), %xmm0
movsd 0xceb7(%rip), %xmm1     # 0x109158
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm2
divsd (%r15), %xmm2
movsd %xmm2, -0x30(%rbp)
movsd 0x3566cd(%rip), %xmm0   # 0x452988
divsd %xmm1, %xmm0
callq 0x9710
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
leaq 0x210d17(%rip), %rax    # 0x30cff0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x3566a6(%rip), %xmm0   # 0x452990
callq 0xb3db9
leaq 0x393ad(%rip), %rsi     # 0x1356a3
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 0x35667a(%rip), %xmm0   # 0x452998
movapd %xmm0, %xmm1
leaq 0x23efd7(%rip), %rax    # 0x33b300
subsd (%rax), %xmm1
leaq 0x210cc4(%rip), %rax    # 0x30cff8
movsd (%rax), %xmm2
leaq 0x39391(%rip), %rsi     # 0x1356d0
movb $0x3, %al
callq 0x9560
movq (%r12), %rcx
leaq 0x3552c(%rip), %rdi     # 0x13187d
movl $0x2, %esi
movl $0x1, %edx
callq 0x9750
jmp 0xfc36a
xorl %r14d, %r14d
jmp 0xfc36a
movb $0x1, %r14b
movsd 0x35665e(%rip), %xmm2   # 0x4529d0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
jne 0xfc382
jnp 0xfc670
movsd 0x35662e(%rip), %xmm0   # 0x4529b8
ucomisd %xmm1, %xmm0
jne 0xfc396
jnp 0xfc670
movsd 0x356622(%rip), %xmm1   # 0x4529c0
xorpd %xmm4, %xmm4
ucomisd %xmm4, %xmm1
jne 0xfc3ae
jnp 0xfc670
movsd 0x356612(%rip), %xmm3   # 0x4529c8
ucomisd %xmm4, %xmm3
jne 0xfc3c2
jnp 0xfc670
divsd %xmm2, %xmm0
movsd %xmm0, 0x3565ba(%rip)   # 0x452988
divsd %xmm2, %xmm1
movsd %xmm1, 0x3565b6(%rip)   # 0x452990
divsd %xmm2, %xmm3
movsd %xmm3, 0x3565b2(%rip)   # 0x452998
leaq 0x23ef03(%rip), %r15    # 0x33b2f0
movsd %xmm0, (%r15)
leaq 0x23eeff(%rip), %r12    # 0x33b2f8
movsd %xmm1, (%r12)
leaq 0x23eefa(%rip), %r14    # 0x33b300
movsd %xmm3, (%r14)
leaq 0x23eef6(%rip), %rax    # 0x33b308
movl $0x3, (%rax)
leaq 0x23eef1(%rip), %rax    # 0x33b310
movsd %xmm0, (%rax)
leaq 0x23eeee(%rip), %rax    # 0x33b318
movsd %xmm1, (%rax)
leaq 0x23eeeb(%rip), %rax    # 0x33b320
movsd %xmm3, (%rax)
callq 0x9710
xorpd %xmm1, %xmm1
cmpeqsd %xmm0, %xmm1
movsd 0xf4d9(%rip), %xmm2     # 0x10b928
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm1, %xmm2
leaq 0x210b66(%rip), %rax    # 0x30cfc8
movlpd %xmm2, (%rax)
movsd 0x35651a(%rip), %xmm0   # 0x452988
movsd 0x35651a(%rip), %xmm1   # 0x452990
movsd 0x35651a(%rip), %xmm2   # 0x452998
callq 0x5c9da
movsd 0xcccd(%rip), %xmm2     # 0x109158
movsd 0x3564f5(%rip), %xmm0   # 0x452988
mulsd %xmm2, %xmm0
movsd %xmm0, 0x3564e9(%rip)   # 0x452988
movsd 0x3564e9(%rip), %xmm1   # 0x452990
mulsd %xmm2, %xmm1
movsd %xmm1, 0x3564dd(%rip)   # 0x452990
leaq 0x141ee6(%rip), %r13    # 0x23e3a0
movq (%r13), %rbx
testq %rbx, %rbx
je 0xfc66d
movsd (%r15), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd (%r12), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, -0x38(%rbp)
movsd (%r14), %xmm1
movsd %xmm1, -0x40(%rbp)
divsd %xmm2, %xmm0
callq 0x9710
movapd %xmm0, %xmm3
leaq 0x391f3(%rip), %rsi     # 0x1356f5
movq %rbx, %rdi
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movb $0x4, %al
callq 0x9560
movq (%r13), %rdi
movsd 0x3564a9(%rip), %xmm0   # 0x4529d0
leaq 0x391ee(%rip), %rsi     # 0x13571c
movb $0x1, %r14b
movb $0x1, %al
callq 0x9560
movq (%r13), %rbx
movsd 0x356444(%rip), %xmm0   # 0x452988
movsd %xmm0, -0x38(%rbp)
movsd (%r15), %xmm1
mulsd 0xcc02(%rip), %xmm1     # 0x109158
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
leaq 0x210a53(%rip), %r15    # 0x30cfb8
divsd (%r15), %xmm2
movsd %xmm2, -0x30(%rbp)
leaq 0x210a72(%rip), %rax    # 0x30cfe8
movsd (%rax), %xmm1
movsd %xmm1, -0x40(%rbp)
callq 0xb3db9
leaq 0x390eb(%rip), %rsi     # 0x135676
movq %rbx, %rdi
movsd -0x38(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
movq %rax, %rdx
movb $0x3, %al
callq 0x9560
movq (%r13), %rbx
movsd 0x3563dd(%rip), %xmm2   # 0x452990
movsd %xmm2, -0x40(%rbp)
movsd (%r12), %xmm0
movsd 0xcb92(%rip), %xmm1     # 0x109158
mulsd %xmm1, %xmm0
subsd %xmm0, %xmm2
divsd (%r15), %xmm2
movsd %xmm2, -0x30(%rbp)
movsd 0x3563a8(%rip), %xmm0   # 0x452988
divsd %xmm1, %xmm0
callq 0x9710
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
leaq 0x2109f2(%rip), %rax    # 0x30cff0
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x356381(%rip), %xmm0   # 0x452990
callq 0xb3db9
leaq 0x39088(%rip), %rsi     # 0x1356a3
movq %rbx, %rdi
movsd -0x40(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
movq %rax, %rdx
movb $0x3, %al
callq 0x9560
movq (%r13), %rdi
movsd 0x356355(%rip), %xmm0   # 0x452998
movapd %xmm0, %xmm1
leaq 0x23ecb2(%rip), %rax    # 0x33b300
subsd (%rax), %xmm1
leaq 0x21099f(%rip), %rax    # 0x30cff8
movsd (%rax), %xmm2
leaq 0x3906c(%rip), %rsi     # 0x1356d0
movb $0x3, %al
callq 0x9560
jmp 0xfc670
movb $0x1, %r14b
testb %r14b, %r14b
je 0xfc68d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xfae54
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq