#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double atan2(double, double);
double fabs(double);
double sqrt(double);
void xyz2llh(double *xyz, double *llh) {
  double a, eps, e, e2;
  double x, y, z;
  double rho2, dz, zdz, nh, slat, n, dz_new;
  a = 6378137.0;
  e = 0.0818191908426;
  eps = 1.0e-3;
  e2 = e * e;
  x = xyz[0];
  y = xyz[1];
  z = xyz[2];
  rho2 = x * x + y * y;
  dz = e2 * z;
  while (1) {
    zdz = z + dz;
    nh = sqrt(rho2 + zdz * zdz);
    slat = zdz / nh;
    n = a / sqrt(1.0 - e2 * slat * slat);
    dz_new = n * e2 * slat;
    if (fabs(dz - dz_new) < eps)
      break;
    dz = dz_new;
  }
  llh[0] = atan2(zdz, sqrt(rho2));
  llh[1] = atan2(y, x);
  llh[2] = nh - n;
  return;
}


x86 assembly (clang, -O0):
<xyz2llh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xed5(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xec0(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeab(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdd8(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x58(%rbp),%xmm1
subsd  -0x80(%rbp),%xmm1
movaps 0xd9e(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    129a <xyz2llh+0x17a>
jmp    12a9 <xyz2llh+0x189>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11c2 <xyz2llh+0xa2>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x68(%rbp),%xmm0
subsd  -0x78(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xyz2llh>:
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm0
movsd  0x10(%rdi),%xmm2
movsd  %xmm0,0x28(%rsp)
mulsd  %xmm0,%xmm0
movsd  %xmm1,0x30(%rsp)
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xeaa(%rip),%xmm3
movsd  %xmm2,0x48(%rsp)
mulsd  %xmm2,%xmm3
xorpd  %xmm4,%xmm4
movsd  %xmm1,0x8(%rsp)
jmp    11cf <xyz2llh+0xaf>
nopl   0x0(%rax)
movsd  %xmm6,0x38(%rsp)
call   1040 <sqrt@plt>
movsd  0x38(%rsp),%xmm6
xorpd  %xmm4,%xmm4
movsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
movsd  0xe7f(%rip),%xmm5
divsd  %xmm0,%xmm5
movapd %xmm5,%xmm0
mulsd  0xe57(%rip),%xmm0
mulsd  %xmm0,%xmm6
subsd  %xmm6,%xmm2
andpd  0xe77(%rip),%xmm2
movsd  0xe5f(%rip),%xmm0
ucomisd %xmm2,%xmm0
movapd %xmm6,%xmm3
ja     124b <xyz2llh+0x12b>
movsd  0x48(%rsp),%xmm2
addsd  %xmm3,%xmm2
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm4,%xmm0
movsd  %xmm2,(%rsp)
movapd %xmm3,0x10(%rsp)
jb     1200 <xyz2llh+0xe0>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1212 <xyz2llh+0xf2>
nop
call   1040 <sqrt@plt>
xorpd  %xmm4,%xmm4
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm1
movapd %xmm2,%xmm6
divsd  %xmm1,%xmm6
movapd %xmm6,%xmm0
mulsd  0xde2(%rip),%xmm0
mulsd  %xmm6,%xmm0
addsd  0xdde(%rip),%xmm0
ucomisd %xmm4,%xmm0
movsd  %xmm1,0x40(%rsp)
jb     1170 <xyz2llh+0x50>
sqrtsd %xmm0,%xmm0
jmp    1185 <xyz2llh+0x65>
movsd  %xmm5,0x10(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     1261 <xyz2llh+0x141>
sqrtsd %xmm1,%xmm1
jmp    126e <xyz2llh+0x14e>
movapd %xmm1,%xmm0
call   1040 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%rbx)
movsd  0x28(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x8(%rbx)
movsd  0x40(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rbx)
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @xyz2llh(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store double* %0, double** %3
store double* %1, double** %4
store double 0x415854A640000000, double* %5
store double 0x3FB4F21A3CDAA98E, double* %7
store double 1.000000e-03, double* %6
%19 = load double, double* %7
%20 = load double, double* %7
%21 = fmul double %19, %20
store double %21, double* %8
%22 = load double*, double** %3
%23 = getelementptr inbounds double, double* %22, i64 0
%24 = load double, double* %23
store double %24, double* %9
%25 = load double*, double** %3
%26 = getelementptr inbounds double, double* %25, i64 1
%27 = load double, double* %26
store double %27, double* %10
%28 = load double*, double** %3
%29 = getelementptr inbounds double, double* %28, i64 2
%30 = load double, double* %29
store double %30, double* %11
%31 = load double, double* %9
%32 = load double, double* %9
%33 = load double, double* %10
%34 = load double, double* %10
%35 = fmul double %33, %34
%36 = call double @llvm.fmuladd.f64(double %31, double %32, double %35)
store double %36, double* %12
%37 = load double, double* %8
%38 = load double, double* %11
%39 = fmul double %37, %38
store double %39, double* %13
br label %40
40: ; preds = %2, %73
%41 = load double, double* %11
%42 = load double, double* %13
%43 = fadd double %41, %42
store double %43, double* %14
%44 = load double, double* %12
%45 = load double, double* %14
%46 = load double, double* %14
%47 = call double @llvm.fmuladd.f64(double %45, double %46, double %44)
%48 = call double @sqrt(double %47)
store double %48, double* %15
%49 = load double, double* %14
%50 = load double, double* %15
%51 = fdiv double %49, %50
store double %51, double* %16
%52 = load double, double* %5
%53 = load double, double* %8
%54 = load double, double* %16
%55 = fmul double %53, %54
%56 = load double, double* %16
%57 = fneg double %55
%58 = call double @llvm.fmuladd.f64(double %57, double %56, double 1.000000e+00)
%59 = call double @sqrt(double %58)
%60 = fdiv double %52, %59
store double %60, double* %17
%61 = load double, double* %17
%62 = load double, double* %8
%63 = fmul double %61, %62
%64 = load double, double* %16
%65 = fmul double %63, %64
store double %65, double* %18
%66 = load double, double* %13
%67 = load double, double* %18
%68 = fsub double %66, %67
%69 = call double @llvm.fabs.f64(double %68)
%70 = load double, double* %6
%71 = fcmp olt double %69, %70
br i1 %71, label %72, label %73
72: ; preds = %40
br label %75
73: ; preds = %40
%74 = load double, double* %18
store double %74, double* %13
br label %40
75: ; preds = %72
%76 = load double, double* %14
%77 = load double, double* %12
%78 = call double @sqrt(double %77)
%79 = call double @atan2(double %76, double %78)
%80 = load double*, double** %4
%81 = getelementptr inbounds double, double* %80, i64 0
store double %79, double* %81
%82 = load double, double* %10
%83 = load double, double* %9
%84 = call double @atan2(double %82, double %83)
%85 = load double*, double** %4
%86 = getelementptr inbounds double, double* %85, i64 1
store double %84, double* %86
%87 = load double, double* %15
%88 = load double, double* %17
%89 = fsub double %87, %88
%90 = load double*, double** %4
%91 = getelementptr inbounds double, double* %90, i64 2
store double %89, double* %91
ret void
}

LLVM IR (-O2):
define void @xyz2llh(double* nocapture %0, double* nocapture writeonly %1) {
%3 = load double, double* %0
%4 = getelementptr inbounds double, double* %0, i64 1
%5 = load double, double* %4
%6 = getelementptr inbounds double, double* %0, i64 2
%7 = load double, double* %6
%8 = fmul double %5, %5
%9 = tail call double @llvm.fmuladd.f64(double %3, double %3, double %8)
%10 = fmul double %7, 0x3F7B6B90F1FE851A
br label %11
11: ; preds = %11, %2
%12 = phi double [ %10, %2 ], [ %22, %11 ]
%13 = fadd double %7, %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %9)
%15 = tail call double @sqrt(double %14)
%16 = fdiv double %13, %15
%17 = fmul double %16, 0xBF7B6B90F1FE851A
%18 = tail call double @llvm.fmuladd.f64(double %17, double %16, double 1.000000e+00)
%19 = tail call double @sqrt(double %18)
%20 = fdiv double 0x415854A640000000, %19
%21 = fmul double %20, 0x3F7B6B90F1FE851A
%22 = fmul double %16, %21
%23 = fsub double %12, %22
%24 = tail call double @llvm.fabs.f64(double %23)
%25 = fcmp olt double %24, 1.000000e-03
br i1 %25, label %26, label %11
26: ; preds = %11
%27 = tail call double @sqrt(double %9)
%28 = tail call double @atan2(double %13, double %27)
store double %28, double* %1
%29 = tail call double @atan2(double %5, double %3)
%30 = getelementptr inbounds double, double* %1, i64 1
store double %29, double* %30
%31 = fsub double %15, %20
%32 = getelementptr inbounds double, double* %1, i64 2
store double %31, double* %32
ret void
}