#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(double);
int AACGM_v2_CGM2Alt(double r_height_in, double r_lat_in, double *r_lat_adj) {
  double unim = 1;
  double r1;
  double ra;
  int error = 0;
  r1 = cos(r_lat_in * M_PI / 180.);
  ra = (r_height_in / 6371.2 + 1) * (r1 * r1);
  if (ra > unim) {
    ra = unim;
    error = 1;
  }
  r1 = acos(sqrt(ra));
  *r_lat_adj = AACGM_v2_Sgn(r1, r_lat_in) * 180 / M_PI;
  return (error);
}


x86 assembly (clang, -O0):
<AACGM_v2_CGM2Alt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xea2(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    0x2e72(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe8e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe6b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe57(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11e1 <AACGM_v2_CGM2Alt+0xa1>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1030 <acos@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1050 <AACGM_v2_Sgn@plt>
imul   $0xb4,%eax,%eax
cvtsi2sd %eax,%xmm0
mov    0x2dd1(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AACGM_v2_CGM2Alt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
mov    0x2e8b(%rip),%r14
movsd  (%r14),%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe92(%rip),%xmm0
call   1040 <cos@plt>
movsd  (%rsp),%xmm2
divsd  0xe88(%rip),%xmm2
movsd  0xe88(%rip),%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm0
mulsd  %xmm2,%xmm0
xor    %ebp,%ebp
ucomisd %xmm1,%xmm0
seta   %bpl
minsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1030 <acos@plt>
movsd  0x8(%rsp),%xmm1
call   1050 <AACGM_v2_Sgn@plt>
imul   $0xb4,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,(%rbx)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define i32 @AACGM_v2_CGM2Alt(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 = fdiv double %0, 6.371200e+03
%9 = fadd double %8, 1.000000e+00
%10 = fmul double %7, %7
%11 = fmul double %9, %10
%12 = fcmp ogt double %11, 1.000000e+00
%13 = select i1 %12, double 1.000000e+00, double %11
%14 = zext i1 %12 to i32
%15 = tail call i32 @sqrt(double %13)
%16 = tail call double @acos(i32 %15)
%17 = tail call i32 @AACGM_v2_Sgn(double %16, double %1)
%18 = mul nsw i32 %17, 180
%19 = sitofp i32 %18 to double
%20 = load double, double* @M_PI
%21 = fdiv double %19, %20
store double %21, double* %2
ret i32 %14
}