// File: /workspace/github_cpp_makefile_star2_O1/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 0x143535(%rip), %r15    # 0x23e3a0
movq (%r15), %rdi
testq %rdi, %rdi
je 0xfaf8f
leaq 0x3a4c7(%rip), %rsi     # 0x135345
movl %ebx, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
leaq 0x24045f(%rip), %r12    # 0x33b2f0
movsd 0x10987(%rip), %xmm2    # 0x10b820
movsd (%r12), %xmm0
mulsd %xmm2, %xmm0
movsd 0x1096d(%rip), %xmm3    # 0x10b818
divsd %xmm3, %xmm0
leaq 0x240442(%rip), %r13    # 0x33b2f8
movsd (%r13), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm3, %xmm1
leaq 0x240435(%rip), %rax    # 0x33b300
movsd (%rax), %xmm2
leaq 0x3a48e(%rip), %rsi     # 0x135364
movb $0x3, %al
callq 0x9560
movq (%r15), %r14
movsd (%r12), %xmm0
mulsd 0x10932(%rip), %xmm0    # 0x10b820
divsd 0x10922(%rip), %xmm0    # 0x10b818
callq 0xb3db9
leaq 0x3a482(%rip), %rsi     # 0x135384
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9560
movq (%r15), %r14
movsd 0x10906(%rip), %xmm0    # 0x10b820
mulsd (%r13), %xmm0
divsd 0x108f0(%rip), %xmm0    # 0x10b818
callq 0xb3db9
leaq 0x3a464(%rip), %rsi     # 0x135398
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9560
movsd (%r12), %xmm0
movsd (%r13), %xmm1
leaq 0x2403ac(%rip), %rax    # 0x33b300
movsd (%rax), %xmm2
callq 0x5c9da
movq (%r15), %rdi
leaq 0x212081(%rip), %rax    # 0x30cfe8
movsd (%rax), %xmm0
leaq 0x21207e(%rip), %rax    # 0x30cff0
movsd (%rax), %xmm1
leaq 0x21207b(%rip), %rax    # 0x30cff8
movsd (%rax), %xmm2
leaq 0x3a424(%rip), %rsi     # 0x1353ac
movb $0x3, %al
callq 0x9560
leaq 0x11d96e(%rip), %rax    # 0x218904
leaq 0x11d933(%rip), %r14    # 0x2188d0
cmpq $0x1, (%r14)
movl $0x1, %ecx
cmovnel %ecx, %ebx
cmpb $0x2, (%rax)
cmovael %ecx, %ebx
testl %ebx, %ebx
js 0xfb0e1
movl $0x2, %edi
callq 0x715ee
leaq 0x240318(%rip), %rax    # 0x33b2e0
movb $0x0, (%rax)
leaq 0x24031e(%rip), %rax    # 0x33b2f0
movsd (%rax), %xmm0
leaq 0x24031b(%rip), %rax    # 0x33b2f8
movsd (%rax), %xmm1
leaq 0x240318(%rip), %rax    # 0x33b300
movsd (%rax), %xmm2
callq 0x67349
testl $0xc40cb04, 0x1(%r14)   # imm = 0xC40CB04
jne 0xfb0a7
movl $0x7, %edi
movl $0xb, %esi
callq 0x6a306
movl %ebx, %edi
callq 0xd340d
leaq 0x142944(%rip), %rax    # 0x23d960
movups 0x3a3c0(%rip), %xmm0    # 0x1353e3
movaps %xmm0, 0x10(%rax)
movups 0x3a3a5(%rip), %xmm0    # 0x1353d3
movaps %xmm0, (%rax)
movw $0x79, 0x20(%rax)
movq (%r15), %rdi
testq %rdi, %rdi
je 0xfb054
leaq 0x2a9b1(%rip), %rsi     # 0x1259f7
leaq 0x142913(%rip), %rdx    # 0x23d960
xorl %eax, %eax
callq 0x9560
movl $0x1, %edi
callq 0xc3105
leaq 0x11d79b(%rip), %rax    # 0x218800
leaq 0x1284d8(%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 0x3a363(%rip), %rax     # 0x1353f5
leaq 0x3a376(%rip), %rdi     # 0x13540f
cmovgq %rax, %rdi
movl $0xf, %esi
callq 0xfad99
movq (%r15), %rdi
testq %rdi, %rdi
je 0xfb0bb
callq 0x9370
movq $0x0, (%r15)
leaq 0x212dd8(%rip), %rax    # 0x30de9a
movb $0x1, (%rax)
leaq 0x212dd0(%rip), %rax    # 0x30de9c
movl $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x240208(%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 0x211e95(%rip), %rax    # 0x30cfb8
movsd (%rax), %xmm1
divsd 0xe029(%rip), %xmm1     # 0x109158
ucomisd %xmm3, %xmm1
jbe 0xfb172
leaq 0x2401bc(%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 0xfafb7
movl $0x1, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x71468
xorl %edi, %edi
movl $0x3, %esi
callq 0x6c67b
leaq 0x24014a(%rip), %rax    # 0x33b2e0
movb $0x1, %cl
movb %cl, (%rax)
leaq 0x240140(%rip), %rax    # 0x33b2e1
movb $0x4, %dl
movb %dl, (%rax)
leaq 0x240104(%rip), %rax    # 0x33b2b0
movb %dl, (%rax)
leaq 0x12025e(%rip), %rax    # 0x21b413
movb %cl, (%rax)
leaq 0x120256(%rip), %rax    # 0x21b414
movb %cl, (%rax)
leaq 0x11d639(%rip), %rbx    # 0x218800
cmpl $0x68f, (%rbx)          # imm = 0x68F
jg 0xfb1f1
leaq 0x240212(%rip), %rax    # 0x33b3e8
movb $0x1, (%rax)
xorl %eax, %eax
cmpq $0x10000, (%r14)        # imm = 0x10000
sete %al
leal (%rax,%rax,4), %eax
leaq 0x141b4f(%rip), %rcx    # 0x23cd3e
movb %al, (%rcx)
movl $0x2a, %edi
callq 0xcf81
leaq 0x128342(%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 0x3a1fa(%rip), %rax     # 0x135421
leaq 0x3a20d(%rip), %rdi     # 0x13543b
cmovgq %rax, %rdi
movl $0xe, %esi
callq 0xfad99
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xab5f