#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 atan(double);
double atan2(double const, double const);
double dot(double const *, double const *, int);
int fabs(double);
double sqrt(double);
extern void ecef2pos(const double *r, double *pos) {
  double e2 = (1.0 / 298.257223563) * (2.0 - (1.0 / 298.257223563)),
         r2 = dot(r, r, 2), z, zk, v = 6378137.0, sinp;
  for (z = r[2], zk = 0.0; fabs(z - zk) >= 1E-4;) {
    zk = z;
    sinp = z / sqrt(r2 + z * z);
    v = 6378137.0 / sqrt(1.0 - e2 * sinp * sinp);
    z = r[2] + v * e2 * sinp;
  }
  pos[0] = r2 > 1E-12 ? atan(z / sqrt(r2))
                      : (r[2] > 0.0 ? 3.1415926535897932 / 2.0
                                    : -3.1415926535897932 / 2.0);
  pos[1] = r2 > 1E-12 ? atan2(r[1], r[0]) : 0.0;
  pos[2] = sqrt(r2 + z * z) - v;
}


x86 assembly (clang, -O0):
<ecef2pos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xea0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1030 <dot@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xe74(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
call   1050 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe4e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1286 <ecef2pos+0x136>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdf1(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xdad(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11a7 <ecef2pos+0x57>
movsd  -0x20(%rbp),%xmm0
movsd  0xd85(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    12cc <ecef2pos+0x17c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1060 <atan@plt>
movsd  %xmm0,-0x50(%rbp)
jmp    1301 <ecef2pos+0x1b1>
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
movsd  0xd43(%rip),%xmm3
movsd  0xd43(%rip),%xmm2
xorps  %xmm0,%xmm0
cmpltsd %xmm1,%xmm0
movaps %xmm0,%xmm1
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x20(%rbp),%xmm0
movsd  0xcfd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1345 <ecef2pos+0x1f5>
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
call   1040 <atan2@plt>
movsd  %xmm0,-0x60(%rbp)
jmp    1352 <ecef2pos+0x202>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1352 <ecef2pos+0x202>
movsd  -0x60(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
subsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecef2pos>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdi,%rsi
mov    $0x2,%edx
call   1030 <dot@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1050 <fabs@plt>
test   %eax,%eax
jle    1272 <ecef2pos+0x122>
movsd  0x8(%rsp),%xmm4
movsd  0x10(%rsp),%xmm2
jmp    1205 <ecef2pos+0xb5>
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
call   1070 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x20(%rsp),%xmm4
movsd  0xe41(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movapd %xmm1,%xmm0
mulsd  0xe43(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x8(%rsp)
subsd  %xmm4,%xmm0
call   1050 <fabs@plt>
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm4
test   %eax,%eax
movsd  0x10(%rsp),%xmm2
jle    128c <ecef2pos+0x13c>
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe0f(%rip),%xmm0
movsd  %xmm4,0x20(%rsp)
jb     1230 <ecef2pos+0xe0>
sqrtsd %xmm0,%xmm0
jmp    123b <ecef2pos+0xeb>
nopw   0x0(%rax,%rax,1)
call   1070 <sqrt@plt>
movsd  0x20(%rsp),%xmm4
movapd %xmm4,%xmm2
divsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
mulsd  0xdb9(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xdb5(%rip),%xmm0
ucomisd 0xdc5(%rip),%xmm0
jb     11a0 <ecef2pos+0x50>
sqrtsd %xmm0,%xmm0
jmp    11b7 <ecef2pos+0x67>
movsd  0xd86(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
ucomisd 0xd8c(%rip),%xmm2
jbe    12af <ecef2pos+0x15f>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
movsd  %xmm3,0x8(%rsp)
jb     12d4 <ecef2pos+0x184>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    12e3 <ecef2pos+0x193>
movsd  0x10(%rbx),%xmm1
xorpd  %xmm0,%xmm0
xor    %eax,%eax
ucomisd %xmm0,%xmm1
seta   %al
lea    0xd68(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
movsd  %xmm1,(%r14)
jmp    130f <ecef2pos+0x1bf>
movapd %xmm2,%xmm0
call   1070 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
divsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
call   1060 <atan@plt>
movsd  %xmm0,(%r14)
movsd  (%rbx),%xmm1
movsd  0x8(%rbx),%xmm0
call   1040 <atan2@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  %xmm0,0x8(%r14)
mulsd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jb     1330 <ecef2pos+0x1e0>
xorps  %xmm0,%xmm0
sqrtsd %xmm3,%xmm0
jmp    1339 <ecef2pos+0x1e9>
movapd %xmm3,%xmm0
call   1070 <sqrt@plt>
movsd  0x18(%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @ecef2pos(double* %0, double* nocapture writeonly %1) {
%3 = tail call double @dot(double* %0, double* %0, i32 2)
%4 = getelementptr inbounds double, double* %0, i64 2
%5 = load double, double* %4
%6 = tail call i32 @fabs(double %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %2, %8
%9 = phi double [ %19, %8 ], [ %5, %2 ]
%10 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %3)
%11 = tail call double @sqrt(double %10)
%12 = fdiv double %9, %11
%13 = fmul double %12, 0xBF7B6B90F1FE94F0
%14 = tail call double @llvm.fmuladd.f64(double %13, double %12, double 1.000000e+00)
%15 = tail call double @sqrt(double %14)
%16 = fdiv double 0x415854A640000000, %15
%17 = load double, double* %4
%18 = fmul double %16, 0x3F7B6B90F1FE94F0
%19 = tail call double @llvm.fmuladd.f64(double %18, double %12, double %17)
%20 = fsub double %19, %9
%21 = tail call i32 @fabs(double %20)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %8, label %23
23: ; preds = %8, %2
%24 = phi double [ 0x415854A640000000, %2 ], [ %16, %8 ]
%25 = phi double [ %5, %2 ], [ %19, %8 ]
%26 = fcmp ogt double %3, 0x3D719799812DEA11
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load double, double* %4
%29 = fcmp ogt double %28, 0.000000e+00
%30 = select i1 %29, double 0x3FF921FB54442D18, double 0xBFF921FB54442D18
store double %30, double* %1
br label %39
31: ; preds = %23
%32 = tail call double @sqrt(double %3)
%33 = fdiv double %25, %32
%34 = tail call double @atan(double %33)
store double %34, double* %1
%35 = getelementptr inbounds double, double* %0, i64 1
%36 = load double, double* %35
%37 = load double, double* %0
%38 = tail call double @atan2(double %36, double %37)
br label %39
39: ; preds = %27, %31
%40 = phi double [ %38, %31 ], [ 0.000000e+00, %27 ]
%41 = getelementptr inbounds double, double* %1, i64 1
store double %40, double* %41
%42 = tail call double @llvm.fmuladd.f64(double %25, double %25, double %3)
%43 = tail call double @sqrt(double %42)
%44 = fsub double %43, %24
%45 = getelementptr inbounds double, double* %1, i64 2
store double %44, double* %45
ret void
}