// File: /workspace/github_cpp_makefile_star2_O2/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 0x2ebd8
movq %rdi, %rbx
leaq 0x2f68e3(%rip), %r12    # 0x3252f0
movsd (%r12), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2f68d9(%rip), %r15    # 0x3252f8
movsd (%r15), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x2f68d0(%rip), %r13    # 0x325300
movsd (%r13), %xmm0
movsd %xmm0, -0x40(%rbp)
pushq $0x2c
popq %r14
movq %rdi, %rax
movq %rax, %rdi
movl %r14d, %esi
callq 0x9100
testq %rax, %rax
je 0x2ea57
movb $0x20, (%rax)
jmp 0x2ea42
pushq $0x41
popq %rsi
movq %rbx, %rdi
callq 0x9100
testq %rax, %rax
jne 0x2ea77
pushq $0x61
popq %rsi
movq %rbx, %rdi
callq 0x9100
testq %rax, %rax
je 0x2ead6
leaq 0x2c8842(%rip), %rax    # 0x2f72c0
pushq $0x5
popq %r14
cmpl $0x0, (%rax)
je 0x2ebdc
leaq 0x11929e(%rip), %rax    # 0x147d30
movsd 0x428(%rax), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x2eaaa
jnp 0x2ebdc
movsd 0x510(%rax), %xmm1
ucomisd %xmm0, %xmm1
jne 0x2eabe
jnp 0x2ebdc
movsd 0x5f8(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2ead6
jnp 0x2ebdc
leaq -0x160(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9330
movq %r14, %rdi
callq 0x988f
leaq 0xc635c(%rip), %rsi     # 0xf4e53
movq %r14, %rdi
callq 0x9090
testq %rax, %rax
je 0x2ebf1
leaq 0x2c84c1(%rip), %rbx    # 0x2f6fd0
movsd (%rbx), %xmm0
movsd %xmm0, -0x58(%rbp)
leaq 0x2c84b9(%rip), %r14    # 0x2f6fd8
movsd (%r14), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x2c84b0(%rip), %r15    # 0x2f6fe0
movsd (%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
callq 0x1eecd
movsd -0x58(%rbp), %xmm0
movsd %xmm0, (%rbx)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, (%r14)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, (%r15)
leaq 0x2f6795(%rip), %r15    # 0x3252f8
testl %eax, %eax
jne 0x2ec9b
movsd (%r12), %xmm0
mulsd 0xc6d2f(%rip), %xmm0    # 0xf58a8
divsd 0xc6d1f(%rip), %xmm0    # 0xf58a0
leaq 0xedcdf(%rip), %rbx     # 0x11c867
leaq -0x160(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x9060
movsd 0xc6d07(%rip), %xmm0    # 0xf58a8
mulsd (%r15), %xmm0
divsd 0xc6cf2(%rip), %xmm0    # 0xf58a0
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 0x2ec1c
pushq $-0x1
popq %r14
movl %r14d, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd02a5(%rip), %rsi     # 0xfee9d
leaq -0x160(%rbp), %rdx
leaq -0x360(%rbp), %rcx
leaq -0x260(%rbp), %r8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9350
cmpl $0x3, %eax
jne 0x2ec9b
leaq -0x160(%rbp), %rsi
xorl %edi, %edi
callq 0x2e7c9
movsd %xmm0, (%r12)
pushq $0x1
popq %r14
leaq -0x360(%rbp), %rsi
movl %r14d, %edi
callq 0x2e7c9
movsd %xmm0, (%r15)
leaq -0x260(%rbp), %rdi
callq 0x2e470
movsd %xmm0, (%r13)
movsd (%r12), %xmm1
movapd 0xc4528(%rip), %xmm2    # 0xf3190
andpd %xmm1, %xmm2
ucomisd 0xc6d1c(%rip), %xmm2    # 0xf5990
jbe 0x2ecc2
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
jmp 0x2ebdc
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
pushq $0x4
jmp 0x2ebda
movsd (%r15), %xmm2
movapd 0xc44c1(%rip), %xmm3    # 0xf3190
andpd %xmm2, %xmm3
ucomisd 0xc6bcd(%rip), %xmm3    # 0xf58a8
jbe 0x2ed04
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
pushq $0x2
jmp 0x2ebda
movsd 0xc43d4(%rip), %xmm3    # 0xf30e0
ucomisd %xmm0, %xmm3
ja 0x2ed4c
ucomisd 0xc6c7e(%rip), %xmm0    # 0xf5998
ja 0x2ed4c
movsd 0xc443c(%rip), %xmm0    # 0xf3160
divsd %xmm0, %xmm1
movsd %xmm1, (%r12)
divsd %xmm0, %xmm2
movsd %xmm2, (%r15)
leaq 0x2f65ca(%rip), %rax    # 0x325308
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
xorl %r14d, %r14d
jmp 0x2ebdc
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r12)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r13)
pushq $0x3
jmp 0x2ebda