#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 M_PI;
double const M_PI_2;
double absAngle(int /*<<< orphan*/);
int /*<<< orphan*/ atan2(int, int);
int cos(double const);
int sin(double const);
double calcGreatCircleCourse(const double lat1, const double lon1,
                             const double lat2, const double lon2) {
  if (lat2 == M_PI_2)
    return (2 * M_PI);
  if (lat2 == -M_PI_2)
    return M_PI;
  if (lon1 == lon2) {
    if (lat1 > lat2)
      return M_PI;
    else
      return (2 * M_PI);
  }
  return absAngle(
      atan2(sin(lon1 - lon2) * cos(lat2),
            cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2)));
}


x86 assembly (clang, -O0):
<calcGreatCircleCourse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    0x2e78(%rip),%rax
ucomisd (%rax),%xmm0
jne    1192 <calcGreatCircleCourse+0x52>
jp     1192 <calcGreatCircleCourse+0x52>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ce <calcGreatCircleCourse+0x18e>
movsd  -0x20(%rbp),%xmm0
mov    0x2e42(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    11de <calcGreatCircleCourse+0x9e>
jp     11de <calcGreatCircleCourse+0x9e>
mov    0x2e18(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ce <calcGreatCircleCourse+0x18e>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    1233 <calcGreatCircleCourse+0xf3>
jp     1233 <calcGreatCircleCourse+0xf3>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1219 <calcGreatCircleCourse+0xd9>
mov    0x2ddd(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ce <calcGreatCircleCourse+0x18e>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ce <calcGreatCircleCourse+0x18e>
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <cos@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1060 <cos@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1060 <cos@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edi
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
sub    %eax,%esi
call   1030 <atan2@plt>
mov    %eax,%edi
call   1040 <absAngle@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcGreatCircleCourse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movapd %xmm0,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jne    1177 <calcGreatCircleCourse+0x37>
jp     1177 <calcGreatCircleCourse+0x37>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
ucomisd %xmm3,%xmm1
jne    1190 <calcGreatCircleCourse+0x50>
jp     1190 <calcGreatCircleCourse+0x50>
ucomisd %xmm2,%xmm4
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
jbe    1163 <calcGreatCircleCourse+0x23>
jmp    1165 <calcGreatCircleCourse+0x25>
subsd  %xmm3,%xmm1
movsd  %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm2,(%rsp)
movsd  %xmm4,0x8(%rsp)
call   1050 <sin@plt>
mov    %eax,%r14d
movsd  (%rsp),%xmm0
call   1060 <cos@plt>
imul   %eax,%r14d
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
mov    %eax,%ebp
movsd  (%rsp),%xmm0
call   1050 <sin@plt>
imul   %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mov    %eax,%r15d
movsd  (%rsp),%xmm0
call   1060 <cos@plt>
mov    %eax,%ebx
imul   %r15d,%ebx
movsd  0x10(%rsp),%xmm0
call   1060 <cos@plt>
imul   %ebx,%eax
sub    %eax,%ebp
mov    %r14d,%edi
mov    %ebp,%esi
call   1030 <atan2@plt>
mov    %eax,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <absAngle@plt>

LLVM IR (-O0):
@M_PI_2 = constant double 0.000000e+00
@M_PI = global i32 0
define double @calcGreatCircleCourse(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%10 = load double, double* %8
%11 = load double, double* @M_PI_2
%12 = fcmp oeq double %10, %11
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = load i32, i32* @M_PI
%15 = mul nsw i32 2, %14
%16 = sitofp i32 %15 to double
store double %16, double* %5
br label %66
17: ; preds = %4
%18 = load double, double* %8
%19 = load double, double* @M_PI_2
%20 = fneg double %19
%21 = fcmp oeq double %18, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* @M_PI
%24 = sitofp i32 %23 to double
store double %24, double* %5
br label %66
25: ; preds = %17
%26 = load double, double* %7
%27 = load double, double* %9
%28 = fcmp oeq double %26, %27
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = load double, double* %6
%31 = load double, double* %8
%32 = fcmp ogt double %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @M_PI
%35 = sitofp i32 %34 to double
store double %35, double* %5
br label %66
36: ; preds = %29
%37 = load i32, i32* @M_PI
%38 = mul nsw i32 2, %37
%39 = sitofp i32 %38 to double
store double %39, double* %5
br label %66
40: ; preds = %25
%41 = load double, double* %7
%42 = load double, double* %9
%43 = fsub double %41, %42
%44 = call i32 @sin(double %43)
%45 = load double, double* %8
%46 = call i32 @cos(double %45)
%47 = mul nsw i32 %44, %46
%48 = load double, double* %6
%49 = call i32 @cos(double %48)
%50 = load double, double* %8
%51 = call i32 @sin(double %50)
%52 = mul nsw i32 %49, %51
%53 = load double, double* %6
%54 = call i32 @sin(double %53)
%55 = load double, double* %8
%56 = call i32 @cos(double %55)
%57 = mul nsw i32 %54, %56
%58 = load double, double* %7
%59 = load double, double* %9
%60 = fsub double %58, %59
%61 = call i32 @cos(double %60)
%62 = mul nsw i32 %57, %61
%63 = sub nsw i32 %52, %62
%64 = call i32 @atan2(i32 %47, i32 %63)
%65 = call double @absAngle(i32 %64)
store double %65, double* %5
br label %66
66: ; preds = %40, %36, %33, %22, %13
%67 = load double, double* %5
ret double %67
}

LLVM IR (-O2):
@M_PI_2 = constant double 0.000000e+00
@M_PI = global i32 0
define double @calcGreatCircleCourse(double %0, double %1, double %2, double %3) {
%5 = fcmp oeq double %2, 0.000000e+00
br i1 %5, label %6, label %10
6: ; preds = %4
%7 = load i32, i32* @M_PI
%8 = shl nsw i32 %7, 1
%9 = sitofp i32 %8 to double
br label %36
10: ; preds = %4
%11 = fcmp oeq double %1, %3
br i1 %11, label %12, label %20
12: ; preds = %10
%13 = fcmp ogt double %0, %2
%14 = load i32, i32* @M_PI
br i1 %13, label %15, label %17
15: ; preds = %12
%16 = sitofp i32 %14 to double
br label %36
17: ; preds = %12
%18 = shl nsw i32 %14, 1
%19 = sitofp i32 %18 to double
br label %36
20: ; preds = %10
%21 = fsub double %1, %3
%22 = tail call i32 @sin(double %21)
%23 = tail call i32 @cos(double %2)
%24 = mul nsw i32 %23, %22
%25 = tail call i32 @cos(double %0)
%26 = tail call i32 @sin(double %2)
%27 = mul nsw i32 %26, %25
%28 = tail call i32 @sin(double %0)
%29 = tail call i32 @cos(double %2)
%30 = mul nsw i32 %29, %28
%31 = tail call i32 @cos(double %21)
%32 = mul nsw i32 %30, %31
%33 = sub nsw i32 %27, %32
%34 = tail call i32 @atan2(i32 %24, i32 %33)
%35 = tail call double @absAngle(i32 %34)
br label %36
36: ; preds = %20, %17, %15, %6
%37 = phi double [ %9, %6 ], [ %16, %15 ], [ %19, %17 ], [ %35, %20 ]
ret double %37
}