// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: lla_to_utm(double, double)
int lla_to_utm(double dLatRad, double dLonRad)
{
double dLat;
double dLon;
double dLonWork;
double dCentralMeridian_Rad;
double N;
double T;
double K;
double A;
double M;
int row,col;

   // convert radians to degrees
   dLat = dLatRad * 180.0/PI;
   dLon = dLonRad * 180.0/PI;

   // use dLonWork to make sure the longitude is between -180.00 .. 179.9
   dLonWork = (dLon + 180.0) - ((int)((dLon + 180.0) / 360.0)) * 360.0 - 180.0; // -180.00 .. 179.9;
   // convert degrees to radians
   dLonRad = dLonWork * PI / 180.0;

   // set the UTM zone string
   UTM_Zone = utm_lon_zone(dLat, dLonWork);
   sprintf(utm_zone_string, "%02d%c", UTM_Zone, utm_lat_zone(dLat, dLon));

   if((dLat >= 84.0) || (dLat <= (-80.0))) {  // polar regions
      lla_to_ups(dLatRad, dLonRad);
   }
   else { // normal regions
      // set central meridian
      dCentralMeridian_Rad = ((183.0 - (6.0 * (double)UTM_Zone)) * -1.0) * PI / 180.0;

      N = WGS84_A / sqrt(1.0 - eccSquared * sin(dLatRad) * sin(dLatRad));
      T = tan(dLatRad) * tan(dLatRad);
      K = eccPrimeSquared * cos(dLatRad) * cos(dLatRad);
      A = cos(dLatRad) * (dLonRad - dCentralMeridian_Rad);
      M = WGS84_A * ((1.0 - eccSquared / 4.0 - 3.0 * eccSquared * eccSquared / 64.0 - 5.0 * eccSquared * eccSquared * eccSquared / 256.0) * dLatRad
          - (3.0 * eccSquared / 8.0 + 3.0 * eccSquared * eccSquared / 32.0 + 45.0 * eccSquared * eccSquared * eccSquared / 1024.0) * sin(2.0 * dLatRad)
          + (15.0 * eccSquared * eccSquared / 256.0 + 45.0 * eccSquared * eccSquared * eccSquared / 1024.0) * sin(4.0 * dLatRad)
          - (35.0 * eccSquared * eccSquared * eccSquared / 3072.0) * sin(6.0 * dLatRad));

      UTMEasting = (double)(dScaleFactor * N * (A + (1.0 - T + K) * A * A * A / 6.0
                 + (5.0 - 18.0 * T + T * T + 72.0 * K - 58.0 * eccPrimeSquared) * A * A * A * A * A / 120.0) + 500000.0);

      UTMNorthing = (double)(dScaleFactor * (M + N * tan(dLatRad) * (A * A / 2.0 + (5.0 - T + 9.0 * K + 4 * K * K) * A * A * A * A / 24.0
                  + (61.0 - 58.0 * T + T * T + 600.0 * K - 330.0 * eccPrimeSquared) * A * A * A * A * A * A / 720.0)));
      if(dLat < 0.0) UTMNorthing += 10000000.0; // 10000000 meter offset for southern hemisphere
   }

   col = (0);
   row = (0);
   strcpy(mgrs_square, "??");

   if(dms == NATO_FMT) {
      row = 1;
      while(UTMNorthing >= 100000.0) {
         UTMNorthing -= 100000.0;
         ++row;
      }
      row = (row % 20);
      UTMNorthing = (double) (int) UTMNorthing;

      col = 0;
      while(UTMEasting >= 100000.0) {
         UTMEasting -= 100000.0;
         ++col;
      }
      col = (col % 8);
      UTMEasting  = (double) (int) UTMEasting;

      calc_mgrs_square(UTM_Zone, row,col);
   }
//sprintf(plot_title, "utm: E:%f(%d) N:%f(%d)  %s  mgrs:%s", UTMEasting,col, UTMNorthing,row, utm_zone_string, mgrs_square);

   return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x68, %rsp
movsd 0x57bdd(%rip), %xmm5    # 0x10b830
movapd %xmm0, -0x30(%rbp)
mulsd %xmm5, %xmm0
movsd 0x57bc4(%rip), %xmm4    # 0x10b828
divsd %xmm4, %xmm0
movapd %xmm0, -0x50(%rbp)
mulsd %xmm5, %xmm1
divsd %xmm4, %xmm1
movsd %xmm1, -0x10(%rbp)
addsd %xmm5, %xmm1
movsd 0x6a4b2(%rip), %xmm2    # 0x11e138
movapd %xmm1, %xmm3
divsd %xmm2, %xmm3
cvttpd2dq %xmm3, %xmm3
cvtdq2pd %xmm3, %xmm3
mulsd %xmm2, %xmm3
subsd %xmm3, %xmm1
addsd 0x6acc2(%rip), %xmm1    # 0x11e968
mulsd %xmm1, %xmm4
divsd %xmm5, %xmm4
movsd %xmm4, -0x38(%rbp)
callq 0xb3701
movl %eax, %ebx
movl %eax, 0x2c2880(%rip)    # 0x376540
movapd -0x50(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
callq 0xb3815
movzbl %al, %ecx
leaq 0x2c2877(%rip), %rdi    # 0x376550
leaq 0x72a45(%rip), %rsi     # 0x126725
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movapd -0x50(%rbp), %xmm1
ucomisd 0x6abd2(%rip), %xmm1    # 0x11e8c8
jae 0xb3d86
movsd 0x6ac2c(%rip), %xmm0    # 0x11e930
ucomisd %xmm1, %xmm0
jae 0xb3d86
xorps %xmm0, %xmm0
cvtsi2sdl 0x2c282b(%rip), %xmm0 # 0x376540
mulsd 0x6ac53(%rip), %xmm0    # 0x11e970
addsd 0x6a463(%rip), %xmm0    # 0x11e188
mulsd 0x57afb(%rip), %xmm0    # 0x10b828
divsd 0x57afb(%rip), %xmm0    # 0x10b830
movsd %xmm0, -0x18(%rbp)
movaps -0x30(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x10(%rbp)
movapd -0x30(%rbp), %xmm0
callq 0x9080
movsd -0x10(%rbp), %xmm1
mulsd 0x6a3e9(%rip), %xmm1    # 0x11e148
mulsd %xmm0, %xmm1
addsd 0x55305(%rip), %xmm1    # 0x109070
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movapd %xmm1, %xmm0
jb 0xb3e84
sqrtsd %xmm0, %xmm0
jmp 0xb3e89
movapd 0x55402(%rip), %xmm0    # 0x109190
andpd -0x30(%rbp), %xmm0
movapd %xmm0, -0x50(%rbp)
callq 0x9080
mulsd 0x6ab93(%rip), %xmm0    # 0x11e938
addsd 0x552c3(%rip), %xmm0    # 0x109070
movsd %xmm0, -0x10(%rbp)
movapd -0x50(%rbp), %xmm0
callq 0x9080
mulsd 0x6ab7c(%rip), %xmm0    # 0x11e940
addsd 0x552a4(%rip), %xmm0    # 0x109070
movsd -0x10(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x6ab6b(%rip), %xmm1    # 0x11e948
movapd %xmm2, %xmm0
callq 0x96b0
movsd %xmm0, -0x10(%rbp)
movapd -0x50(%rbp), %xmm0
mulsd 0x57b90(%rip), %xmm0    # 0x10b988
addsd 0x6ab50(%rip), %xmm0    # 0x11e950
callq 0x91b0
mulsd -0x10(%rbp), %xmm0
mulsd 0x6ab46(%rip), %xmm0    # 0x11e958
movapd %xmm0, -0x50(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x9710
movapd 0x55387(%rip), %xmm1    # 0x1091b0
movapd -0x50(%rbp), %xmm4
xorpd %xmm4, %xmm1
xorpd %xmm2, %xmm2
cmpnlesd -0x30(%rbp), %xmm2
movapd %xmm2, %xmm3
andpd %xmm4, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
mulsd %xmm0, %xmm2
addsd 0x6ab08(%rip), %xmm2    # 0x11e960
movsd %xmm2, 0x2c26d0(%rip)   # 0x376530
movsd -0x38(%rbp), %xmm0
callq 0x9080
mulsd -0x50(%rbp), %xmm0
addsd 0x6aae9(%rip), %xmm0    # 0x11e960
movsd %xmm0, 0x2c26b9(%rip)   # 0x376538
jmp 0xb4147
callq 0x9270
movsd 0x6a2bf(%rip), %xmm1    # 0x11e150
divsd %xmm0, %xmm1
movsd %xmm1, -0x10(%rbp)
movaps -0x30(%rbp), %xmm0
callq 0x91b0
movsd %xmm0, -0x60(%rbp)
movapd -0x30(%rbp), %xmm0
callq 0x91b0
mulsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movapd -0x30(%rbp), %xmm0
callq 0x9710
mulsd 0x6aaaa(%rip), %xmm0    # 0x11e978
movsd %xmm0, -0x58(%rbp)
movapd -0x30(%rbp), %xmm0
callq 0x9710
mulsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movapd -0x30(%rbp), %xmm0
callq 0x9710
movsd -0x38(%rbp), %xmm1
addsd -0x18(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movapd -0x30(%rbp), %xmm0
addsd %xmm0, %xmm0
callq 0x9080
mulsd 0x6aa66(%rip), %xmm0    # 0x11e980
movsd 0x6aa66(%rip), %xmm2    # 0x11e988
movapd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, -0x18(%rbp)
movapd %xmm1, %xmm0
mulsd 0x57a30(%rip), %xmm0    # 0x10b970
callq 0x9080
mulsd 0x6aa43(%rip), %xmm0    # 0x11e990
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movapd -0x30(%rbp), %xmm0
mulsd 0x6a83c(%rip), %xmm0    # 0x11e7a0
callq 0x9080
mulsd 0x6aa27(%rip), %xmm0    # 0x11e998
addsd -0x18(%rbp), %xmm0
mulsd 0x6a1d2(%rip), %xmm0    # 0x11e150
movsd %xmm0, -0x18(%rbp)
movsd -0x10(%rbp), %xmm0
mulsd 0x6aa10(%rip), %xmm0    # 0x11e9a0
movsd 0x550d8(%rip), %xmm1    # 0x109070
movsd -0x60(%rbp), %xmm3
subsd %xmm3, %xmm1
movsd -0x58(%rbp), %xmm4
addsd %xmm4, %xmm1
movsd -0x38(%rbp), %xmm5
mulsd %xmm5, %xmm1
mulsd %xmm5, %xmm1
mulsd %xmm5, %xmm1
divsd 0x6a7dd(%rip), %xmm1    # 0x11e7a0
addsd %xmm5, %xmm1
movsd 0x6a9d9(%rip), %xmm2    # 0x11e9a8
mulsd %xmm3, %xmm2
addsd 0x5515d(%rip), %xmm2    # 0x109138
movapd %xmm3, %xmm6
mulsd %xmm3, %xmm6
movsd %xmm6, -0x68(%rbp)
addsd %xmm6, %xmm2
movsd 0x6a8cc(%rip), %xmm3    # 0x11e8c0
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
addsd 0x6a9ac(%rip), %xmm3    # 0x11e9b0
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
divsd 0x57930(%rip), %xmm3    # 0x10b950
addsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
addsd 0x6a6b0(%rip), %xmm3    # 0x11e6e0
movsd %xmm3, 0x2c2500(%rip)   # 0x376538
movapd -0x30(%rbp), %xmm0
callq 0x91b0
movsd -0x38(%rbp), %xmm7
movapd %xmm7, %xmm1
mulsd %xmm7, %xmm1
mulsd 0x55011(%rip), %xmm1    # 0x109068
mulsd -0x10(%rbp), %xmm0
movsd -0x60(%rbp), %xmm6
movsd 0x550cf(%rip), %xmm3    # 0x109138
subsd %xmm6, %xmm3
movsd 0x6a793(%rip), %xmm2    # 0x11e808
movsd -0x58(%rbp), %xmm4
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
movsd 0x578e6(%rip), %xmm3    # 0x10b970
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
mulsd %xmm7, %xmm3
mulsd %xmm7, %xmm3
mulsd %xmm7, %xmm3
mulsd %xmm7, %xmm3
divsd 0x54f92(%rip), %xmm3    # 0x109040
movapd %xmm3, %xmm5
movapd %xmm6, %xmm2
mulsd 0x6a8fa(%rip), %xmm2    # 0x11e9b8
addsd 0x6a8fa(%rip), %xmm2    # 0x11e9c0
movapd %xmm2, %xmm3
movapd %xmm4, %xmm2
mulsd 0x5796a(%rip), %xmm2    # 0x10ba40
addsd -0x68(%rbp), %xmm3
addsd %xmm3, %xmm2
addsd 0x6a8e1(%rip), %xmm2    # 0x11e9c8
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
divsd 0x6a8c9(%rip), %xmm2    # 0x11e9d0
addsd %xmm1, %xmm5
movapd %xmm2, %xmm1
addsd %xmm5, %xmm1
mulsd %xmm0, %xmm1
addsd -0x18(%rbp), %xmm1
mulsd 0x6a87c(%rip), %xmm1    # 0x11e9a0
movsd %xmm1, 0x2c2404(%rip)   # 0x376530
xorpd %xmm0, %xmm0
ucomisd -0x50(%rbp), %xmm0
jbe 0xb4147
addsd 0x57799(%rip), %xmm1    # 0x10b8d8
movsd %xmm1, 0x2c23e9(%rip)   # 0x376530
movb $0x0, 0x2c2424(%rip)    # 0x376572
movw $0x3f3f, 0x2c2419(%rip) # imm = 0x3F3F
leaq 0x258e52(%rip), %rax    # 0x30cfb0
cmpb $0x4, (%rax)
jne 0xb4210
movsd 0x2c23c1(%rip), %xmm0   # 0x376530
movl $0x1, %esi
ucomisd 0x54f4c(%rip), %xmm0    # 0x1090c8
jb 0xb41b1
movsd 0x6a6ba(%rip), %xmm1    # 0x11e840
movsd 0x54f3a(%rip), %xmm2    # 0x1090c8
addsd %xmm1, %xmm0
incl %esi
ucomisd %xmm2, %xmm0
jae 0xb418e
movl %esi, %eax
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
imulq %rax, %rcx
shrq $0x24, %rcx
shll $0x2, %ecx
leal (%rcx,%rcx,4), %eax
subl %eax, %esi
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movlps %xmm0, 0x2c2370(%rip)   # 0x376530
movsd 0x2c2370(%rip), %xmm0   # 0x376538
xorl %edx, %edx
ucomisd 0x54ef6(%rip), %xmm0    # 0x1090c8
jb 0xb41f5
xorl %edx, %edx
movsd 0x6a662(%rip), %xmm1    # 0x11e840
movsd 0x54ee2(%rip), %xmm2    # 0x1090c8
addsd %xmm1, %xmm0
incl %edx
ucomisd %xmm2, %xmm0
jae 0xb41e6
andl $0x7, %edx
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movlpd %xmm0, 0x2c2333(%rip)   # 0x376538
movl 0x2c2335(%rip), %edi    # 0x376540
callq 0xb3a95
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %rbp
retq