// File: 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
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
leaq 0x14311e(%rip), %rax    # 0x29d580
cmpq $0x0, (%rax)
je 0x15a5d5
leaq 0x14310d(%rip), %rax    # 0x29d580
movq (%rax), %rdi
movl -0x4(%rbp), %edx
leaq 0x3db47(%rip), %rsi     # 0x197fc7
movb $0x0, %al
callq 0x9550
leaq 0x1430f2(%rip), %rax    # 0x29d580
movq (%rax), %rdi
movsd 0x14bdf(%rip), %xmm0    # 0x16f078
leaq 0x240030(%rip), %rax    # 0x39a4d0
mulsd (%rax), %xmm0
movsd 0x1711c(%rip), %xmm1    # 0x1715c8
divsd %xmm1, %xmm0
movsd 0x14bc0(%rip), %xmm1    # 0x16f078
leaq 0x240019(%rip), %rax    # 0x39a4d8
mulsd (%rax), %xmm1
movsd 0x170fd(%rip), %xmm2    # 0x1715c8
divsd %xmm2, %xmm1
leaq 0x24000a(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm2
leaq 0x3db05(%rip), %rsi     # 0x197fe6
movb $0x3, %al
callq 0x9550
leaq 0x143091(%rip), %rax    # 0x29d580
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movsd 0x14b7a(%rip), %xmm0    # 0x16f078
leaq 0x23ffcb(%rip), %rax    # 0x39a4d0
mulsd (%rax), %xmm0
movsd 0x170b7(%rip), %xmm1    # 0x1715c8
divsd %xmm1, %xmm0
callq 0xf4d40
movq -0x18(%rbp), %rdi
movq %rax, %rdx
leaq 0x3dade(%rip), %rsi     # 0x198006
movb $0x0, %al
callq 0x9550
leaq 0x14304a(%rip), %rax    # 0x29d580
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movsd 0x14b33(%rip), %xmm0    # 0x16f078
leaq 0x23ff8c(%rip), %rax    # 0x39a4d8
mulsd (%rax), %xmm0
movsd 0x17070(%rip), %xmm1    # 0x1715c8
divsd %xmm1, %xmm0
callq 0xf4d40
movq -0x10(%rbp), %rdi
movq %rax, %rdx
leaq 0x3daab(%rip), %rsi     # 0x19801a
movb $0x0, %al
callq 0x9550
leaq 0x23ff53(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
leaq 0x23ff50(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm1
leaq 0x23ff4d(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm2
callq 0x7fcf0
leaq 0x142fdd(%rip), %rax    # 0x29d580
movq (%rax), %rdi
leaq 0x211c1b(%rip), %rax    # 0x36c1c8
movsd (%rax), %xmm0
leaq 0x211c18(%rip), %rax    # 0x36c1d0
movsd (%rax), %xmm1
leaq 0x211c15(%rip), %rax    # 0x36c1d8
movsd (%rax), %xmm2
leaq 0x3da60(%rip), %rsi     # 0x19802e
movb $0x3, %al
callq 0x9550
leaq 0x11d508(%rip), %rax    # 0x277ae4
cmpb $0x0, (%rax)
je 0x15a5f9
leaq 0x11d4fc(%rip), %rax    # 0x277ae4
movzbl (%rax), %eax
cmpl $0x1, %eax
je 0x15a5f9
movl $0x1, -0x4(%rbp)
jmp 0x15a60f
leaq 0x11d4b0(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
je 0x15a60d
movl $0x1, -0x4(%rbp)
jmp 0x15a60f
cmpl $0x0, -0x4(%rbp)
jge 0x15a67d
leaq 0x23feb4(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
callq 0x159850
movaps %xmm0, %xmm1
leaq 0x211b69(%rip), %rax    # 0x36c198
movsd (%rax), %xmm0
movsd 0x14b45(%rip), %xmm2    # 0x16f180
divsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x15a7ae
leaq 0x23fe88(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm0
callq 0x159850
movaps %xmm0, %xmm1
leaq 0x211b35(%rip), %rax    # 0x36c198
movsd (%rax), %xmm0
movsd 0x14b11(%rip), %xmm2    # 0x16f180
divsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x15a7ae
movl $0x2, %edi
callq 0x9ae80
leaq 0x23fe32(%rip), %rax    # 0x39a4c0
movb $0x0, (%rax)
leaq 0x23fe38(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
leaq 0x23fe35(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm1
leaq 0x23fe32(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm2
callq 0x8d180
leaq 0x11d3f2(%rip), %rcx    # 0x277ab0
movabsq $0xc40cb0400, %rax      # imm = 0xC40CB0400
andq (%rcx), %rax
cmpq $0x0, %rax
je 0x15a6d6
jmp 0x15a788
movl $0x7, %edi
movl $0xb, %esi
callq 0x90d70
movl -0x4(%rbp), %edi
callq 0x120fc0
leaq 0x14244c(%rip), %rdi    # 0x29cb40
leaq 0x3d95a(%rip), %rsi     # 0x198055
movb $0x0, %al
callq 0x9060
leaq 0x142e77(%rip), %rax    # 0x29d580
cmpq $0x0, (%rax)
je 0x15a72e
leaq 0x142e6a(%rip), %rax    # 0x29d580
movq (%rax), %rdi
leaq 0x2e6df(%rip), %rsi     # 0x188dff
leaq 0x142419(%rip), %rdx    # 0x29cb40
movb $0x0, %al
callq 0x9550
movl $0x1, %edi
callq 0x10cbe0
leaq 0x11d2a1(%rip), %rax    # 0x2779e0
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
leaq 0x127fd9(%rip), %rax    # 0x282724
imull $0x31a, (%rax), %eax    # imm = 0x31A
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x1c(%rbp), %eax
cmpl %ecx, %eax
jle 0x15a775
leaq 0x3d90e(%rip), %rdi     # 0x198077
movl $0xf, %esi
callq 0x15a360
jmp 0x15a786
leaq 0x3d915(%rip), %rdi     # 0x198091
movl $0xf, %esi
callq 0x15a360
jmp 0x15a788
movl $0x2, %edi
callq 0x159a00
leaq 0x2128e1(%rip), %rax    # 0x36d07a
movb $0x1, (%rax)
leaq 0x2128d9(%rip), %rax    # 0x36d07c
movl $0x0, (%rax)
jmp 0x15a8a3
movl $0x1, %edx
xorl %esi, %esi
movl %edx, %edi
callq 0x9ac40
xorl %edi, %edi
movl $0x3, %esi
callq 0x93b60
leaq 0x23fcf1(%rip), %rax    # 0x39a4c0
movb $0x1, (%rax)
leaq 0x23fce8(%rip), %rax    # 0x39a4c1
movb $0x4, (%rax)
leaq 0x23fcad(%rip), %rax    # 0x39a490
movb $0x4, (%rax)
leaq 0x11fe06(%rip), %rax    # 0x27a5f3
movb $0x1, (%rax)
leaq 0x11fdfd(%rip), %rax    # 0x27a5f4
movb $0x1, (%rax)
leaq 0x11d1df(%rip), %rax    # 0x2779e0
cmpl $0x690, (%rax)          # imm = 0x690
setge %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x15a846
leaq 0x23fdad(%rip), %rax    # 0x39a5c8
movb $0x1, (%rax)
leaq 0x11d28b(%rip), %rax    # 0x277ab0
cmpq $0x10000, (%rax)        # imm = 0x10000
jne 0x15a83a
leaq 0x1416e9(%rip), %rax    # 0x29bf1e
movb $0x5, (%rax)
jmp 0x15a844
leaq 0x1416dd(%rip), %rax    # 0x29bf1e
movb $0x0, (%rax)
jmp 0x15a846
movl $0x2a, %edi
callq 0xeaf0
leaq 0x11d189(%rip), %rax    # 0x2779e0
movl (%rax), %eax
movl %eax, -0x20(%rbp)
leaq 0x127ec1(%rip), %rax    # 0x282724
imull $0x31a, (%rax), %eax    # imm = 0x31A
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x20(%rbp), %eax
cmpl %ecx, %eax
jle 0x15a88d
leaq 0x3d822(%rip), %rdi     # 0x1980a3
movl $0xe, %esi
callq 0x15a360
jmp 0x15a89e
leaq 0x3d829(%rip), %rdi     # 0x1980bd
movl $0xe, %esi
callq 0x15a360
callq 0xb0d0
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)