// File: jingdao[P]PointCloudApp/pcd.cpp
// Function: wgs2utm(double, double, double*, double*)
void wgs2utm(double lat, double lon, double *easting, double *northing) {
	double a = 6378137;
	double f = 1 / 298.257223563;
	double k0 = 0.9996;
	double b = a * (1 - f);
	double e = sqrt(1 - b * b / a / a);
	double phi = lat / 180 * M_PI;

	double utmz = 1 + floor((lon + 180) / 6);            // longitude to utm zone
	double zcm = 3 + 6 * (utmz - 1) - 180;                     // central meridian of a zone
	double esq = (1 - (b / a) * (b / a));
	double e0sq = e * e / (1 - pow(e, 2));
	double M = 0;

	double N = a / sqrt(1 - pow(e * sin(phi), 2));
	double T = pow(tan(phi), 2);
	double C = e0sq * pow(cos(phi), 2);
	double A = (lon - zcm) * M_PI / 180 * cos(phi);

	// calculate M (USGS style)
	M = phi * (1 - esq * (1.0 / 4 + esq * (3.0 / 64 + 5 * esq / 256)));
	M = M - sin(2 * phi) * (esq * (3.0 / 8 + esq * (3.0 / 32 + 45 * esq / 1024)));
	M = M + sin(4 * phi) * (esq * esq * (15.0 / 256 + esq * 45.0 / 1024));
	M = M - sin(6 * phi) * (esq * esq * esq * (35.0 / 3072));
	M = M * a;                                      //Arc length along standard meridian
	double M0 = 0;                                         // if another point of origin is used than the equator

	// now we are ready to calculate the UTM values...
	// first the easting
	double x = k0 * N * A * (1 + A * A * ((1 - T + C) / 6 + A * A * (5 - 18 * T + T * T + 72 * C - 58 * e0sq) / 120)); //Easting relative to CM
	x = x + 500000; // standard easting
	// now the northing
	double y = k0 * (M - M0 + N * tan(phi) * (A * A * (1.0 / 2 + A * A * ((5 - T + 9 * C + 4 * C * C) / 24 + A * A * (61 - 58 * T + T * T + 600 * C - 330 * e0sq) / 720))));    // first from the equator
	if (y < 0) {
		y = 10000000 + y;   // add in false northing if south of the equator
	}

	*easting = x;
	*northing = y;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movsd 0xfb73(%rip), %xmm0     # 0x132f8
movsd %xmm0, -0x28(%rbp)
movsd 0xfb5e(%rip), %xmm0     # 0x132f0
movsd %xmm0, -0x30(%rbp)
movsd 0xfb49(%rip), %xmm0     # 0x132e8
movsd %xmm0, -0x38(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0xfaa7(%rip), %xmm1     # 0x13258
subsd -0x30(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm1
mulsd -0x40(%rbp), %xmm1
divsd -0x28(%rbp), %xmm1
divsd -0x28(%rbp), %xmm1
movsd 0xfa7d(%rip), %xmm0     # 0x13258
subsd %xmm1, %xmm0
callq 0x2170
movsd %xmm0, -0x48(%rbp)
movsd -0x8(%rbp), %xmm0
movsd 0xfada(%rip), %xmm1     # 0x132d0
divsd %xmm1, %xmm0
movsd 0xfad6(%rip), %xmm1     # 0x132d8
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0xfabd(%rip), %xmm0     # 0x132d0
addsd -0x10(%rbp), %xmm0
movsd 0xfa58(%rip), %xmm1     # 0x13278
divsd %xmm1, %xmm0
callq 0x2360
movaps %xmm0, %xmm1
movsd 0xfa24(%rip), %xmm0     # 0x13258
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd 0xfa0e(%rip), %xmm1     # 0x13258
subsd %xmm1, %xmm0
movsd 0xfa22(%rip), %xmm1     # 0x13278
mulsd %xmm1, %xmm0
movsd 0xfa7e(%rip), %xmm1     # 0x132e0
addsd %xmm1, %xmm0
movsd 0xfa62(%rip), %xmm1     # 0x132d0
subsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x40(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
divsd -0x28(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm1, %xmm0
movsd 0xf9aa(%rip), %xmm1     # 0x13258
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x48(%rbp), %xmm0
mulsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x108(%rbp)
movsd -0x48(%rbp), %xmm0
movl $0x2, %edi
callq 0xa9a0
movaps %xmm0, %xmm2
movsd -0x108(%rbp), %xmm0
movsd 0xf96d(%rip), %xmm1     # 0x13258
subsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x2070
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
mulsd %xmm1, %xmm0
movl $0x2, %edi
callq 0xa9a0
movaps %xmm0, %xmm1
movsd 0xf910(%rip), %xmm0     # 0x13258
subsd %xmm1, %xmm0
callq 0x2170
movaps %xmm0, %xmm1
movsd -0xf8(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x2110
movl $0x2, %edi
callq 0xa9a0
movsd %xmm0, -0x88(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x23a0
movl $0x2, %edi
callq 0xa9a0
movaps %xmm0, %xmm1
movsd -0xf0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x10(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
movsd 0xf90d(%rip), %xmm1     # 0x132d8
mulsd %xmm1, %xmm0
movsd 0xf8f9(%rip), %xmm1     # 0x132d0
divsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x23a0
movaps %xmm0, %xmm1
movsd -0xe8(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
movsd 0xf82d(%rip), %xmm4     # 0x13248
mulsd -0x68(%rbp), %xmm4
movsd 0xf8a0(%rip), %xmm3     # 0x132c8
divsd %xmm3, %xmm4
movsd 0xf88c(%rip), %xmm3     # 0x132c0
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm2
movsd 0xf874(%rip), %xmm3     # 0x132b8
addsd %xmm3, %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
movsd 0xf7ed(%rip), %xmm2     # 0x13258
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd 0xf823(%rip), %xmm0     # 0x132b0
mulsd -0x50(%rbp), %xmm0
callq 0x2070
movsd -0xe0(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
movsd -0x68(%rbp), %xmm3
movsd 0xf7e7(%rip), %xmm5     # 0x13298
mulsd -0x68(%rbp), %xmm5
movsd 0xf7d2(%rip), %xmm4     # 0x13290
divsd %xmm4, %xmm5
movsd 0xf7de(%rip), %xmm4     # 0x132a8
addsd %xmm5, %xmm4
mulsd %xmm4, %xmm3
movsd 0xf7c6(%rip), %xmm4     # 0x132a0
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd 0xf71d(%rip), %xmm0     # 0x13238
mulsd -0x50(%rbp), %xmm0
callq 0x2070
movsd -0xd8(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
mulsd -0x68(%rbp), %xmm2
movsd 0xf759(%rip), %xmm4     # 0x13298
mulsd -0x68(%rbp), %xmm4
movsd 0xf744(%rip), %xmm3     # 0x13290
divsd %xmm3, %xmm4
movsd 0xf730(%rip), %xmm3     # 0x13288
addsd %xmm4, %xmm3
mulsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd 0xf6f6(%rip), %xmm0     # 0x13278
mulsd -0x50(%rbp), %xmm0
callq 0x2070
movsd -0xd0(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
mulsd -0x68(%rbp), %xmm2
mulsd -0x68(%rbp), %xmm2
movsd 0xf6d5(%rip), %xmm3     # 0x13280
mulsd %xmm3, %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x38(%rbp), %xmm0
mulsd -0x80(%rbp), %xmm0
mulsd -0x98(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
mulsd -0x98(%rbp), %xmm1
movsd 0xf641(%rip), %xmm2     # 0x13258
subsd -0x88(%rbp), %xmm2
addsd -0x90(%rbp), %xmm2
movsd 0xf649(%rip), %xmm3     # 0x13278
divsd %xmm3, %xmm2
movsd -0x98(%rbp), %xmm3
mulsd -0x98(%rbp), %xmm3
movsd -0x88(%rbp), %xmm5
movsd 0xf61d(%rip), %xmm4     # 0x13270
mulsd %xmm4, %xmm5
movsd 0xf5e9(%rip), %xmm4     # 0x13248
addsd %xmm4, %xmm5
movsd -0x88(%rbp), %xmm4
movsd -0x88(%rbp), %xmm6
mulsd %xmm6, %xmm4
addsd %xmm5, %xmm4
movsd -0x90(%rbp), %xmm5
movsd 0xf5dd(%rip), %xmm6     # 0x13268
mulsd %xmm6, %xmm5
addsd %xmm4, %xmm5
movsd -0x70(%rbp), %xmm4
movsd 0xf580(%rip), %xmm6     # 0x13220
mulsd %xmm6, %xmm4
addsd %xmm5, %xmm4
mulsd %xmm4, %xmm3
movsd 0xf5ac(%rip), %xmm4     # 0x13260
divsd %xmm4, %xmm3
addsd %xmm3, %xmm2
mulsd %xmm2, %xmm1
movsd 0xf590(%rip), %xmm2     # 0x13258
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd 0xf570(%rip), %xmm0     # 0x13250
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x78(%rbp), %xmm0
subsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x2110
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xb8(%rbp), %xmm0
mulsd %xmm3, %xmm1
movsd -0x98(%rbp), %xmm3
mulsd -0x98(%rbp), %xmm3
movsd -0x98(%rbp), %xmm4
mulsd -0x98(%rbp), %xmm4
movsd 0xf4d8(%rip), %xmm5     # 0x13248
subsd -0x88(%rbp), %xmm5
movsd -0x90(%rbp), %xmm6
movsd 0xf4b8(%rip), %xmm7     # 0x13240
mulsd %xmm7, %xmm6
addsd %xmm5, %xmm6
movsd 0xf4a0(%rip), %xmm5     # 0x13238
mulsd -0x90(%rbp), %xmm5
movsd -0x90(%rbp), %xmm7
mulsd %xmm7, %xmm5
addsd %xmm6, %xmm5
movsd 0xf478(%rip), %xmm6     # 0x13230
divsd %xmm6, %xmm5
movsd -0x98(%rbp), %xmm6
mulsd -0x98(%rbp), %xmm6
movsd -0x88(%rbp), %xmm8
movsd 0xf443(%rip), %xmm7     # 0x13220
mulsd %xmm7, %xmm8
movsd 0xf43e(%rip), %xmm7     # 0x13228
addsd %xmm7, %xmm8
movsd -0x88(%rbp), %xmm7
movsd -0x88(%rbp), %xmm9
mulsd %xmm9, %xmm7
addsd %xmm8, %xmm7
movsd -0x90(%rbp), %xmm8
movsd 0xf3fc(%rip), %xmm9     # 0x13218
mulsd %xmm9, %xmm8
addsd %xmm7, %xmm8
movsd -0x70(%rbp), %xmm7
movsd 0xf3dc(%rip), %xmm9     # 0x13210
mulsd %xmm9, %xmm7
addsd %xmm8, %xmm7
mulsd %xmm7, %xmm6
movsd 0xf3be(%rip), %xmm7     # 0x13208
divsd %xmm7, %xmm6
addsd %xmm6, %xmm5
mulsd %xmm5, %xmm4
movsd 0xf3a2(%rip), %xmm5     # 0x13200
addsd %xmm5, %xmm4
mulsd %xmm4, %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xb0(%rbp)
xorps %xmm0, %xmm0
ucomisd -0xb0(%rbp), %xmm0
jbe 0x3e9f
movsd 0xf471(%rip), %xmm0     # 0x13300
addsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xa8(%rbp), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0xb0(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)