// File: jkingan[P]ladyheather/heathgps.cpp
// Function: ecef_to_lla(double, double, double)
void ecef_to_lla(double x, double y, double z)
{
  // convert ECEF coordinate to geocentric lat/lon/alt in radians/meters

  double b = sqrt( (WGS84_A*WGS84_A) * (1.0-(WGS84_E*WGS84_E)) );
  double bsq = (b * b);
  double ep = sqrt( (WGS84_A*WGS84_A - bsq) / bsq);
  double p = sqrt( (x*x) + (y*y) );
  double th = atan2(WGS84_A*z, b*p);

  elon = atan2(y,x);
  elat = atan2( (z + (ep*ep)*b*(sin(th)*sin(th)*sin(th)) ), (p - (WGS84_E*WGS84_E)*WGS84_A*(cos(th)*cos(th)*cos(th))) );

  double N = WGS84_A / ( sqrt(1.0-(WGS84_E*WGS84_E)*(sin(elat)*sin(elat))) );
  ealt = (p / cos(elat)) - N;

  // mod lon to 0-2pi
  elon = fmod(elon,(2.0*PI));
  // correction for altitude near poles left out.  // zork
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movsd %xmm2, -0x18(%rbp)
movsd 0x102d46(%rip), %xmm0   # 0x182b78
callq 0x9280
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x102d1d(%rip), %xmm0   # 0x182b70
subsd -0x28(%rbp), %xmm0
divsd -0x28(%rbp), %xmm0
callq 0x9280
movsd %xmm0, -0x30(%rbp)
movsd -0x8(%rbp), %xmm0
movsd -0x8(%rbp), %xmm2
movsd -0x10(%rbp), %xmm1
mulsd -0x10(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x9280
movsd %xmm0, -0x38(%rbp)
movsd 0x102cb3(%rip), %xmm0   # 0x182b48
mulsd -0x18(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
mulsd -0x38(%rbp), %xmm1
callq 0x9050
movsd %xmm0, -0x40(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
callq 0x9050
movsd %xmm0, 0x34bdbb(%rip)   # 0x3cbc80
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x30(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x9080
movsd %xmm0, -0x98(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x9080
movaps %xmm0, %xmm1
movsd -0x98(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x9080
movsd -0x90(%rbp), %xmm2
movsd -0x88(%rbp), %xmm1
movaps %xmm0, %xmm3
movsd -0x80(%rbp), %xmm0
mulsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x96f0
movsd %xmm0, -0x78(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x96f0
movaps %xmm0, %xmm1
movsd -0x78(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0x96f0
movsd -0x70(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0x60(%rbp), %xmm0
mulsd %xmm3, %xmm1
movsd 0x102bc0(%rip), %xmm3   # 0x182b68
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
callq 0x9050
movsd %xmm0, 0x34bcbb(%rip)   # 0x3cbc78
movsd 0x34bcb3(%rip), %xmm0   # 0x3cbc78
callq 0x9080
movsd %xmm0, -0x58(%rbp)
movsd 0x34bca1(%rip), %xmm0   # 0x3cbc78
callq 0x9080
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd 0x102b70(%rip), %xmm1   # 0x182b60
mulsd %xmm1, %xmm0
movsd 0xef06c(%rip), %xmm1    # 0x16f068
addsd %xmm1, %xmm0
callq 0x9280
movaps %xmm0, %xmm1
movsd 0x102b38(%rip), %xmm0   # 0x182b48
divsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x34bc4d(%rip), %xmm0   # 0x3cbc78
callq 0x96f0
movaps %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
divsd %xmm1, %xmm0
subsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x34bc3f(%rip)   # 0x3cbc88
movsd 0x34bc2f(%rip), %xmm0   # 0x3cbc80
movsd 0x102aff(%rip), %xmm1   # 0x182b58
callq 0x94d0
movsd %xmm0, 0x34bc1a(%rip)   # 0x3cbc80
addq $0xa0, %rsp
popq %rbp
retq
nop