// File: jkingan[P]ladyheather/heathui.cpp
// Function: parse_lla(char*)
int parse_lla(char *s)
{
double old_lat, old_lon, old_alt;
double x_lat, x_lon, x_alt;
char lat_s[SLEN+1];
char lon_s[SLEN+1];
char alt_s[SLEN+1];
int n;
char *comma;

   // set lat/lon/altitude
   if(s == 0) return (-1);

   old_lat = precise_lat;
   old_lon = precise_lon;
   old_alt = precise_alt;

   comma = s;
   while(comma) {  // convert commas to spaces
      comma = strchr(comma, ',');
      if(comma) *comma = ' ';
      else break;
   }

//   precise_lat = precise_lon = precise_alt = 1.0E6;
   if(strchr(s, 'A') || strchr(s, 'a')) {  // set lat/lon/alt to current average value
      if(have_lla_queue == 0) return NO_AVERAGE;
      if(plot[ONE].stat_count == (DATA_SIZE) 0) return NO_AVERAGE;
      if(plot[TWO].stat_count == (DATA_SIZE) 0) return NO_AVERAGE;
      if(plot[THREE].stat_count == (DATA_SIZE) 0) return NO_AVERAGE;
   }

   strcpy(lat_s, s);
   strupr(lat_s);
   if(strstr(lat_s, "LOC")) {
      x_lat = lat;
      x_lon = lon;
      x_alt = alt;
      n = read_default_lla();  // get location from heather.loc file
      lat = x_lat;
      lon = x_lon;
      alt = x_alt;
      if(n != LLA_OK) goto bad_loc;

      sprintf(lat_s, "%.9f", precise_lat*180.0/PI);
      sprintf(lon_s, "%.9f", precise_lon*180.0/PI);
      sprintf(alt_s, "%.9f", precise_alt);
   }
   else {
      n = sscanf(s, "%s %s %s", &lat_s[0],&lon_s[0],&alt_s[0]);
      if(n != 3) {
         bad_loc:
         precise_lat = old_lat;
         precise_lon = old_lon;
         precise_alt = old_alt;
         return LLA_MISSING;
      }
   }

   precise_lat = parse_coord(0, lat_s);
   precise_lon = parse_coord(1, lon_s);
   precise_alt = parse_alt(alt_s);
//sprintf(plot_title, "lat:%.9f lon:%.9f alt:%.9f", precise_lat,precise_lon,precise_alt);

   if((precise_lat < -90.0) || (precise_lat > 90.0)) {
      precise_lat = old_lat;
      precise_lon = old_lon;
      precise_alt = old_alt;
      return BAD_LAT;
   }
   else if((precise_lon < -180.0) || (precise_lon > 180.0)) {
      precise_lat = old_lat;
      precise_lon = old_lon;
      precise_alt = old_alt;
      return BAD_LON;
   }
   else if((precise_alt< -1000.0) || (precise_alt > 20000.0)) {
      precise_lat = old_lat;
      precise_lon = old_lon;
      precise_alt = old_alt;
      return BAD_ALT;
   }

   precise_lat /= RAD_TO_DEG;
   precise_lon /= RAD_TO_DEG;
   have_precise_lla = (-5);

   return LLA_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x45792
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45c56
leaq 0x354d37(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0x354d2f(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x354d27(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x350(%rbp)
cmpq $0x0, -0x350(%rbp)
je 0x45809
movq -0x350(%rbp), %rdi
movl $0x2c, %esi
callq 0x9100
movq %rax, -0x350(%rbp)
cmpq $0x0, -0x350(%rbp)
je 0x45805
movq -0x350(%rbp), %rax
movb $0x20, (%rax)
jmp 0x45807
jmp 0x45809
jmp 0x457cd
movq -0x10(%rbp), %rdi
movl $0x41, %esi
callq 0x9100
cmpq $0x0, %rax
jne 0x45835
movq -0x10(%rbp), %rdi
movl $0x61, %esi
callq 0x9100
cmpq $0x0, %rax
je 0x458c1
leaq 0x326c64(%rip), %rax    # 0x36c4a0
cmpl $0x0, (%rax)
jne 0x4584d
movl $0x5, -0x4(%rbp)
jmp 0x45c56
leaq 0x1774cc(%rip), %rax    # 0x1bcd20
movsd 0x428(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x45873
jp 0x45873
movl $0x5, -0x4(%rbp)
jmp 0x45c56
leaq 0x1774a6(%rip), %rax    # 0x1bcd20
movsd 0x510(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x45899
jp 0x45899
movl $0x5, -0x4(%rbp)
jmp 0x45c56
leaq 0x177480(%rip), %rax    # 0x1bcd20
movsd 0x5f8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x458bf
jp 0x458bf
movl $0x5, -0x4(%rbp)
jmp 0x45c56
jmp 0x458c1
leaq -0x140(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9350
leaq -0x140(%rbp), %rdi
callq 0x9890
leaq -0x140(%rbp), %rdi
leaq 0x12b4da(%rip), %rsi    # 0x170dc5
callq 0x9090
cmpq $0x0, %rax
je 0x459fd
leaq 0x3268af(%rip), %rax    # 0x36c1b0
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x3268a7(%rip), %rax    # 0x36c1b8
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x32689f(%rip), %rax    # 0x36c1c0
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0x2d870
movl %eax, -0x344(%rbp)
movsd -0x30(%rbp), %xmm0
leaq 0x32686f(%rip), %rax    # 0x36c1b0
movsd %xmm0, (%rax)
movsd -0x38(%rbp), %xmm0
leaq 0x326867(%rip), %rax    # 0x36c1b8
movsd %xmm0, (%rax)
movsd -0x40(%rbp), %xmm0
leaq 0x32685f(%rip), %rax    # 0x36c1c0
movsd %xmm0, (%rax)
cmpl $0x0, -0x344(%rbp)
je 0x45973
jmp 0x45a35
leaq -0x140(%rbp), %rdi
movsd 0x1296f6(%rip), %xmm0   # 0x16f078
leaq 0x354b47(%rip), %rax    # 0x39a4d0
mulsd (%rax), %xmm0
movsd 0x12bc33(%rip), %xmm1   # 0x1715c8
divsd %xmm1, %xmm0
leaq 0x14fad9(%rip), %rsi    # 0x195479
movb $0x1, %al
callq 0x9060
leaq -0x240(%rbp), %rdi
movsd 0x1296c2(%rip), %xmm0   # 0x16f078
leaq 0x354b1b(%rip), %rax    # 0x39a4d8
mulsd (%rax), %xmm0
movsd 0x12bbff(%rip), %xmm1   # 0x1715c8
divsd %xmm1, %xmm0
leaq 0x14faa5(%rip), %rsi    # 0x195479
movb $0x1, %al
callq 0x9060
leaq -0x340(%rbp), %rdi
leaq 0x354af7(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm0
leaq 0x14fa85(%rip), %rsi    # 0x195479
movb $0x1, %al
callq 0x9060
jmp 0x45a73
movq -0x10(%rbp), %rdi
leaq -0x140(%rbp), %rdx
leaq -0x240(%rbp), %rcx
leaq -0x340(%rbp), %r8
leaq 0x133d9c(%rip), %rsi    # 0x1797b9
movb $0x0, %al
callq 0x9370
movl %eax, -0x344(%rbp)
cmpl $0x3, -0x344(%rbp)
je 0x45a71
jmp 0x45a35
movsd -0x18(%rbp), %xmm0
leaq 0x354a8f(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
movsd -0x20(%rbp), %xmm0
leaq 0x354a87(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
movsd -0x28(%rbp), %xmm0
leaq 0x354a7f(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
movl $0x4, -0x4(%rbp)
jmp 0x45c56
jmp 0x45a73
leaq -0x140(%rbp), %rsi
xorl %edi, %edi
callq 0x453c0
leaq 0x354a48(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
leaq -0x240(%rbp), %rsi
movl $0x1, %edi
callq 0x453c0
leaq 0x354a34(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
leaq -0x340(%rbp), %rdi
callq 0x44cc0
leaq 0x354a25(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
movsd 0x1295b9(%rip), %xmm0   # 0x16f080
leaq 0x354a02(%rip), %rax    # 0x39a4d0
ucomisd (%rax), %xmm0
ja 0x45aed
leaq 0x3549f5(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
movsd 0x1295a1(%rip), %xmm1   # 0x16f088
ucomisd %xmm1, %xmm0
jbe 0x45b29
movsd -0x18(%rbp), %xmm0
leaq 0x3549d7(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
movsd -0x20(%rbp), %xmm0
leaq 0x3549cf(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
movsd -0x28(%rbp), %xmm0
leaq 0x3549c7(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x45c56
movsd 0x12953f(%rip), %xmm0   # 0x16f070
leaq 0x3549a0(%rip), %rax    # 0x39a4d8
ucomisd (%rax), %xmm0
ja 0x45b57
leaq 0x354993(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm0
movsd 0x129527(%rip), %xmm1   # 0x16f078
ucomisd %xmm1, %xmm0
jbe 0x45b93
movsd -0x18(%rbp), %xmm0
leaq 0x35496d(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
movsd -0x20(%rbp), %xmm0
leaq 0x354965(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
movsd -0x28(%rbp), %xmm0
leaq 0x35495d(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
movl $0x2, -0x4(%rbp)
jmp 0x45c56
movsd 0x129565(%rip), %xmm0   # 0x16f100
leaq 0x35493e(%rip), %rax    # 0x39a4e0
ucomisd (%rax), %xmm0
ja 0x45bc1
leaq 0x354931(%rip), %rax    # 0x39a4e0
movsd (%rax), %xmm0
movsd 0x12badd(%rip), %xmm1   # 0x171698
ucomisd %xmm1, %xmm0
jbe 0x45bfa
movsd -0x18(%rbp), %xmm0
leaq 0x354903(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
movsd -0x20(%rbp), %xmm0
leaq 0x3548fb(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
movsd -0x28(%rbp), %xmm0
leaq 0x3548f3(%rip), %rax    # 0x39a4e0
movsd %xmm0, (%rax)
movl $0x3, -0x4(%rbp)
jmp 0x45c56
jmp 0x45bfc
jmp 0x45bfe
leaq 0x3548cb(%rip), %rax    # 0x39a4d0
movsd (%rax), %xmm0
movsd 0x12956f(%rip), %xmm1   # 0x16f180
divsd %xmm1, %xmm0
leaq 0x3548b4(%rip), %rax    # 0x39a4d0
movsd %xmm0, (%rax)
leaq 0x3548b1(%rip), %rax    # 0x39a4d8
movsd (%rax), %xmm0
movsd 0x12954d(%rip), %xmm1   # 0x16f180
divsd %xmm1, %xmm0
leaq 0x35489a(%rip), %rax    # 0x39a4d8
movsd %xmm0, (%rax)
leaq 0x35489f(%rip), %rax    # 0x39a4e8
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
nopw %cs:(%rax,%rax)