#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, double);
double const cos(double);
int fabs(double);
double const pow(int /*<<< orphan*/, int);
int /*<<< orphan*/ sin(double);
double const sqrt(double);
void LatLonAlt(double x_n, double y_n, double z_n, double *lat, double *lon,
               double *alt) {
  int iterations = 100;
  const double a = (6378137.0);
  const double e2 = (0.00669437999014132);
  const double p = sqrt(x_n * x_n + y_n * y_n);
  *lon = 2.0 * atan2(y_n, x_n + p);
  *lat = atan(z_n / (p * (1.0 - e2)));
  *alt = 0.0;
  while (iterations > 0) {
    double tmp = *alt;
    double N = a / sqrt(1.0 - e2 * pow(sin(*lat), 2));
    *alt = p / cos(*lat) - N;
    *lat = atan(z_n / (p * (1.0 - e2 * N / (N + *alt))));
    if (fabs(*alt - tmp) < 1e-3)
      break;
    iterations--;
  }
}


x86 assembly (clang, -O0):
<LatLonAlt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
movl   $0x64,-0x34(%rbp)
movsd  0xe76(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe61(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1090 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
addsd  -0x50(%rbp),%xmm1
call   1030 <atan2@plt>
movaps %xmm0,%xmm1
movsd  0xe0f(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  0xdee(%rip),%xmm1
mulsd  -0x50(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1060 <atan@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
cmpl   $0x0,-0x34(%rbp)
jle    1348 <LatLonAlt+0x1d8>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
call   1050 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1080 <pow@plt>
movsd  0xdc5(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdb1(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1090 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xd8d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
divsd  %xmm1,%xmm0
subsd  -0x60(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  0xd3a(%rip),%xmm3
mulsd  -0x60(%rbp),%xmm3
movsd  -0x60(%rbp),%xmm2
mov    -0x30(%rbp),%rax
addsd  (%rax),%xmm2
divsd  %xmm2,%xmm3
movsd  0xd34(%rip),%xmm2
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1060 <atan@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
subsd  -0x58(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xcf5(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    133a <LatLonAlt+0x1ca>
jmp    1348 <LatLonAlt+0x1d8>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1233 <LatLonAlt+0xc3>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LatLonAlt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movsd  %xmm2,0x20(%rsp)
movapd %xmm1,%xmm2
movapd %xmm0,%xmm3
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ad <LatLonAlt+0x3d>
sqrtsd %xmm0,%xmm0
jmp    11ca <LatLonAlt+0x5a>
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1090 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  %xmm0,0x18(%rsp)
addsd  %xmm0,%xmm3
movapd %xmm2,%xmm0
movapd %xmm3,%xmm1
call   1030 <atan2@plt>
addsd  %xmm0,%xmm0
movsd  %xmm0,(%r15)
movsd  0xe0e(%rip),%xmm1
mulsd  0x18(%rsp),%xmm1
movsd  0x20(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1060 <atan@plt>
movsd  %xmm0,(%rbx)
movq   $0x0,(%r14)
mov    $0xffffff9b,%ebp
jmp    12a4 <LatLonAlt+0x134>
nopl   0x0(%rax)
call   1090 <sqrt@plt>
movsd  0xdeb(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rbx),%xmm0
call   1070 <cos@plt>
movsd  0x18(%rsp),%xmm3
movapd %xmm3,%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
movapd %xmm0,%xmm2
mulsd  0xd9f(%rip),%xmm2
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
addsd  0xd97(%rip),%xmm2
mulsd  %xmm3,%xmm2
movsd  0x20(%rsp),%xmm0
divsd  %xmm2,%xmm0
call   1060 <atan@plt>
movsd  %xmm0,(%rbx)
movsd  (%r14),%xmm0
subsd  0x10(%rsp),%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    12ef <LatLonAlt+0x17f>
inc    %ebp
je     12ef <LatLonAlt+0x17f>
movsd  (%r14),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx),%xmm0
call   1050 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1080 <pow@plt>
mulsd  0xd38(%rip),%xmm0
addsd  0xd38(%rip),%xmm0
ucomisd 0xd40(%rip),%xmm0
jb     1220 <LatLonAlt+0xb0>
sqrtsd %xmm0,%xmm0
jmp    1225 <LatLonAlt+0xb5>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @LatLonAlt(double %0, double %1, double %2, double* nocapture %3, double* nocapture writeonly %4, double* nocapture %5) {
%7 = fmul double %1, %1
%8 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %7)
%9 = tail call double @sqrt(double %8)
%10 = fadd double %9, %0
%11 = tail call double @atan2(double %1, double %10)
%12 = fmul double %11, 2.000000e+00
store double %12, double* %4
%13 = fmul double %9, 0x3FEFC928DE1C02D6
%14 = fdiv double %2, %13
%15 = tail call double @atan(double %14)
store double %15, double* %3
store double 0.000000e+00, double* %5
br label %16
16: ; preds = %19, %6
%17 = phi i32 [ 100, %6 ], [ %42, %19 ]
%18 = icmp eq i32 %17, 0
br i1 %18, label %43, label %19
19: ; preds = %16
%20 = load double, double* %5
%21 = load double, double* %3
%22 = tail call i32 @sin(double %21)
%23 = tail call double @pow(i32 %22, i32 2)
%24 = tail call double @llvm.fmuladd.f64(double %23, double 0xBF7B6B90F1FE94F4, double 1.000000e+00)
%25 = tail call double @sqrt(double %24)
%26 = fdiv double 0x415854A640000000, %25
%27 = load double, double* %3
%28 = tail call double @cos(double %27)
%29 = fdiv double %9, %28
%30 = fsub double %29, %26
store double %30, double* %5
%31 = fmul double %26, 0x3F7B6B90F1FE94F4
%32 = fadd double %26, %30
%33 = fdiv double %31, %32
%34 = fsub double 1.000000e+00, %33
%35 = fmul double %9, %34
%36 = fdiv double %2, %35
%37 = tail call double @atan(double %36)
store double %37, double* %3
%38 = load double, double* %5
%39 = fsub double %38, %20
%40 = tail call i32 @fabs(double %39)
%41 = icmp slt i32 %40, 1
%42 = add nsw i32 %17, -1
br i1 %41, label %43, label %16
43: ; preds = %19, %16
ret void
}