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


x86 assembly (clang, -O0):
<cgm_to_altitude>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xeba(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe95(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
movsd  0xe91(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe7c(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11e4 <cgm_to_altitude+0xa4>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1030 <acos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <sgn@plt>
imul   $0xb4,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  0xdf5(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgm_to_altitude>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
mulsd  0xe9f(%rip),%xmm0
divsd  0xe9f(%rip),%xmm0
call   1050 <cos@plt>
movsd  0x8(%rsp),%xmm2
divsd  0xe94(%rip),%xmm2
movsd  0xe94(%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  0x10(%rsp),%xmm1
call   1040 <sgn@plt>
imul   $0xb4,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe32(%rip),%xmm0
movsd  %xmm0,(%rbx)
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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