// File: /workspace/github_cpp_makefile_star2_O3/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 0x317bd
movq %rdi, %rbx
leaq 0x309cff(%rip), %r12    # 0x33b2f0
movsd (%r12), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x309cf5(%rip), %r15    # 0x33b2f8
movsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x309cec(%rip), %r13    # 0x33b300
movsd (%r13), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x2c, %esi
callq 0x9100
testq %rax, %rax
je 0x31636
movb $0x20, (%rax)
movq %rax, %rdi
jmp 0x3161f
movq %rbx, %rdi
movl $0x41, %esi
callq 0x9100
testq %rax, %rax
jne 0x3165a
movq %rbx, %rdi
movl $0x61, %esi
callq 0x9100
testq %rax, %rax
je 0x316bb
leaq 0x2dbc5f(%rip), %rax    # 0x30d2c0
movl $0x5, %r14d
cmpl $0x0, (%rax)
je 0x317c3
leaq 0x12c6b9(%rip), %rax    # 0x15dd30
movsd 0x428(%rax), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x3168f
jnp 0x317c3
movsd 0x510(%rax), %xmm1
ucomisd %xmm0, %xmm1
jne 0x316a3
jnp 0x317c3
movsd 0x5f8(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x316bb
jnp 0x317c3
leaq -0x160(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9340
movq %r14, %rdi
callq 0x9899
leaq 0xd96fc(%rip), %rsi     # 0x10add8
movq %r14, %rdi
callq 0x9090
testq %rax, %rax
je 0x317d8
leaq 0x2db8dc(%rip), %rbx    # 0x30cfd0
movsd (%rbx), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x2db8d4(%rip), %r14    # 0x30cfd8
movsd (%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x2db8cb(%rip), %r15    # 0x30cfe0
movsd (%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x20293
movsd -0x58(%rbp), %xmm0
movsd %xmm0, (%rbx)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, (%r14)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r15)
leaq 0x309bb0(%rip), %r15    # 0x33b2f8
testl %eax, %eax
jne 0x3188a
movsd (%r12), %xmm0
mulsd 0xda0d2(%rip), %xmm0    # 0x10b830
divsd 0xda0c2(%rip), %xmm0    # 0x10b828
leaq 0x1011da(%rip), %rbx    # 0x132947
leaq -0x160(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
movsd 0xda0aa(%rip), %xmm0    # 0x10b830
mulsd (%r15), %xmm0
divsd 0xda095(%rip), %xmm0    # 0x10b828
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 0x31807
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 0xe363e(%rip), %rsi     # 0x114e1d
leaq -0x160(%rbp), %rdx
leaq -0x360(%rbp), %rcx
leaq -0x260(%rbp), %r8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9360
cmpl $0x3, %eax
jne 0x3188a
leaq -0x160(%rbp), %rsi
xorl %edi, %edi
callq 0x3139b
movsd %xmm0, (%r12)
movl $0x1, %r14d
leaq -0x360(%rbp), %rsi
movl $0x1, %edi
callq 0x3139b
movsd %xmm0, (%r15)
leaq -0x260(%rbp), %rdi
callq 0x30ff6
movsd %xmm0, (%r13)
movsd (%r12), %xmm1
movapd 0xd7939(%rip), %xmm2    # 0x109190
andpd %xmm1, %xmm2
ucomisd 0xda0b5(%rip), %xmm2    # 0x10b918
jbe 0x318b5
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
jmp 0x317c3
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 0x317c3
movsd (%r15), %xmm2
movapd 0xd78ce(%rip), %xmm3    # 0x109190
andpd %xmm2, %xmm3
ucomisd 0xd9f62(%rip), %xmm3    # 0x10b830
jbe 0x318fb
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 0x317c3
movsd 0xd77dd(%rip), %xmm3    # 0x1090e0
ucomisd %xmm0, %xmm3
ja 0x31943
ucomisd 0xda00f(%rip), %xmm0    # 0x10b920
ja 0x31943
movsd 0xd7845(%rip), %xmm0    # 0x109160
divsd %xmm0, %xmm1
movsd %xmm1, (%r12)
divsd %xmm0, %xmm2
movsd %xmm2, (%r15)
leaq 0x3099d3(%rip), %rax    # 0x33b308
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
xorl %r14d, %r14d
jmp 0x317c3
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 0x317c3