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


x86 assembly (clang, -O0):
<AACGM_v2_Alt2CGM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    0x2e6c(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe78(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c3 <AACGM_v2_Alt2CGM+0x83>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe3c(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1208 <AACGM_v2_Alt2CGM+0xc8>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe08(%rip),%xmm0
divsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1030 <acos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1050 <AACGM_v2_Sgn@plt>
imul   $0xb4,%eax,%eax
cvtsi2sd %eax,%xmm0
mov    0x2d9e(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AACGM_v2_Alt2CGM>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    0x2e8b(%rip),%r14
movsd  (%r14),%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe92(%rip),%xmm0
call   1040 <cos@plt>
mulsd  %xmm0,%xmm0
movsd  0xe89(%rip),%xmm1
maxsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
divsd  0xe7f(%rip),%xmm2
movsd  0xe7f(%rip),%xmm0
addsd  %xmm0,%xmm2
divsd  %xmm1,%xmm2
movsd  0xe77(%rip),%xmm1
maxsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1030 <acos@plt>
movsd  0x10(%rsp),%xmm1
call   1050 <AACGM_v2_Sgn@plt>
imul   $0xb4,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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