#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 normVect(double const *);
double sqrt(double);
void xyz2llh(const 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;
  if (normVect(xyz) < eps) {
    llh[0] = 0.0;
    llh[1] = 0.0;
    llh[2] = -a;
    return;
  }
  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  0xec5(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb0(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <normVect@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d5 <xyz2llh+0xa5>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
jmp    136f <xyz2llh+0x23f>
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   1050 <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  0xd6c(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <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 0xd32(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1306 <xyz2llh+0x1d6>
jmp    1315 <xyz2llh+0x1e5>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    122e <xyz2llh+0xfe>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
call   1050 <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   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <normVect@plt>
movsd  0xeb6(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    116c <xyz2llh+0x3c>
xorpd  %xmm0,%xmm0
movupd %xmm0,(%r14)
movabs $0xc15854a640000000,%rax
54 58 c1
mov    %rax,0x10(%r14)
jmp    12e6 <xyz2llh+0x1b6>
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
movsd  0x10(%rbx),%xmm2
movsd  %xmm0,0x20(%rsp)
mulsd  %xmm0,%xmm0
movsd  %xmm1,0x28(%rsp)
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe6e(%rip),%xmm3
movsd  %xmm2,0x38(%rsp)
mulsd  %xmm2,%xmm3
xorpd  %xmm4,%xmm4
movsd  %xmm1,0x8(%rsp)
jmp    120f <xyz2llh+0xdf>
movsd  %xmm6,0x30(%rsp)
call   1050 <sqrt@plt>
movsd  0x30(%rsp),%xmm6
xorpd  %xmm4,%xmm4
movsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
movsd  0xe47(%rip),%xmm5
divsd  %xmm0,%xmm5
movapd %xmm5,%xmm0
mulsd  0xe1f(%rip),%xmm0
mulsd  %xmm0,%xmm6
subsd  %xmm6,%xmm2
andpd  0xe37(%rip),%xmm2
movsd  0xdff(%rip),%xmm0
ucomisd %xmm2,%xmm0
movapd %xmm6,%xmm3
ja     128b <xyz2llh+0x15b>
movsd  0x38(%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     1240 <xyz2llh+0x110>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    1252 <xyz2llh+0x122>
nop
call   1050 <sqrt@plt>
xorpd  %xmm4,%xmm4
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm1
movapd %xmm2,%xmm6
divsd  %xmm1,%xmm6
movapd %xmm6,%xmm0
mulsd  0xdaa(%rip),%xmm0
mulsd  %xmm6,%xmm0
addsd  0xda6(%rip),%xmm0
ucomisd %xmm4,%xmm0
movsd  %xmm1,0x40(%rsp)
jb     11b0 <xyz2llh+0x80>
sqrtsd %xmm0,%xmm0
jmp    11c5 <xyz2llh+0x95>
movsd  %xmm5,0x10(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jb     12a1 <xyz2llh+0x171>
sqrtsd %xmm1,%xmm1
jmp    12ae <xyz2llh+0x17e>
movapd %xmm1,%xmm0
call   1050 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%r14)
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
call   1030 <atan2@plt>
movsd  %xmm0,0x8(%r14)
movsd  0x40(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%r14)
add    $0x48,%rsp
pop    %rbx
pop    %r14
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 = call double @normVect(double* %22)
%24 = load double, double* %6
%25 = fcmp olt double %23, %24
br i1 %25, label %26, label %35
26: ; preds = %2
%27 = load double*, double** %4
%28 = getelementptr inbounds double, double* %27, i64 0
store double 0.000000e+00, double* %28
%29 = load double*, double** %4
%30 = getelementptr inbounds double, double* %29, i64 1
store double 0.000000e+00, double* %30
%31 = load double, double* %5
%32 = fneg double %31
%33 = load double*, double** %4
%34 = getelementptr inbounds double, double* %33, i64 2
store double %32, double* %34
br label %106
35: ; preds = %2
%36 = load double*, double** %3
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
store double %38, double* %9
%39 = load double*, double** %3
%40 = getelementptr inbounds double, double* %39, i64 1
%41 = load double, double* %40
store double %41, double* %10
%42 = load double*, double** %3
%43 = getelementptr inbounds double, double* %42, i64 2
%44 = load double, double* %43
store double %44, double* %11
%45 = load double, double* %9
%46 = load double, double* %9
%47 = load double, double* %10
%48 = load double, double* %10
%49 = fmul double %47, %48
%50 = call double @llvm.fmuladd.f64(double %45, double %46, double %49)
store double %50, double* %12
%51 = load double, double* %8
%52 = load double, double* %11
%53 = fmul double %51, %52
store double %53, double* %13
br label %54
54: ; preds = %35, %87
%55 = load double, double* %11
%56 = load double, double* %13
%57 = fadd double %55, %56
store double %57, double* %14
%58 = load double, double* %12
%59 = load double, double* %14
%60 = load double, double* %14
%61 = call double @llvm.fmuladd.f64(double %59, double %60, double %58)
%62 = call double @sqrt(double %61)
store double %62, double* %15
%63 = load double, double* %14
%64 = load double, double* %15
%65 = fdiv double %63, %64
store double %65, double* %16
%66 = load double, double* %5
%67 = load double, double* %8
%68 = load double, double* %16
%69 = fmul double %67, %68
%70 = load double, double* %16
%71 = fneg double %69
%72 = call double @llvm.fmuladd.f64(double %71, double %70, double 1.000000e+00)
%73 = call double @sqrt(double %72)
%74 = fdiv double %66, %73
store double %74, double* %17
%75 = load double, double* %17
%76 = load double, double* %8
%77 = fmul double %75, %76
%78 = load double, double* %16
%79 = fmul double %77, %78
store double %79, double* %18
%80 = load double, double* %13
%81 = load double, double* %18
%82 = fsub double %80, %81
%83 = call double @llvm.fabs.f64(double %82)
%84 = load double, double* %6
%85 = fcmp olt double %83, %84
br i1 %85, label %86, label %87
86: ; preds = %54
br label %89
87: ; preds = %54
%88 = load double, double* %18
store double %88, double* %13
br label %54
89: ; preds = %86
%90 = load double, double* %14
%91 = load double, double* %12
%92 = call double @sqrt(double %91)
%93 = call double @atan2(double %90, double %92)
%94 = load double*, double** %4
%95 = getelementptr inbounds double, double* %94, i64 0
store double %93, double* %95
%96 = load double, double* %10
%97 = load double, double* %9
%98 = call double @atan2(double %96, double %97)
%99 = load double*, double** %4
%100 = getelementptr inbounds double, double* %99, i64 1
store double %98, double* %100
%101 = load double, double* %15
%102 = load double, double* %17
%103 = fsub double %101, %102
%104 = load double*, double** %4
%105 = getelementptr inbounds double, double* %104, i64 2
store double %103, double* %105
br label %106
106: ; preds = %89, %26
ret void
}

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