// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: save_precise_posn(int)
void save_precise_posn(int quick_save)
{
   // see if single precision TSIP message position will be close enough 
   // !!!! resolution_SMT does not update lla values during survey, can't do precise save
   if(lla_file) {
      fprintf(lla_file, "### save_precise_position(%d)\n", quick_save);
      fprintf(lla_file, "### precise lla:%.9f %.9f %.3f\n", precise_lat*180.0/PI, precise_lon*180.0/PI, precise_alt);
      fprintf(lla_file, "### precise lat:%s\n", dms_fmt(precise_lat*180.0/PI));
      fprintf(lla_file, "### precise lon:%s\n", dms_fmt(precise_lon*180.0/PI));

      lla_to_ecef(precise_lat,precise_lon,precise_alt);
      fprintf(lla_file, "### precise ecef x:%.5f y:%.5f z:%.5f\n", ecef_x, ecef_y, ecef_z);
   }

// medsurv
   if((res_t && (res_t != RES_T))) quick_save = 1;
   else if(rcvr_type != TSIP_RCVR) quick_save = 1;

   if((quick_save >= 0) || (1 && (float_error(precise_lat) < LAT_THRESH) && (float_error(precise_lon) < LON_THRESH))) {
      stop_self_survey(2);  // abort standard survey
      check_precise_posn = 0;
      set_lla(precise_lat, precise_lon, precise_alt);

      if(NO_EEPROM_CMDS) ;
      else {
         save_segment(7, 11);     // save the position in EEPROM
         log_saved_posn(quick_save);
         sprintf(log_text, "# Saved precise position directly");
         if(lla_file) fprintf(lla_file, "%s\n", log_text);
         write_log_comment(1);
         if(SCREEN_WIDTH > NARROW_SCREEN) lla_header("Precise survey complete  ", WHITE);
         else                             lla_header("Survey complete  ", WHITE);
      }
      close_lla_file(2);
      precise_survey_done = 1;
      trimble_save = 0;
   }
   else {  // single/double precision difference is too big, do single point surveys until we get close
      set_survey_params(1, 0, 1L);  // config for single fix survey, don't save position
      start_self_survey(0x00, 3);   // start the survey

      check_precise_posn = 1;       // we are looking for a fix very close to where we are
      check_delay = 4;
      plot_lla = 4;                 // prepare to plot the search attempts
      plot_azel = 1;
      update_azel = 1;
      if(WIDE_SCREEN == 0) {
         shared_plot = 1; 
         if(rcvr_type == TICC_RCVR) all_adevs = ALL_CHANS;
         else                       all_adevs = SINGLE_ADEVS;
      }
      config_screen(42);
      if(SCREEN_WIDTH > NARROW_SCREEN) lla_header("Saving precise position  ", YELLOW);
      else                             lla_header("Saving position    ", YELLOW);
      refresh_page();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x142dba(%rip), %r15    # 0x23e3a0
movq (%r15), %rdi
testq %rdi, %rdi
je 0xfb70a
leaq 0x39e3c(%rip), %rsi     # 0x135435
movl %ebx, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
leaq 0x23fce4(%rip), %r12    # 0x33b2f0
movsd 0x1021c(%rip), %xmm2    # 0x10b830
movsd (%r12), %xmm0
mulsd %xmm2, %xmm0
movsd 0x10202(%rip), %xmm3    # 0x10b828
divsd %xmm3, %xmm0
leaq 0x23fcc7(%rip), %r13    # 0x33b2f8
movsd (%r13), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm3, %xmm1
leaq 0x23fcba(%rip), %rax    # 0x33b300
movsd (%rax), %xmm2
leaq 0x39e03(%rip), %rsi     # 0x135454
movb $0x3, %al
callq 0x9560
movq (%r15), %r14
movsd (%r12), %xmm0
mulsd 0x101c7(%rip), %xmm0    # 0x10b830
divsd 0x101b7(%rip), %xmm0    # 0x10b828
callq 0xb4219
leaq 0x39df7(%rip), %rsi     # 0x135474
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9560
movq (%r15), %r14
movsd 0x1019b(%rip), %xmm0    # 0x10b830
mulsd (%r13), %xmm0
divsd 0x10185(%rip), %xmm0    # 0x10b828
callq 0xb4219
leaq 0x39dd9(%rip), %rsi     # 0x135488
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9560
movsd (%r12), %xmm0
movsd (%r13), %xmm1
leaq 0x23fc31(%rip), %rax    # 0x33b300
movsd (%rax), %xmm2
callq 0x5c8c0
movq (%r15), %rdi
leaq 0x211906(%rip), %rax    # 0x30cfe8
movsd (%rax), %xmm0
leaq 0x211903(%rip), %rax    # 0x30cff0
movsd (%rax), %xmm1
leaq 0x211900(%rip), %rax    # 0x30cff8
movsd (%rax), %xmm2
leaq 0x39d99(%rip), %rsi     # 0x13549c
movb $0x3, %al
callq 0x9560
leaq 0x11d1f3(%rip), %rax    # 0x218904
leaq 0x11d1b8(%rip), %r14    # 0x2188d0
cmpq $0x1, (%r14)
movl $0x1, %ecx
cmovnel %ecx, %ebx
cmpb $0x2, (%rax)
cmovael %ecx, %ebx
testl %ebx, %ebx
js 0xfb85c
movl $0x2, %edi
callq 0x71618
leaq 0x23fb9d(%rip), %rax    # 0x33b2e0
movb $0x0, (%rax)
leaq 0x23fba3(%rip), %rax    # 0x33b2f0
movsd (%rax), %xmm0
leaq 0x23fba0(%rip), %rax    # 0x33b2f8
movsd (%rax), %xmm1
leaq 0x23fb9d(%rip), %rax    # 0x33b300
movsd (%rax), %xmm2
callq 0x674dc
testl $0xc40cb04, 0x1(%r14)   # imm = 0xC40CB04
jne 0xfb822
movl $0x7, %edi
movl $0xb, %esi
callq 0x6a4ce
movl %ebx, %edi
callq 0xd3b42
leaq 0x1421c9(%rip), %rax    # 0x23d960
movups 0x39d35(%rip), %xmm0    # 0x1354d3
movaps %xmm0, 0x10(%rax)
movups 0x39d1a(%rip), %xmm0    # 0x1354c3
movaps %xmm0, (%rax)
movw $0x79, 0x20(%rax)
movq (%r15), %rdi
testq %rdi, %rdi
je 0xfb7cf
leaq 0x2a316(%rip), %rsi     # 0x125ad7
leaq 0x142198(%rip), %rdx    # 0x23d960
xorl %eax, %eax
callq 0x9560
movl $0x1, %edi
callq 0xc36e2
leaq 0x11d020(%rip), %rax    # 0x218800
leaq 0x127d5d(%rip), %rcx    # 0x223544
imull $0x31a, (%rcx), %ecx    # imm = 0x31A
movslq %ecx, %rcx
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x25, %rcx
addl %edx, %ecx
cmpl %ecx, (%rax)
leaq 0x39cd8(%rip), %rax     # 0x1354e5
leaq 0x39ceb(%rip), %rdi     # 0x1354ff
cmovgq %rax, %rdi
movl $0xf, %esi
callq 0xfb514
movq (%r15), %rdi
testq %rdi, %rdi
je 0xfb836
callq 0x9370
movq $0x0, (%r15)
leaq 0x21265d(%rip), %rax    # 0x30de9a
movb $0x1, (%rax)
leaq 0x212655(%rip), %rax    # 0x30de9c
movl $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23fa8d(%rip), %rax    # 0x33b2f0
movsd (%rax), %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
subsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
xorpd %xmm2, %xmm2
subsd %xmm1, %xmm2
movapd %xmm1, %xmm3
cmpltsd %xmm0, %xmm3
andpd %xmm3, %xmm2
andnpd %xmm1, %xmm3
orpd %xmm2, %xmm3
leaq 0x21171a(%rip), %rax    # 0x30cfb8
movsd (%rax), %xmm1
divsd 0xd8b6(%rip), %xmm1     # 0x109160
ucomisd %xmm3, %xmm1
jbe 0xfb8ed
leaq 0x23fa41(%rip), %rax    # 0x33b2f8
movsd (%rax), %xmm2
xorps %xmm3, %xmm3
cvtsd2ss %xmm2, %xmm3
cvtss2sd %xmm3, %xmm3
subsd %xmm3, %xmm2
movapd %xmm2, %xmm3
cmpltsd %xmm0, %xmm3
subsd %xmm2, %xmm0
andpd %xmm3, %xmm0
andnpd %xmm2, %xmm3
orpd %xmm0, %xmm3
ucomisd %xmm3, %xmm1
ja 0xfb732
movl $0x1, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x714be
xorl %edi, %edi
movl $0x3, %esi
callq 0x6c6a4
leaq 0x23f9cf(%rip), %rax    # 0x33b2e0
movb $0x1, %cl
movb %cl, (%rax)
leaq 0x23f9c5(%rip), %rax    # 0x33b2e1
movb $0x4, %dl
movb %dl, (%rax)
leaq 0x23f989(%rip), %rax    # 0x33b2b0
movb %dl, (%rax)
leaq 0x11fae3(%rip), %rax    # 0x21b413
movb %cl, (%rax)
leaq 0x11fadb(%rip), %rax    # 0x21b414
movb %cl, (%rax)
leaq 0x11cebe(%rip), %rbx    # 0x218800
cmpl $0x68f, (%rbx)          # imm = 0x68F
jg 0xfb96c
leaq 0x23fa97(%rip), %rax    # 0x33b3e8
movb $0x1, (%rax)
xorl %eax, %eax
cmpq $0x10000, (%r14)        # imm = 0x10000
sete %al
leal (%rax,%rax,4), %eax
leaq 0x1413d4(%rip), %rcx    # 0x23cd3e
movb %al, (%rcx)
movl $0x2a, %edi
callq 0xcf89
leaq 0x127bc7(%rip), %rax    # 0x223544
imull $0x31a, (%rax), %eax    # imm = 0x31A
cltq
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x25, %rax
addl %ecx, %eax
cmpl %eax, (%rbx)
leaq 0x39b6f(%rip), %rax     # 0x135511
leaq 0x39b82(%rip), %rdi     # 0x13552b
cmovgq %rax, %rdi
movl $0xe, %esi
callq 0xfb514
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xab54