// File: 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
subq $0xc0, %rsp
movb $0x0, -0x1(%rbp)
leaq 0x23e74e(%rip), %rax    # 0x39a4c4
cmpl $0x0, (%rax)
je 0x15c0fd
movsd 0x356129(%rip), %xmm0   # 0x4b1eb0
leaq 0x23e736(%rip), %rax    # 0x39a4c4
movl (%rax), %ecx
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x3560f7(%rip)   # 0x4b1e98
movsd 0x35610f(%rip), %xmm0   # 0x4b1eb8
movl (%rax), %ecx
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x3560e4(%rip)   # 0x4b1ea0
movsd 0x3560fc(%rip), %xmm0   # 0x4b1ec0
movl (%rax), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x3560d1(%rip)   # 0x4b1ea8
movsd 0x3560b9(%rip), %xmm0   # 0x4b1e98
leaq 0x23e6ea(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
movsd 0x3560ae(%rip), %xmm0   # 0x4b1ea0
leaq 0x23e6df(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
movsd 0x3560a3(%rip), %xmm0   # 0x4b1ea8
leaq 0x23e6d4(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
leaq 0x23e6d1(%rip), %rax    # 0x39a4e8
movl $0x2, (%rax)
leaq 0x23e6ac(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
leaq 0x23e6c1(%rip), %rax    # 0x39a4f0
movsd %xmm0, (%rax)
leaq 0x23e69e(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm0
leaq 0x23e6b3(%rip), %rax    # 0x39a4f8
movsd %xmm0, (%rax)
leaq 0x23e690(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm0
leaq 0x23e6a5(%rip), %rax    # 0x39a500
movsd %xmm0, (%rax)
leaq 0x23e68a(%rip), %rax    # 0x39a4f0
movsd (%rax), %xmm0
callq 0x96f0
leaq 0x210332(%rip), %rax    # 0x36c1a8
movsd %xmm0, (%rax)
leaq 0x210327(%rip), %rax    # 0x36c1a8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15bea3
jp 0x15bea3
leaq 0x210311(%rip), %rax    # 0x36c1a8
movsd 0x132f1(%rip), %xmm0    # 0x16f190
movsd %xmm0, (%rax)
movsd 0x355fed(%rip), %xmm0   # 0x4b1e98
movsd 0x355fed(%rip), %xmm1   # 0x4b1ea0
movsd 0x355fed(%rip), %xmm2   # 0x4b1ea8
callq 0x7fcf0
movsd 0x132b8(%rip), %xmm0    # 0x16f180
mulsd 0x355fc8(%rip), %xmm0   # 0x4b1e98
movsd %xmm0, 0x355fc0(%rip)   # 0x4b1e98
movsd 0x132a0(%rip), %xmm0    # 0x16f180
mulsd 0x355fb8(%rip), %xmm0   # 0x4b1ea0
movsd %xmm0, 0x355fb0(%rip)   # 0x4b1ea0
leaq 0x141689(%rip), %rax    # 0x29d580
cmpq $0x0, (%rax)
je 0x15c0f3
leaq 0x141678(%rip), %rax    # 0x29d580
movq (%rax), %rdi
leaq 0x23e5b2(%rip), %rax    # 0x39a4c4
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
leaq 0x3c3b6(%rip), %rsi     # 0x1982d6
movb $0x1, %al
callq 0x9550
leaq 0x141652(%rip), %rax    # 0x29d580
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movsd 0x355f5b(%rip), %xmm0   # 0x4b1e98
movsd %xmm0, -0x48(%rbp)
movsd 0x355f4e(%rip), %xmm1   # 0x4b1e98
leaq 0x23e57f(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x1320c(%rip), %xmm2    # 0x16f180
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
leaq 0x210215(%rip), %rax    # 0x36c198
divsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq 0x210235(%rip), %rax    # 0x36c1c8
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x355ef4(%rip), %xmm0   # 0x4b1e98
callq 0xf4d40
movq -0x50(%rbp), %rdi
movsd -0x48(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
movq %rax, %rdx
leaq 0x3c332(%rip), %rsi     # 0x1982f8
movb $0x3, %al
callq 0x9550
leaq 0x1415ac(%rip), %rax    # 0x29d580
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movsd 0x355ebd(%rip), %xmm0   # 0x4b1ea0
movsd %xmm0, -0x20(%rbp)
movsd 0x355eb0(%rip), %xmm1   # 0x4b1ea0
leaq 0x23e4e1(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x13166(%rip), %xmm2    # 0x16f180
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
leaq 0x21016f(%rip), %rax    # 0x36c198
divsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x355e5e(%rip), %xmm0   # 0x4b1e98
movsd 0x1313e(%rip), %xmm1    # 0x16f180
divsd %xmm1, %xmm0
callq 0x96f0
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0x21016d(%rip), %rax    # 0x36c1d0
movsd (%rax), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x355e2c(%rip), %xmm0   # 0x4b1ea0
callq 0xf4d40
movq -0x28(%rbp), %rdi
movsd -0x20(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
movsd -0x10(%rbp), %xmm2
movq %rax, %rdx
leaq 0x3c28f(%rip), %rsi     # 0x198325
movb $0x3, %al
callq 0x9550
leaq 0x1414dc(%rip), %rax    # 0x29d580
movq (%rax), %rdi
movsd 0x355df9(%rip), %xmm0   # 0x4b1ea8
movsd 0x355df1(%rip), %xmm1   # 0x4b1ea8
leaq 0x23e422(%rip), %rax    # 0x39a4e0
subsd (%rax), %xmm1
leaq 0x21010f(%rip), %rax    # 0x36c1d8
movsd (%rax), %xmm2
leaq 0x3c27e(%rip), %rsi     # 0x198352
movb $0x3, %al
callq 0x9550
leaq 0x14149e(%rip), %rax    # 0x29d580
movq (%rax), %rdi
leaq 0x3837d(%rip), %rsi     # 0x194469
movb $0x0, %al
callq 0x9550
movzbl -0x1(%rbp), %eax
orl $0x1, %eax
movb %al, -0x1(%rbp)
movsd 0x355ddb(%rip), %xmm0   # 0x4b1ee0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15c115
jp 0x15c115
jmp 0x15c559
movsd 0x355dab(%rip), %xmm0   # 0x4b1ec8
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15c12d
jp 0x15c12d
jmp 0x15c559
movsd 0x355d9b(%rip), %xmm0   # 0x4b1ed0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15c145
jp 0x15c145
jmp 0x15c559
movsd 0x355d8b(%rip), %xmm0   # 0x4b1ed8
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15c15d
jp 0x15c15d
jmp 0x15c559
movsd 0x355d63(%rip), %xmm0   # 0x4b1ec8
divsd 0x355d73(%rip), %xmm0   # 0x4b1ee0
movsd %xmm0, 0x355d23(%rip)   # 0x4b1e98
movsd 0x355d53(%rip), %xmm0   # 0x4b1ed0
divsd 0x355d5b(%rip), %xmm0   # 0x4b1ee0
movsd %xmm0, 0x355d13(%rip)   # 0x4b1ea0
movsd 0x355d43(%rip), %xmm0   # 0x4b1ed8
divsd 0x355d43(%rip), %xmm0   # 0x4b1ee0
movsd %xmm0, 0x355d03(%rip)   # 0x4b1ea8
movsd 0x355ceb(%rip), %xmm0   # 0x4b1e98
leaq 0x23e31c(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
movsd 0x355ce0(%rip), %xmm0   # 0x4b1ea0
leaq 0x23e311(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
movsd 0x355cd5(%rip), %xmm0   # 0x4b1ea8
leaq 0x23e306(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
leaq 0x23e303(%rip), %rax    # 0x39a4e8
movl $0x3, (%rax)
movsd 0x355ca5(%rip), %xmm0   # 0x4b1e98
leaq 0x23e2f6(%rip), %rax    # 0x39a4f0
movsd %xmm0, (%rax)
movsd 0x355c9a(%rip), %xmm0   # 0x4b1ea0
leaq 0x23e2eb(%rip), %rax    # 0x39a4f8
movsd %xmm0, (%rax)
movsd 0x355c8f(%rip), %xmm0   # 0x4b1ea8
leaq 0x23e2e0(%rip), %rax    # 0x39a500
movsd %xmm0, (%rax)
leaq 0x23e2c5(%rip), %rax    # 0x39a4f0
movsd (%rax), %xmm0
callq 0x96f0
leaq 0x20ff6d(%rip), %rax    # 0x36c1a8
movsd %xmm0, (%rax)
leaq 0x20ff62(%rip), %rax    # 0x36c1a8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15c268
jp 0x15c268
leaq 0x20ff4c(%rip), %rax    # 0x36c1a8
movsd 0x12f2c(%rip), %xmm0    # 0x16f190
movsd %xmm0, (%rax)
movsd 0x355c28(%rip), %xmm0   # 0x4b1e98
movsd 0x355c28(%rip), %xmm1   # 0x4b1ea0
movsd 0x355c28(%rip), %xmm2   # 0x4b1ea8
callq 0x7fcf0
movsd 0x12ef3(%rip), %xmm0    # 0x16f180
mulsd 0x355c03(%rip), %xmm0   # 0x4b1e98
movsd %xmm0, 0x355bfb(%rip)   # 0x4b1e98
movsd 0x12edb(%rip), %xmm0    # 0x16f180
mulsd 0x355bf3(%rip), %xmm0   # 0x4b1ea0
movsd %xmm0, 0x355beb(%rip)   # 0x4b1ea0
leaq 0x1412c4(%rip), %rax    # 0x29d580
cmpq $0x0, (%rax)
je 0x15c54f
leaq 0x1412b3(%rip), %rax    # 0x29d580
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movsd 0x12ea1(%rip), %xmm0    # 0x16f180
leaq 0x23e1ea(%rip), %rax    # 0x39a4d0
mulsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd 0x12e86(%rip), %xmm0    # 0x16f180
leaq 0x23e1d7(%rip), %rax    # 0x39a4d8
mulsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq 0x23e1cc(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd 0x355b70(%rip), %xmm0   # 0x4b1e98
movsd 0x12e50(%rip), %xmm1    # 0x16f180
divsd %xmm1, %xmm0
callq 0x96f0
movq -0xb8(%rbp), %rdi
movsd -0xb0(%rbp), %xmm1
movsd -0xa8(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xa0(%rbp), %xmm0
leaq 0x3c015(%rip), %rsi     # 0x198377
movb $0x4, %al
callq 0x9550
leaq 0x141210(%rip), %rax    # 0x29d580
movq (%rax), %rdi
movsd 0x355b65(%rip), %xmm0   # 0x4b1ee0
leaq 0x3c01c(%rip), %rsi     # 0x19839e
movb $0x1, %al
callq 0x9550
leaq 0x1411f0(%rip), %rax    # 0x29d580
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movsd 0x355af6(%rip), %xmm0   # 0x4b1e98
movsd %xmm0, -0x90(%rbp)
movsd 0x355ae6(%rip), %xmm1   # 0x4b1e98
leaq 0x23e117(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x12da4(%rip), %xmm2    # 0x16f180
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
leaq 0x20fdad(%rip), %rax    # 0x36c198
divsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
leaq 0x20fdca(%rip), %rax    # 0x36c1c8
movsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x355a89(%rip), %xmm0   # 0x4b1e98
callq 0xf4d40
movq -0x98(%rbp), %rdi
movsd -0x90(%rbp), %xmm0
movsd -0x88(%rbp), %xmm1
movsd -0x80(%rbp), %xmm2
movq %rax, %rdx
leaq 0x3bebe(%rip), %rsi     # 0x1982f8
movb $0x3, %al
callq 0x9550
leaq 0x141138(%rip), %rax    # 0x29d580
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movsd 0x355a49(%rip), %xmm0   # 0x4b1ea0
movsd %xmm0, -0x68(%rbp)
movsd 0x355a3c(%rip), %xmm1   # 0x4b1ea0
leaq 0x23e06d(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x12cf2(%rip), %xmm2    # 0x16f180
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
leaq 0x20fcfb(%rip), %rax    # 0x36c198
divsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd 0x3559ea(%rip), %xmm0   # 0x4b1e98
movsd 0x12cca(%rip), %xmm1    # 0x16f180
divsd %xmm1, %xmm0
callq 0x96f0
movaps %xmm0, %xmm1
movsd -0x78(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
leaq 0x20fcf9(%rip), %rax    # 0x36c1d0
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x3559b8(%rip), %xmm0   # 0x4b1ea0
callq 0xf4d40
movq -0x70(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
movq %rax, %rdx
leaq 0x3be1b(%rip), %rsi     # 0x198325
movb $0x3, %al
callq 0x9550
leaq 0x141068(%rip), %rax    # 0x29d580
movq (%rax), %rdi
movsd 0x355985(%rip), %xmm0   # 0x4b1ea8
movsd 0x35597d(%rip), %xmm1   # 0x4b1ea8
leaq 0x23dfae(%rip), %rax    # 0x39a4e0
subsd (%rax), %xmm1
leaq 0x20fc9b(%rip), %rax    # 0x36c1d8
movsd (%rax), %xmm2
leaq 0x3be0a(%rip), %rsi     # 0x198352
movb $0x3, %al
callq 0x9550
movzbl -0x1(%rbp), %eax
orl $0x2, %eax
movb %al, -0x1(%rbp)
cmpb $0x0, -0x1(%rbp)
je 0x15c569
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x15a450
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)