// File: /workspace/github_cpp_makefile_star2_O2/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 0x14287b(%rip), %r15    # 0x2283a0
movq (%r15), %rdi
testq %rdi, %rdi
je 0xe5c49
leaq 0x3981d(%rip), %rsi     # 0x11f355
movl %ebx, %edx
xorl %eax, %eax
callq 0x9560
movq (%r15), %rdi
leaq 0x23f7a5(%rip), %r12    # 0x3252f0
movsd 0xfd55(%rip), %xmm2     # 0xf58a8
movsd (%r12), %xmm0
mulsd %xmm2, %xmm0
movsd 0xfd3b(%rip), %xmm3     # 0xf58a0
divsd %xmm3, %xmm0
leaq 0x23f788(%rip), %r13    # 0x3252f8
movsd (%r13), %xmm1
mulsd %xmm2, %xmm1
divsd %xmm3, %xmm1
leaq 0x23f77b(%rip), %rax    # 0x325300
movsd (%rax), %xmm2
leaq 0x397e4(%rip), %rsi     # 0x11f374
movb $0x3, %al
callq 0x9560
movq (%r15), %r14
movsd (%r12), %xmm0
mulsd 0xfd00(%rip), %xmm0     # 0xf58a8
divsd 0xfcf0(%rip), %xmm0     # 0xf58a0
callq 0xa3ca2
leaq 0x397d8(%rip), %rsi     # 0x11f394
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9560
movq (%r15), %r14
movsd 0xfcd4(%rip), %xmm0     # 0xf58a8
mulsd (%r13), %xmm0
divsd 0xfcbe(%rip), %xmm0     # 0xf58a0
callq 0xa3ca2
leaq 0x397ba(%rip), %rsi     # 0x11f3a8
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x9560
movsd (%r12), %xmm0
movsd (%r13), %xmm1
leaq 0x23f6f2(%rip), %rax    # 0x325300
movsd (%rax), %xmm2
callq 0x55535
movq (%r15), %rdi
leaq 0x2113c7(%rip), %rax    # 0x2f6fe8
movsd (%rax), %xmm0
leaq 0x2113c4(%rip), %rax    # 0x2f6ff0
movsd (%rax), %xmm1
leaq 0x2113c1(%rip), %rax    # 0x2f6ff8
movsd (%rax), %xmm2
leaq 0x3977a(%rip), %rsi     # 0x11f3bc
movb $0x3, %al
callq 0x9560
leaq 0x11ccb4(%rip), %rax    # 0x202904
leaq 0x11cc79(%rip), %r14    # 0x2028d0
cmpq $0x1, (%r14)
pushq $0x1
popq %rcx
cmovnel %ecx, %ebx
cmpb $0x2, (%rax)
cmovael %ecx, %ebx
testl %ebx, %ebx
js 0xe5d6e
pushq $0x2
popq %rdi
callq 0x67da0
leaq 0x23f662(%rip), %rax    # 0x3252e0
movb $0x0, (%rax)
leaq 0x23f668(%rip), %rax    # 0x3252f0
movsd (%rax), %xmm0
leaq 0x23f665(%rip), %rax    # 0x3252f8
movsd (%rax), %xmm1
leaq 0x23f662(%rip), %rax    # 0x325300
movsd (%rax), %xmm2
callq 0x5ec70
testl $0xc40cb04, 0x1(%r14)   # imm = 0xC40CB04
jne 0xe5d46
pushq $0x7
popq %rdi
pushq $0xb
popq %rsi
callq 0x6166c
movl %ebx, %edi
callq 0xc2231
leaq 0x141c92(%rip), %rax    # 0x227960
movups 0x3971e(%rip), %xmm0    # 0x11f3f3
movaps %xmm0, 0x10(%rax)
movups 0x39703(%rip), %xmm0    # 0x11f3e3
movaps %xmm0, (%rax)
movw $0x79, 0x20(%rax)
movq (%r15), %rdi
testq %rdi, %rdi
je 0xe5d06
leaq 0x29d27(%rip), %rsi     # 0x10fa1f
leaq 0x141c61(%rip), %rdx    # 0x227960
xorl %eax, %eax
callq 0x9560
pushq $0x1
popq %rdi
callq 0xb25f5
leaq 0x11caeb(%rip), %rax    # 0x202800
movl (%rax), %ecx
leaq 0x127826(%rip), %rax    # 0x20d544
imull $0x31a, (%rax), %eax    # imm = 0x31A
pushq $0x64
popq %rsi
cltd
idivl %esi
cmpl %eax, %ecx
leaq 0x396d2(%rip), %rax     # 0x11f405
leaq 0x396e5(%rip), %rdi     # 0x11f41f
cmovgq %rax, %rdi
pushq $0xf
popq %rsi
callq 0xe5a5f
callq 0xe5327
leaq 0x212148(%rip), %rax    # 0x2f7e9a
movb $0x1, (%rax)
leaq 0x212140(%rip), %rax    # 0x2f7e9c
andl $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23f57b(%rip), %rax    # 0x3252f0
movsd (%rax), %xmm1
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 0x21120b(%rip), %rax    # 0x2f6fb8
movsd (%rax), %xmm1
divsd 0xd3a7(%rip), %xmm1     # 0xf3160
ucomisd %xmm3, %xmm1
jbe 0xe5df9
leaq 0x23f532(%rip), %rax    # 0x3252f8
movsd (%rax), %xmm2
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 0xe5c6f
pushq $0x1
popq %rdi
xorl %esi, %esi
movl %edi, %edx
callq 0x67c78
pushq $0x3
popq %rsi
xorl %edi, %edi
callq 0x6355d
leaq 0x23f4ca(%rip), %rax    # 0x3252e0
movb $0x1, %cl
movb %cl, (%rax)
leaq 0x23f4c0(%rip), %rax    # 0x3252e1
movb $0x4, %dl
movb %dl, (%rax)
leaq 0x23f484(%rip), %rax    # 0x3252b0
movb %dl, (%rax)
leaq 0x11f5de(%rip), %rax    # 0x205413
movb %cl, (%rax)
leaq 0x11f5d6(%rip), %rax    # 0x205414
movb %cl, (%rax)
leaq 0x11c9b9(%rip), %rbx    # 0x202800
cmpl $0x68f, (%rbx)          # imm = 0x68F
jg 0xe5e71
leaq 0x23f592(%rip), %rax    # 0x3253e8
movb $0x1, (%rax)
xorl %eax, %eax
cmpq $0x10000, (%r14)        # imm = 0x10000
sete %al
leal (%rax,%rax,4), %eax
leaq 0x140ecf(%rip), %rcx    # 0x226d3e
movb %al, (%rcx)
pushq $0x2a
popq %rdi
callq 0xcc4f
movl (%rbx), %ecx
leaq 0x1276c2(%rip), %rax    # 0x20d544
imull $0x31a, (%rax), %eax    # imm = 0x31A
pushq $0x64
popq %rsi
cltd
idivl %esi
cmpl %eax, %ecx
leaq 0x3959a(%rip), %rax     # 0x11f431
leaq 0x395ad(%rip), %rdi     # 0x11f44b
cmovgq %rax, %rdi
pushq $0xe
popq %rsi
callq 0xe5a5f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xaa05