#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 convert_geo_coord(double, double, double, double *, double *, int, int);
int fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, ...);
int /*<<< orphan*/ stderr;
int AACGM_v2_Convert(double in_lat, double in_lon, double height,
                     double *out_lat, double *out_lon, double *r, int flag) {
  int err;
  int order = 10;
  if (height < 0) {
    fprintf(stderr,
            "ERROR: coordinate transformations are not defined "
            "for altitudes < 0 km: %lf\n",
            height);
    return -2;
  }
  if (height > 2000) {
    fprintf(stderr,
            "ERROR: coefficients are not valid for altitudes "
            "above %d km: %lf\n",
            2000, height);
    return -4;
  }
  if (fabs(in_lat) > 90.) {
    fprintf(stderr,
            "ERROR: latitude must be in the range -90 to +90 degrees: "
            "%lf\n",
            in_lat);
    return -8;
  }
  if (in_lon < 0)
    in_lon += 360.0;
  if ((in_lon < 0) || (in_lon > 360)) {
    fprintf(stderr,
            "ERROR: longitude must be in the range 0 to 360 degrees: "
            "%lf\n",
            in_lon);
    return -16;
  }
  err =
      convert_geo_coord(in_lat, in_lon, height, out_lat, out_lon, flag, order);
  *r = 1.0;
  if (err != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<AACGM_v2_Convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %ecx,-0x3c(%rbp)
movl   $0xa,-0x44(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1193 <AACGM_v2_Convert+0x63>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
movsd  -0x20(%rbp),%xmm0
lea    0xea0(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12e1 <AACGM_v2_Convert+0x1b1>
movsd  -0x20(%rbp),%xmm0
movsd  0xe60(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11da <AACGM_v2_Convert+0xaa>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
movsd  -0x20(%rbp),%xmm1
lea    0xeae(%rip),%rsi
movsd  0xe39(%rip),%xmm0
mov    $0x2,%al
call   1050 <fprintf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    12e1 <AACGM_v2_Convert+0x1b1>
movsd  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe18(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1222 <AACGM_v2_Convert+0xf2>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
movsd  -0x10(%rbp),%xmm0
lea    0xea0(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movl   $0xfffffff8,-0x4(%rbp)
jmp    12e1 <AACGM_v2_Convert+0x1b1>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1242 <AACGM_v2_Convert+0x112>
movsd  0xdd8(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     1267 <AACGM_v2_Convert+0x137>
movsd  -0x18(%rbp),%xmm0
movsd  0xdb3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    128f <AACGM_v2_Convert+0x15f>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
movsd  -0x18(%rbp),%xmm0
lea    0xe71(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
movl   $0xfffffff0,-0x4(%rbp)
jmp    12e1 <AACGM_v2_Convert+0x1b1>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    -0x44(%rbp),%ecx
call   1030 <convert_geo_coord@plt>
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
movsd  0xd58(%rip),%xmm0
movsd  %xmm0,(%rax)
cmpl   $0x0,-0x40(%rbp)
je     12da <AACGM_v2_Convert+0x1aa>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e1 <AACGM_v2_Convert+0x1b1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AACGM_v2_Convert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm2,%xmm3
jbe    1169 <AACGM_v2_Convert+0x39>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0xebc(%rip),%rsi
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    $0xfffffffe,%eax
jmp    1279 <AACGM_v2_Convert+0x149>
ucomisd 0xe8f(%rip),%xmm2
jbe    11a0 <AACGM_v2_Convert+0x70>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xeda(%rip),%rsi
movsd  0xe75(%rip),%xmm0
movapd %xmm2,%xmm1
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    $0xfffffffc,%eax
jmp    1279 <AACGM_v2_Convert+0x149>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
movapd %xmm1,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,(%rsp)
call   1040 <fabs@plt>
cmp    $0x5b,%eax
jl     11ed <AACGM_v2_Convert+0xbd>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xec8(%rip),%rsi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    $0xfffffff8,%eax
jmp    1279 <AACGM_v2_Convert+0x149>
movsd  (%rsp),%xmm0
movsd  0xe0e(%rip),%xmm3
movapd 0x10(%rsp),%xmm4
addsd  %xmm4,%xmm3
xorpd  %xmm2,%xmm2
movapd %xmm4,%xmm1
cmpltsd %xmm2,%xmm1
andpd  %xmm1,%xmm3
andnpd %xmm4,%xmm1
orpd   %xmm3,%xmm1
ucomisd %xmm1,%xmm2
ja     1259 <AACGM_v2_Convert+0x129>
ucomisd 0xddd(%rip),%xmm1
ja     1259 <AACGM_v2_Convert+0x129>
movsd  0x8(%rsp),%xmm2
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    $0xa,%ecx
call   1030 <convert_geo_coord@plt>
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%r14)
neg    %eax
sbb    %eax,%eax
jmp    1279 <AACGM_v2_Convert+0x149>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    $0xfffffff0,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [77 x i8] c"ERROR: coordinate transformations are not defined for altitudes < 0 km: %lf\0A\00"
@.str.1 = [66 x i8] c"ERROR: coefficients are not valid for altitudes above %d km: %lf\0A\00"
@.str.2 = [62 x i8] c"ERROR: latitude must be in the range -90 to +90 degrees: %lf\0A\00"
@.str.3 = [61 x i8] c"ERROR: longitude must be in the range 0 to 360 degrees: %lf\0A\00"
define i32 @AACGM_v2_Convert(double %0, double %1, double %2, double* %3, double* %4, double* %5, i32 %6) {
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store double %0, double* %9
store double %1, double* %10
store double %2, double* %11
store double* %3, double** %12
store double* %4, double** %13
store double* %5, double** %14
store i32 %6, i32* %15
store i32 10, i32* %17
%18 = load double, double* %11
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %24
20: ; preds = %7
%21 = load i32, i32* @stderr
%22 = load double, double* %11
%23 = call i32 (i32, i8*, double, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), double %22)
store i32 -2, i32* %8
br label %70
24: ; preds = %7
%25 = load double, double* %11
%26 = fcmp ogt double %25, 2.000000e+03
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = load double, double* %11
%30 = call i32 (i32, i8*, double, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), double 2.000000e+03, double %29)
store i32 -4, i32* %8
br label %70
31: ; preds = %24
%32 = load double, double* %9
%33 = call i32 @fabs(double %32)
%34 = sitofp i32 %33 to double
%35 = fcmp ogt double %34, 9.000000e+01
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = load double, double* %9
%39 = call i32 (i32, i8*, double, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), double %38)
store i32 -8, i32* %8
br label %70
40: ; preds = %31
%41 = load double, double* %10
%42 = fcmp olt double %41, 0.000000e+00
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load double, double* %10
%45 = fadd double %44, 3.600000e+02
store double %45, double* %10
br label %46
46: ; preds = %43, %40
%47 = load double, double* %10
%48 = fcmp olt double %47, 0.000000e+00
br i1 %48, label %52, label %49
49: ; preds = %46
%50 = load double, double* %10
%51 = fcmp ogt double %50, 3.600000e+02
br i1 %51, label %52, label %56
52: ; preds = %49, %46
%53 = load i32, i32* @stderr
%54 = load double, double* %10
%55 = call i32 (i32, i8*, double, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), double %54)
store i32 -16, i32* %8
br label %70
56: ; preds = %49
%57 = load double, double* %9
%58 = load double, double* %10
%59 = load double, double* %11
%60 = load double*, double** %12
%61 = load double*, double** %13
%62 = load i32, i32* %15
%63 = load i32, i32* %17
%64 = call i32 @convert_geo_coord(double %57, double %58, double %59, double* %60, double* %61, i32 %62, i32 %63)
store i32 %64, i32* %16
%65 = load double*, double** %14
store double 1.000000e+00, double* %65
%66 = load i32, i32* %16
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %56
store i32 -1, i32* %8
br label %70
69: ; preds = %56
store i32 0, i32* %8
br label %70
70: ; preds = %69, %68, %52, %36, %27, %20
%71 = load i32, i32* %8
ret i32 %71
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [77 x i8] c"ERROR: coordinate transformations are not defined for altitudes < 0 km: %lf\0A\00"
@.str.1 = [66 x i8] c"ERROR: coefficients are not valid for altitudes above %d km: %lf\0A\00"
@.str.2 = [62 x i8] c"ERROR: latitude must be in the range -90 to +90 degrees: %lf\0A\00"
@.str.3 = [61 x i8] c"ERROR: longitude must be in the range 0 to 360 degrees: %lf\0A\00"
define i32 @AACGM_v2_Convert(double %0, double %1, double %2, double* %3, double* %4, double* nocapture writeonly %5, i32 %6) {
%8 = fcmp olt double %2, 0.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0), double %2)
br label %37
12: ; preds = %7
%13 = fcmp ogt double %2, 2.000000e+03
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0), double 2.000000e+03, double %2)
br label %37
17: ; preds = %12
%18 = tail call i32 @fabs(double %0)
%19 = icmp sgt i32 %18, 90
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), double %0)
br label %37
23: ; preds = %17
%24 = fcmp olt double %1, 0.000000e+00
%25 = fadd double %1, 3.600000e+02
%26 = select i1 %24, double %25, double %1
%27 = fcmp olt double %26, 0.000000e+00
%28 = fcmp ogt double %26, 3.600000e+02
%29 = or i1 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), double %26)
br label %37
33: ; preds = %23
%34 = tail call i32 @convert_geo_coord(double %0, double %26, double %2, double* %3, double* %4, i32 %6, i32 10)
store double 1.000000e+00, double* %5
%35 = icmp ne i32 %34, 0
%36 = sext i1 %35 to i32
br label %37
37: ; preds = %33, %30, %20, %14, %9
%38 = phi i32 [ -2, %9 ], [ -4, %14 ], [ -8, %20 ], [ -16, %30 ], [ %36, %33 ]
ret i32 %38
}