// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movsd 0x57f4e(%rip), %xmm5    # 0x10b820
movsd %xmm0, -0x10(%rbp)
mulsd %xmm5, %xmm0
movsd 0x57f35(%rip), %xmm4    # 0x10b818
divsd %xmm4, %xmm0
movsd %xmm0, -0x40(%rbp)
mulsd %xmm5, %xmm1
divsd %xmm4, %xmm1
movsd %xmm1, -0x20(%rbp)
addsd %xmm5, %xmm1
movsd 0x6a78b(%rip), %xmm2    # 0x11e090
movapd %xmm1, %xmm3
divsd %xmm2, %xmm3
cvttpd2dq %xmm3, %xmm3
cvtdq2pd %xmm3, %xmm3
mulsd %xmm2, %xmm3
subsd %xmm3, %xmm1
addsd 0x6af93(%rip), %xmm1    # 0x11e8b8
mulsd %xmm1, %xmm4
divsd %xmm5, %xmm4
movsd %xmm4, -0x28(%rbp)
callq 0xb336c
movl %eax, %ebx
movl %eax, 0x2c2c01(%rip)    # 0x376540
movsd -0x40(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
callq 0xb3480
movzbl %al, %ecx
leaq 0x2c2bf8(%rip), %rdi    # 0x376550
leaq 0x72ce6(%rip), %rsi     # 0x126645
movl %ebx, %edx
xorl %eax, %eax
callq 0x9060
movsd -0x40(%rbp), %xmm1
ucomisd 0x6aea3(%rip), %xmm1    # 0x11e818
jae 0xb39ff
movsd 0x6aefd(%rip), %xmm0    # 0x11e880
ucomisd %xmm1, %xmm0
jae 0xb39ff
xorps %xmm0, %xmm0
cvtsi2sdl 0x2c2bac(%rip), %xmm0 # 0x376540
mulsd 0x6af24(%rip), %xmm0    # 0x11e8c0
addsd 0x6a73c(%rip), %xmm0    # 0x11e0e0
mulsd 0x57e6c(%rip), %xmm0    # 0x10b818
divsd 0x57e6c(%rip), %xmm0    # 0x10b820
movsd %xmm0, -0x18(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x20(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x9080
movsd -0x20(%rbp), %xmm1
mulsd 0x6a6c1(%rip), %xmm1    # 0x11e0a0
mulsd %xmm0, %xmm1
addsd 0x55685(%rip), %xmm1    # 0x109070
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movapd %xmm1, %xmm0
jb 0xb3a13
sqrtsd %xmm0, %xmm0
jmp 0xb3a18
movsd -0x10(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
callq 0xb37ad
jmp 0xb3cd7
callq 0x9270
movsd 0x6a688(%rip), %xmm1    # 0x11e0a8
divsd %xmm0, %xmm1
movsd %xmm1, -0x20(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x91b0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x91b0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x9710
mulsd 0x6ae6a(%rip), %xmm0    # 0x11e8c8
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x9710
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x9710
movsd -0x28(%rbp), %xmm1
addsd -0x18(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
addsd %xmm0, %xmm0
callq 0x9080
mulsd 0x6ae26(%rip), %xmm0    # 0x11e8d0
movsd 0x6ae26(%rip), %xmm2    # 0x11e8d8
movsd -0x10(%rbp), %xmm1
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, -0x18(%rbp)
movapd %xmm1, %xmm0
mulsd 0x57e98(%rip), %xmm0    # 0x10b968
callq 0x9080
mulsd 0x6ae03(%rip), %xmm0    # 0x11e8e0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x10(%rbp), %xmm0
mulsd 0x6abfc(%rip), %xmm0    # 0x11e6f0
callq 0x9080
mulsd 0x6ade7(%rip), %xmm0    # 0x11e8e8
addsd -0x18(%rbp), %xmm0
mulsd 0x6a59a(%rip), %xmm0    # 0x11e0a8
movsd %xmm0, -0x18(%rbp)
movsd -0x20(%rbp), %xmm0
mulsd 0x6add0(%rip), %xmm0    # 0x11e8f0
movsd 0x55548(%rip), %xmm1    # 0x109070
movsd -0x38(%rbp), %xmm3
subsd %xmm3, %xmm1
movsd -0x30(%rbp), %xmm4
addsd %xmm4, %xmm1
movsd -0x28(%rbp), %xmm5
mulsd %xmm5, %xmm1
mulsd %xmm5, %xmm1
mulsd %xmm5, %xmm1
divsd 0x6ab9d(%rip), %xmm1    # 0x11e6f0
addsd %xmm5, %xmm1
movsd 0x6ad99(%rip), %xmm2    # 0x11e8f8
mulsd %xmm3, %xmm2
addsd 0x555cd(%rip), %xmm2    # 0x109138
movapd %xmm3, %xmm6
mulsd %xmm3, %xmm6
movsd %xmm6, -0x48(%rbp)
addsd %xmm6, %xmm2
movsd 0x6ac8c(%rip), %xmm3    # 0x11e810
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
addsd 0x6ad6c(%rip), %xmm3    # 0x11e900
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
mulsd %xmm5, %xmm3
divsd 0x57d98(%rip), %xmm3    # 0x10b948
addsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
addsd 0x6aa80(%rip), %xmm3    # 0x11e640
movsd %xmm3, 0x2c2970(%rip)   # 0x376538
movsd -0x10(%rbp), %xmm0
callq 0x91b0
movsd -0x28(%rbp), %xmm7
movapd %xmm7, %xmm1
mulsd %xmm7, %xmm1
mulsd 0x55481(%rip), %xmm1    # 0x109068
mulsd -0x20(%rbp), %xmm0
movsd -0x38(%rbp), %xmm6
movsd 0x5553f(%rip), %xmm3    # 0x109138
subsd %xmm6, %xmm3
movsd 0x6ab53(%rip), %xmm2    # 0x11e758
movsd -0x30(%rbp), %xmm4
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
movsd 0x57d4e(%rip), %xmm3    # 0x10b968
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
addsd %xmm2, %xmm3
mulsd %xmm7, %xmm3
mulsd %xmm7, %xmm3
mulsd %xmm7, %xmm3
mulsd %xmm7, %xmm3
divsd 0x55402(%rip), %xmm3    # 0x109040
movapd %xmm3, %xmm5
movapd %xmm6, %xmm2
mulsd 0x6acba(%rip), %xmm2    # 0x11e908
addsd 0x6acba(%rip), %xmm2    # 0x11e910
movapd %xmm2, %xmm3
movapd %xmm4, %xmm2
mulsd 0x57dda(%rip), %xmm2    # 0x10ba40
addsd -0x48(%rbp), %xmm3
addsd %xmm3, %xmm2
addsd 0x6aca1(%rip), %xmm2    # 0x11e918
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm7, %xmm2
divsd 0x6ac89(%rip), %xmm2    # 0x11e920
addsd %xmm1, %xmm5
movapd %xmm2, %xmm1
addsd %xmm5, %xmm1
mulsd %xmm0, %xmm1
addsd -0x18(%rbp), %xmm1
mulsd 0x6ac3c(%rip), %xmm1    # 0x11e8f0
movsd %xmm1, 0x2c2874(%rip)   # 0x376530
xorpd %xmm0, %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0xb3cd7
addsd 0x57bf9(%rip), %xmm1    # 0x10b8c8
movsd %xmm1, 0x2c2859(%rip)   # 0x376530
movb $0x0, 0x2c2894(%rip)    # 0x376572
movw $0x3f3f, 0x2c2889(%rip) # imm = 0x3F3F
leaq 0x2592c2(%rip), %rax    # 0x30cfb0
cmpb $0x4, (%rax)
jne 0xb3db0
movsd 0x2c2831(%rip), %xmm0   # 0x376530
movl $0x1, %esi
ucomisd 0x553bc(%rip), %xmm0    # 0x1090c8
jb 0xb3d49
movsd 0x6aa7a(%rip), %xmm1    # 0x11e790
movsd 0x553aa(%rip), %xmm2    # 0x1090c8
addsd %xmm1, %xmm0
incl %esi
ucomisd %xmm2, %xmm0
jae 0xb3d1e
movsd %xmm0, 0x2c27fe(%rip)   # 0x376530
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, 0x2c27d8(%rip)   # 0x376530
movsd 0x2c27d8(%rip), %xmm0   # 0x376538
xorl %edx, %edx
ucomisd 0x5535e(%rip), %xmm0    # 0x1090c8
jb 0xb3d95
xorl %edx, %edx
movsd 0x6aa1a(%rip), %xmm1    # 0x11e790
movsd 0x5534a(%rip), %xmm2    # 0x1090c8
addsd %xmm1, %xmm0
incl %edx
ucomisd %xmm2, %xmm0
jae 0xb3d7e
movsd %xmm0, 0x2c27a6(%rip)   # 0x376538
andl $0x7, %edx
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movlpd %xmm0, 0x2c2793(%rip)   # 0x376538
movl 0x2c2795(%rip), %edi    # 0x376540
callq 0xb3700
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %rbp
retq