#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 FLT_EPSILON;
int asin(double const);
int atan2(double const, double const);
int /*<<< orphan*/ compute_enu(double, double, double *, double *, double *);
double sqrt(double);
void turtle_ecef_to_horizontal(double latitude, double longitude,
                               const double direction[3], double *azimuth,
                               double *elevation) {
  double e[3], n[3], u[3];
  compute_enu(latitude, longitude, e, n, u);
  const double x =
      e[0] * direction[0] + e[1] * direction[1] + e[2] * direction[2];
  const double y =
      n[0] * direction[0] + n[1] * direction[1] + n[2] * direction[2];
  const double z =
      u[0] * direction[0] + u[1] * direction[1] + u[2] * direction[2];
  double r = direction[0] * direction[0] + direction[1] * direction[1] +
             direction[2] * direction[2];
  if (r <= FLT_EPSILON)
    return;
  r = sqrt(r);
  if (azimuth != NULL)
    *azimuth = atan2(x, y) * 180. / 3.14159265358979323846;
  if (elevation != NULL)
    *elevation = asin(z / r) * 180. / 3.14159265358979323846;
}


x86 assembly (clang, -O0):
<turtle_ecef_to_horizontal>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1050 <compute_enu@plt>
movsd  -0x40(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x60(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x58(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x80(%rbp),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x78(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0xa0(%rbp),%xmm1
ff
mov    0x2d46(%rip),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jb     12ad <turtle_ecef_to_horizontal+0x16d>
jmp    134a <turtle_ecef_to_horizontal+0x20a>
movsd  -0xa0(%rbp),%xmm0
ff
call   1060 <sqrt@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
cmpq   $0x0,-0x20(%rbp)
je     1306 <turtle_ecef_to_horizontal+0x1c6>
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x90(%rbp),%xmm1
ff
call   1030 <atan2@plt>
cvtsi2sd %eax,%xmm0
movsd  0xd1a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd06(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     134a <turtle_ecef_to_horizontal+0x20a>
movsd  -0x98(%rbp),%xmm0
ff
divsd  -0xa0(%rbp),%xmm0
ff
call   1040 <asin@plt>
cvtsi2sd %eax,%xmm0
movsd  0xcd6(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xcc2(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<turtle_ecef_to_horizontal>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x90(%rsp),%rdi
lea    0x70(%rsp),%rsi
lea    0x50(%rsp),%rdx
call   1050 <compute_enu@plt>
movsd  (%rbx),%xmm3
movsd  0x8(%rbx),%xmm4
movsd  0x10(%rbx),%xmm2
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm2,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    0x2e3f(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm0,%xmm1
jae    1330 <turtle_ecef_to_horizontal+0x1f0>
movsd  0x98(%rsp),%xmm8
mulsd  %xmm4,%xmm8
movsd  0x90(%rsp),%xmm7
mulsd  %xmm3,%xmm7
movsd  0xa0(%rsp),%xmm10
mulsd  %xmm2,%xmm10
movsd  0x78(%rsp),%xmm9
mulsd  %xmm4,%xmm9
movsd  0x70(%rsp),%xmm5
mulsd  %xmm3,%xmm5
movsd  0x80(%rsp),%xmm1
mulsd  %xmm2,%xmm1
mulsd  0x58(%rsp),%xmm4
mulsd  0x50(%rsp),%xmm3
mulsd  0x60(%rsp),%xmm2
xorpd  %xmm6,%xmm6
ucomisd %xmm6,%xmm0
movsd  %xmm2,0x20(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  %xmm4,0x10(%rsp)
jb     1239 <turtle_ecef_to_horizontal+0xf9>
sqrtsd %xmm0,%xmm0
test   %r15,%r15
jne    12a3 <turtle_ecef_to_horizontal+0x163>
jmp    12fa <turtle_ecef_to_horizontal+0x1ba>
movsd  %xmm10,0x8(%rsp)
movsd  %xmm8,0x48(%rsp)
movsd  %xmm7,0x40(%rsp)
movsd  %xmm9,0x38(%rsp)
movsd  %xmm1,0x30(%rsp)
movsd  %xmm5,0x28(%rsp)
call   1060 <sqrt@plt>
movsd  0x28(%rsp),%xmm5
movsd  0x30(%rsp),%xmm1
movsd  0x38(%rsp),%xmm9
movsd  0x40(%rsp),%xmm7
movsd  0x48(%rsp),%xmm8
movsd  0x8(%rsp),%xmm10
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
test   %r15,%r15
je     12fa <turtle_ecef_to_horizontal+0x1ba>
addsd  %xmm8,%xmm7
addsd  %xmm7,%xmm10
addsd  %xmm9,%xmm5
addsd  %xmm5,%xmm1
movsd  %xmm0,0x8(%rsp)
movapd %xmm10,%xmm0
call   1030 <atan2@plt>
movsd  0x10(%rsp),%xmm4
movsd  0x18(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd19(%rip),%xmm0
divsd  0xd19(%rip),%xmm0
movsd  %xmm0,(%r15)
movsd  0x8(%rsp),%xmm0
test   %r14,%r14
je     1330 <turtle_ecef_to_horizontal+0x1f0>
addsd  %xmm4,%xmm3
addsd  %xmm3,%xmm2
divsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
call   1040 <asin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xcdd(%rip),%xmm0
divsd  0xcdd(%rip),%xmm0
movsd  %xmm0,(%r14)
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FLT_EPSILON = global double 0.000000e+00
define void @turtle_ecef_to_horizontal(double %0, double %1, double* %2, double* %3, double* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca [3 x double]
%12 = alloca [3 x double]
%13 = alloca [3 x double]
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double %0, double* %6
store double %1, double* %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%18 = load double, double* %6
%19 = load double, double* %7
%20 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%21 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%22 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%23 = call i32 @compute_enu(double %18, double %19, double* %20, double* %21, double* %22)
%24 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%25 = load double, double* %24
%26 = load double*, double** %8
%27 = getelementptr inbounds double, double* %26, i64 0
%28 = load double, double* %27
%29 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 1
%30 = load double, double* %29
%31 = load double*, double** %8
%32 = getelementptr inbounds double, double* %31, i64 1
%33 = load double, double* %32
%34 = fmul double %30, %33
%35 = call double @llvm.fmuladd.f64(double %25, double %28, double %34)
%36 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 2
%37 = load double, double* %36
%38 = load double*, double** %8
%39 = getelementptr inbounds double, double* %38, i64 2
%40 = load double, double* %39
%41 = call double @llvm.fmuladd.f64(double %37, double %40, double %35)
store double %41, double* %14
%42 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%43 = load double, double* %42
%44 = load double*, double** %8
%45 = getelementptr inbounds double, double* %44, i64 0
%46 = load double, double* %45
%47 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 1
%48 = load double, double* %47
%49 = load double*, double** %8
%50 = getelementptr inbounds double, double* %49, i64 1
%51 = load double, double* %50
%52 = fmul double %48, %51
%53 = call double @llvm.fmuladd.f64(double %43, double %46, double %52)
%54 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 2
%55 = load double, double* %54
%56 = load double*, double** %8
%57 = getelementptr inbounds double, double* %56, i64 2
%58 = load double, double* %57
%59 = call double @llvm.fmuladd.f64(double %55, double %58, double %53)
store double %59, double* %15
%60 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 0
%61 = load double, double* %60
%62 = load double*, double** %8
%63 = getelementptr inbounds double, double* %62, i64 0
%64 = load double, double* %63
%65 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 1
%66 = load double, double* %65
%67 = load double*, double** %8
%68 = getelementptr inbounds double, double* %67, i64 1
%69 = load double, double* %68
%70 = fmul double %66, %69
%71 = call double @llvm.fmuladd.f64(double %61, double %64, double %70)
%72 = getelementptr inbounds [3 x double], [3 x double]* %13, i64 0, i64 2
%73 = load double, double* %72
%74 = load double*, double** %8
%75 = getelementptr inbounds double, double* %74, i64 2
%76 = load double, double* %75
%77 = call double @llvm.fmuladd.f64(double %73, double %76, double %71)
store double %77, double* %16
%78 = load double*, double** %8
%79 = getelementptr inbounds double, double* %78, i64 0
%80 = load double, double* %79
%81 = load double*, double** %8
%82 = getelementptr inbounds double, double* %81, i64 0
%83 = load double, double* %82
%84 = load double*, double** %8
%85 = getelementptr inbounds double, double* %84, i64 1
%86 = load double, double* %85
%87 = load double*, double** %8
%88 = getelementptr inbounds double, double* %87, i64 1
%89 = load double, double* %88
%90 = fmul double %86, %89
%91 = call double @llvm.fmuladd.f64(double %80, double %83, double %90)
%92 = load double*, double** %8
%93 = getelementptr inbounds double, double* %92, i64 2
%94 = load double, double* %93
%95 = load double*, double** %8
%96 = getelementptr inbounds double, double* %95, i64 2
%97 = load double, double* %96
%98 = call double @llvm.fmuladd.f64(double %94, double %97, double %91)
store double %98, double* %17
%99 = load double, double* %17
%100 = load double, double* @FLT_EPSILON
%101 = fcmp ole double %99, %100
br i1 %101, label %102, label %103
102: ; preds = %5
br label %128
103: ; preds = %5
%104 = load double, double* %17
%105 = call double @sqrt(double %104)
store double %105, double* %17
%106 = load double*, double** %9
%107 = icmp ne double* %106, null
br i1 %107, label %108, label %116
108: ; preds = %103
%109 = load double, double* %14
%110 = load double, double* %15
%111 = call i32 @atan2(double %109, double %110)
%112 = sitofp i32 %111 to double
%113 = fmul double %112, 1.800000e+02
%114 = fdiv double %113, 0x400921FB54442D18
%115 = load double*, double** %9
store double %114, double* %115
br label %116
116: ; preds = %108, %103
%117 = load double*, double** %10
%118 = icmp ne double* %117, null
br i1 %118, label %119, label %128
119: ; preds = %116
%120 = load double, double* %16
%121 = load double, double* %17
%122 = fdiv double %120, %121
%123 = call i32 @asin(double %122)
%124 = sitofp i32 %123 to double
%125 = fmul double %124, 1.800000e+02
%126 = fdiv double %125, 0x400921FB54442D18
%127 = load double*, double** %10
store double %126, double* %127
br label %128
128: ; preds = %102, %119, %116
ret void
}

LLVM IR (-O2):
@FLT_EPSILON = global double 0.000000e+00
define void @turtle_ecef_to_horizontal(double %0, double %1, double* nocapture %2, double* writeonly %3, double* writeonly %4) {
%6 = alloca [3 x double]
%7 = alloca [3 x double]
%8 = alloca [3 x double]
%9 = bitcast [3 x double]* %6 to i8*
%10 = bitcast [3 x double]* %7 to i8*
%11 = bitcast [3 x double]* %8 to i8*
%12 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%13 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%14 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%15 = call i32 @compute_enu(double %0, double %1, double* %12, double* %13, double* %14)
%16 = load double, double* %12
%17 = load double, double* %2
%18 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %2, i64 1
%21 = load double, double* %20
%22 = fmul double %19, %21
%23 = call double @llvm.fmuladd.f64(double %16, double %17, double %22)
%24 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 2
%25 = load double, double* %24
%26 = getelementptr inbounds double, double* %2, i64 2
%27 = load double, double* %26
%28 = call double @llvm.fmuladd.f64(double %25, double %27, double %23)
%29 = load double, double* %13
%30 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 1
%31 = load double, double* %30
%32 = fmul double %21, %31
%33 = call double @llvm.fmuladd.f64(double %29, double %17, double %32)
%34 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
%35 = load double, double* %34
%36 = call double @llvm.fmuladd.f64(double %35, double %27, double %33)
%37 = load double, double* %14
%38 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 1
%39 = load double, double* %38
%40 = fmul double %21, %39
%41 = call double @llvm.fmuladd.f64(double %37, double %17, double %40)
%42 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 2
%43 = load double, double* %42
%44 = call double @llvm.fmuladd.f64(double %43, double %27, double %41)
%45 = fmul double %21, %21
%46 = call double @llvm.fmuladd.f64(double %17, double %17, double %45)
%47 = call double @llvm.fmuladd.f64(double %27, double %27, double %46)
%48 = load double, double* @FLT_EPSILON
%49 = fcmp ugt double %47, %48
br i1 %49, label %50, label %66
50: ; preds = %5
%51 = call double @sqrt(double %47)
%52 = icmp eq double* %3, null
br i1 %52, label %58, label %53
53: ; preds = %50
%54 = call i32 @atan2(double %28, double %36)
%55 = sitofp i32 %54 to double
%56 = fmul double %55, 1.800000e+02
%57 = fdiv double %56, 0x400921FB54442D18
store double %57, double* %3
br label %58
58: ; preds = %53, %50
%59 = icmp eq double* %4, null
br i1 %59, label %66, label %60
60: ; preds = %58
%61 = fdiv double %44, %51
%62 = call i32 @asin(double %61)
%63 = sitofp i32 %62 to double
%64 = fmul double %63, 1.800000e+02
%65 = fdiv double %64, 0x400921FB54442D18
store double %65, double* %4
br label %66
66: ; preds = %58, %60, %5
ret void
}