#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 */
int M_PI;
double asin(double);
double atan2(double, double);
double vector_norm(int, double *);
int /*<<< orphan*/ wgsecef2ned_d(double const *, double const *, double *);
void wgsecef2azel(const double ecef[3], const double ref_ecef[3],
                  double *azimuth, double *elevation) {
  double ned[3];
  wgsecef2ned_d(ecef, ref_ecef, ned);
  *azimuth = atan2(ned[1], ned[0]);
  if (*azimuth < 0)
    *azimuth += 2 * M_PI;
  *elevation = asin(-ned[2] / vector_norm(3, ned));
}


x86 assembly (clang, -O0):
<wgsecef2azel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <wgsecef2ned_d@plt>
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1030 <atan2@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jbe    11ad <wgsecef2azel+0x6d>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0x18(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
lea    -0x40(%rbp),%rsi
mov    $0x3,%edi
call   1040 <vector_norm@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1050 <asin@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wgsecef2azel>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsp,%rdx
call   1060 <wgsecef2ned_d@plt>
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
call   1030 <atan2@plt>
movsd  %xmm0,(%rbx)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    118d <wgsecef2azel+0x4d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
movsd  0x10(%rsp),%xmm0
xorpd  0xe65(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
mov    %rsp,%rsi
mov    $0x3,%edi
call   1040 <vector_norm@plt>
movapd 0x20(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1050 <asin@plt>
movsd  %xmm0,(%r14)
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @wgsecef2azel(double* %0, double* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca [3 x double]
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store double* %3, double** %8
%10 = load double*, double** %5
%11 = load double*, double** %6
%12 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%13 = call i32 @wgsecef2ned_d(double* %10, double* %11, double* %12)
%14 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%15 = load double, double* %14
%16 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%17 = load double, double* %16
%18 = call double @atan2(double %15, double %17)
%19 = load double*, double** %7
store double %18, double* %19
%20 = load double*, double** %7
%21 = load double, double* %20
%22 = fcmp olt double %21, 0.000000e+00
br i1 %22, label %23, label %30
23: ; preds = %4
%24 = load i32, i32* @M_PI
%25 = mul nsw i32 2, %24
%26 = sitofp i32 %25 to double
%27 = load double*, double** %7
%28 = load double, double* %27
%29 = fadd double %28, %26
store double %29, double* %27
br label %30
30: ; preds = %23, %4
%31 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%32 = load double, double* %31
%33 = fneg double %32
%34 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%35 = call double @vector_norm(i32 3, double* %34)
%36 = fdiv double %33, %35
%37 = call double @asin(double %36)
%38 = load double*, double** %8
store double %37, double* %38
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @wgsecef2azel(double* %0, double* %1, double* nocapture writeonly %2, double* nocapture writeonly %3) {
%5 = alloca [3 x double]
%6 = bitcast [3 x double]* %5 to i8*
%7 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%8 = call i32 @wgsecef2ned_d(double* %0, double* %1, double* %7)
%9 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 1
%10 = load double, double* %9
%11 = load double, double* %7
%12 = call double @atan2(double %10, double %11)
store double %12, double* %2
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = load i32, i32* @M_PI
%16 = shl nsw i32 %15, 1
%17 = sitofp i32 %16 to double
%18 = fadd double %12, %17
store double %18, double* %2
br label %19
19: ; preds = %14, %4
%20 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
%21 = load double, double* %20
%22 = fneg double %21
%23 = call double @vector_norm(i32 3, double* %7)
%24 = fdiv double %22, %23
%25 = call double @asin(double %24)
store double %25, double* %3
ret void
}