// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
testq %rdi, %rdi
je 0x31633
movq %rdi, %rbx
leaq 0x309e89(%rip), %r12    # 0x33b2f0
movsd (%r12), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x309e7f(%rip), %r15    # 0x33b2f8
movsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x309e76(%rip), %r13    # 0x33b300
movsd (%r13), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x2c, %esi
callq 0x9100
testq %rax, %rax
je 0x314ac
movb $0x20, (%rax)
movq %rax, %rdi
jmp 0x31495
movq %rbx, %rdi
movl $0x41, %esi
callq 0x9100
testq %rax, %rax
jne 0x314d0
movq %rbx, %rdi
movl $0x61, %esi
callq 0x9100
testq %rax, %rax
je 0x31531
leaq 0x2dbde9(%rip), %rax    # 0x30d2c0
movl $0x5, %r14d
cmpl $0x0, (%rax)
je 0x31639
leaq 0x12c843(%rip), %rax    # 0x15dd30
movsd 0x428(%rax), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x31505
jnp 0x31639
movsd 0x510(%rax), %xmm1
ucomisd %xmm0, %xmm1
jne 0x31519
jnp 0x31639
movsd 0x5f8(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x31531
jnp 0x31639
leaq -0x160(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9340
movq %r14, %rdi
callq 0x9899
leaq 0xd9876(%rip), %rsi     # 0x10adc8
movq %r14, %rdi
callq 0x9090
testq %rax, %rax
je 0x3164e
leaq 0x2dba66(%rip), %rbx    # 0x30cfd0
movsd (%rbx), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x2dba5e(%rip), %r14    # 0x30cfd8
movsd (%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x2dba55(%rip), %r15    # 0x30cfe0
movsd (%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x202d4
movsd -0x58(%rbp), %xmm0
movsd %xmm0, (%rbx)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, (%r14)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r15)
leaq 0x309d3a(%rip), %r15    # 0x33b2f8
testl %eax, %eax
jne 0x31700
movsd (%r12), %xmm0
mulsd 0xda24c(%rip), %xmm0    # 0x10b820
divsd 0xda23c(%rip), %xmm0    # 0x10b818
leaq 0x101274(%rip), %rbx    # 0x132857
leaq -0x160(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
movsd 0xda224(%rip), %xmm0    # 0x10b820
mulsd (%r15), %xmm0
divsd 0xda20f(%rip), %xmm0    # 0x10b818
leaq -0x360(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
movsd (%r13), %xmm0
leaq -0x260(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
jmp 0x3167d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe3734(%rip), %rsi     # 0x114d89
leaq -0x160(%rbp), %rdx
leaq -0x360(%rbp), %rcx
leaq -0x260(%rbp), %r8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9360
cmpl $0x3, %eax
jne 0x31700
leaq -0x160(%rbp), %rsi
xorl %edi, %edi
callq 0x3121e
movsd %xmm0, (%r12)
movl $0x1, %r14d
leaq -0x360(%rbp), %rsi
movl $0x1, %edi
callq 0x3121e
movsd %xmm0, (%r15)
leaq -0x260(%rbp), %rdi
callq 0x30e70
movsd %xmm0, (%r13)
movsd (%r12), %xmm1
movapd 0xd7ab3(%rip), %xmm2    # 0x109180
andpd %xmm1, %xmm2
ucomisd 0xda237(%rip), %xmm2    # 0x10b910
jbe 0x3172b
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
jmp 0x31639
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
movl $0x4, %r14d
jmp 0x31639
movsd (%r15), %xmm2
movapd 0xd7a48(%rip), %xmm3    # 0x109180
andpd %xmm2, %xmm3
ucomisd 0xda0dc(%rip), %xmm3    # 0x10b820
jbe 0x31771
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
movl $0x2, %r14d
jmp 0x31639
movsd 0xd7967(%rip), %xmm3    # 0x1090e0
ucomisd %xmm0, %xmm3
ja 0x317b9
ucomisd 0xda191(%rip), %xmm0    # 0x10b918
ja 0x317b9
movsd 0xd79c7(%rip), %xmm0    # 0x109158
divsd %xmm0, %xmm1
movsd %xmm1, (%r12)
divsd %xmm0, %xmm2
movsd %xmm2, (%r15)
leaq 0x309b5d(%rip), %rax    # 0x33b308
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
xorl %r14d, %r14d
jmp 0x31639
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
movl $0x3, %r14d
jmp 0x31639