#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 acos(int /*<<< orphan*/);
double cos(double);
int sgn(double, double);
int /*<<< orphan*/ sqrt(int);
void altitude_to_cgm(double r_height_in, double r_lat_alt, double *r_lat_adj) {
  double eradius = 6371.2;
  double eps = 1e-9;
  double unim = 0.9999999;
  double r1;
  double r0, ra;
  r1 = cos(3.14159265358979323846 * (r_lat_alt) / 180);
  ra = r1 * r1;
  if (ra < eps)
    ra = eps;
  r0 = (r_height_in / eradius + 1) / ra;
  if (r0 < unim)
    r0 = unim;
  r1 = acos(sqrt(1 / r0));
  *r_lat_adj = sgn(r1, r_lat_alt) * 180 / 3.14159265358979323846;
}


x86 assembly (clang, -O0):
<altitude_to_cgm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xec2(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xead(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe98(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe83(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe6e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11cd <altitude_to_cgm+0x8d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    120b <altitude_to_cgm+0xcb>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe15(%rip),%xmm0
divsd  -0x40(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1030 <acos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <sgn@plt>
imul   $0xb4,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  0xdba(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<altitude_to_cgm>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
mulsd  0xea1(%rip),%xmm0
divsd  0xea1(%rip),%xmm0
call   1050 <cos@plt>
mulsd  %xmm0,%xmm0
movsd  0xe98(%rip),%xmm1
maxsd  %xmm0,%xmm1
movsd  (%rsp),%xmm2
divsd  0xe8f(%rip),%xmm2
movsd  0xe8f(%rip),%xmm0
addsd  %xmm0,%xmm2
divsd  %xmm1,%xmm2
movsd  0xe87(%rip),%xmm1
maxsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1030 <acos@plt>
movsd  0x8(%rsp),%xmm1
call   1040 <sgn@plt>
imul   $0xb4,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe27(%rip),%xmm0
movsd  %xmm0,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @altitude_to_cgm(double %0, double %1, double* %2) {
%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
store double %0, double* %4
store double %1, double* %5
store double* %2, double** %6
store double 6.371200e+03, double* %7
store double 1.000000e-09, double* %8
store double 0x3FEFFFFFCA501ACB, double* %9
%13 = load double, double* %5
%14 = fmul double 0x400921FB54442D18, %13
%15 = fdiv double %14, 1.800000e+02
%16 = call double @cos(double %15)
store double %16, double* %10
%17 = load double, double* %10
%18 = load double, double* %10
%19 = fmul double %17, %18
store double %19, double* %12
%20 = load double, double* %12
%21 = load double, double* %8
%22 = fcmp olt double %20, %21
br i1 %22, label %23, label %25
23: ; preds = %3
%24 = load double, double* %8
store double %24, double* %12
br label %25
25: ; preds = %23, %3
%26 = load double, double* %4
%27 = load double, double* %7
%28 = fdiv double %26, %27
%29 = fadd double %28, 1.000000e+00
%30 = load double, double* %12
%31 = fdiv double %29, %30
store double %31, double* %11
%32 = load double, double* %11
%33 = load double, double* %9
%34 = fcmp olt double %32, %33
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = load double, double* %9
store double %36, double* %11
br label %37
37: ; preds = %35, %25
%38 = load double, double* %11
%39 = fdiv double 1.000000e+00, %38
%40 = fptosi double %39 to i32
%41 = call i32 @sqrt(i32 %40)
%42 = call double @acos(i32 %41)
store double %42, double* %10
%43 = load double, double* %10
%44 = load double, double* %5
%45 = call i32 @sgn(double %43, double %44)
%46 = mul nsw i32 %45, 180
%47 = sitofp i32 %46 to double
%48 = fdiv double %47, 0x400921FB54442D18
%49 = load double*, double** %6
store double %48, double* %49
ret void
}

LLVM IR (-O2):
define void @altitude_to_cgm(double %0, double %1, double* nocapture writeonly %2) {
%4 = fmul double %1, 0x400921FB54442D18
%5 = fdiv double %4, 1.800000e+02
%6 = tail call double @cos(double %5)
%7 = fmul double %6, %6
%8 = fcmp olt double %7, 1.000000e-09
%9 = select i1 %8, double 1.000000e-09, double %7
%10 = fdiv double %0, 6.371200e+03
%11 = fadd double %10, 1.000000e+00
%12 = fdiv double %11, %9
%13 = fcmp olt double %12, 0x3FEFFFFFCA501ACB
%14 = select i1 %13, double 0x3FEFFFFFCA501ACB, double %12
%15 = fdiv double 1.000000e+00, %14
%16 = fptosi double %15 to i32
%17 = tail call i32 @sqrt(i32 %16)
%18 = tail call double @acos(i32 %17)
%19 = tail call i32 @sgn(double %18, double %1)
%20 = mul nsw i32 %19, 180
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, 0x400921FB54442D18
store double %22, double* %2
ret void
}