#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 */
scalar_t__ M_PI;
double const M_PI_2;
scalar_t__ M_PI_4;
double acos(int);
double asin(int);
double calcGreatCircleRoute(double const, double const, double const,
                            double const, double *);
int cos(double);
scalar_t__ isAngleBetween(scalar_t__, double, scalar_t__);
int sin(double);
double calcGCCrossTrackError(const double lat1, const double lon1,
                             const double lon2, const double latX,
                             const double lonX, const double course12,
                             double *atd) {
  double dist1X, xtd;
  double course1X = calcGreatCircleRoute(lat1, lon1, latX, lonX, &dist1X);
  if (lat1 != M_PI_2 && lat1 != -M_PI_2)
    xtd = asin(sin(dist1X) * sin(course1X - course12));
  else {
    double diff;
    if (lat1 == M_PI_2)
      diff = lonX - lon2;
    else
      diff = lon2 - lonX;
    xtd = asin(sin(dist1X) * sin(diff));
  }
  if (isAngleBetween(course12 + M_PI_4, course1X, course12 + M_PI))
    *atd = -acos(cos(dist1X) / cos(xtd));
  else
    *atd = acos(cos(dist1X) / cos(xtd));
  return xtd;
}


x86 assembly (clang, -O0):
<calcGCCrossTrackError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
mov    %rdi,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm3
lea    -0x40(%rbp),%rdi
call   1040 <calcGreatCircleRoute@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e20(%rip),%rax
ucomisd (%rax),%xmm0
jne    11cd <calcGCCrossTrackError+0x6d>
jp     11cd <calcGCCrossTrackError+0x6d>
jmp    123a <calcGCCrossTrackError+0xda>
movsd  -0x8(%rbp),%xmm0
mov    0x2dff(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    1209 <calcGCCrossTrackError+0xa9>
jp     1209 <calcGCCrossTrackError+0xa9>
jmp    123a <calcGCCrossTrackError+0xda>
movsd  -0x40(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,-0x5c(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
call   1050 <sin@plt>
mov    -0x5c(%rbp),%edi
imul   %eax,%edi
call   1060 <asin@plt>
movsd  %xmm0,-0x48(%rbp)
jmp    12a0 <calcGCCrossTrackError+0x140>
movsd  -0x8(%rbp),%xmm0
mov    0x2d92(%rip),%rax
ucomisd (%rax),%xmm0
jne    126a <calcGCCrossTrackError+0x10a>
jp     126a <calcGCCrossTrackError+0x10a>
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1279 <calcGCCrossTrackError+0x119>
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <sin@plt>
mov    %eax,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1050 <sin@plt>
mov    -0x60(%rbp),%edi
imul   %eax,%edi
call   1060 <asin@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    0x2d34(%rip),%rax
cvtsi2sdq (%rax),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
movsd  -0x50(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    0x2d1d(%rip),%rax
cvtsi2sdq (%rax),%xmm2
addsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rsi
call   1070 <isAngleBetween@plt>
cmp    $0x0,%rax
je     1332 <calcGCCrossTrackError+0x1d2>
movsd  -0x40(%rbp),%xmm0
call   1080 <cos@plt>
mov    %eax,-0x64(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1080 <cos@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <acos@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1360 <calcGCCrossTrackError+0x200>
movsd  -0x40(%rbp),%xmm0
call   1080 <cos@plt>
mov    %eax,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1080 <cos@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <acos@plt>
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcGCCrossTrackError>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
movsd  %xmm5,0x18(%rsp)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm0,0x28(%rsp)
lea    0x8(%rsp),%rdi
movaps %xmm3,%xmm2
movsd  %xmm4,(%rsp)
movaps %xmm4,%xmm3
call   1040 <calcGreatCircleRoute@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  0x28(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    11aa <calcGCCrossTrackError+0x4a>
jnp    11c5 <calcGCCrossTrackError+0x65>
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mov    %eax,%ebp
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
jmp    11e7 <calcGCCrossTrackError+0x87>
movsd  (%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
movsd  (%rsp),%xmm0
mov    %eax,%ebp
call   1050 <sin@plt>
imul   %eax,%ebp
mov    %ebp,%edi
call   1060 <asin@plt>
mov    0x2de3(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdq (%rax),%xmm1
movsd  0x18(%rsp),%xmm2
addsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rdi
mov    0x2dcd(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdq (%rax),%xmm1
movsd  %xmm0,(%rsp)
addsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rsi
movsd  0x10(%rsp),%xmm0
call   1070 <isAngleBetween@plt>
mov    %rax,%rbp
movsd  0x8(%rsp),%xmm0
call   1080 <cos@plt>
mov    %eax,%ebx
movsd  (%rsp),%xmm0
call   1080 <cos@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <acos@plt>
test   %rbp,%rbp
je     1270 <calcGCCrossTrackError+0x110>
xorps  0xd90(%rip),%xmm0
movsd  (%rsp),%xmm1
movsd  %xmm0,(%r14)
movaps %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@M_PI_2 = constant double 0.000000e+00
@M_PI_4 = global i64 0
@M_PI = global i64 0
define double @calcGCCrossTrackError(double %0, double %1, double %2, double %3, double %4, double %5, double* %6) {
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double*
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double %5, double* %13
store double* %6, double** %14
%19 = load double, double* %8
%20 = load double, double* %9
%21 = load double, double* %11
%22 = load double, double* %12
%23 = call double @calcGreatCircleRoute(double %19, double %20, double %21, double %22, double* %15)
store double %23, double* %17
%24 = load double, double* %8
%25 = load double, double* @M_PI_2
%26 = fcmp une double %24, %25
br i1 %26, label %27, label %41
27: ; preds = %7
%28 = load double, double* %8
%29 = load double, double* @M_PI_2
%30 = fneg double %29
%31 = fcmp une double %28, %30
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load double, double* %15
%34 = call i32 @sin(double %33)
%35 = load double, double* %17
%36 = load double, double* %13
%37 = fsub double %35, %36
%38 = call i32 @sin(double %37)
%39 = mul nsw i32 %34, %38
%40 = call double @asin(i32 %39)
store double %40, double* %16
br label %60
41: ; preds = %27, %7
%42 = load double, double* %8
%43 = load double, double* @M_PI_2
%44 = fcmp oeq double %42, %43
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load double, double* %12
%47 = load double, double* %10
%48 = fsub double %46, %47
store double %48, double* %18
br label %53
49: ; preds = %41
%50 = load double, double* %10
%51 = load double, double* %12
%52 = fsub double %50, %51
store double %52, double* %18
br label %53
53: ; preds = %49, %45
%54 = load double, double* %15
%55 = call i32 @sin(double %54)
%56 = load double, double* %18
%57 = call i32 @sin(double %56)
%58 = mul nsw i32 %55, %57
%59 = call double @asin(i32 %58)
store double %59, double* %16
br label %60
60: ; preds = %53, %32
%61 = load double, double* %13
%62 = load i64, i64* @M_PI_4
%63 = sitofp i64 %62 to double
%64 = fadd double %61, %63
%65 = fptosi double %64 to i64
%66 = load double, double* %17
%67 = load double, double* %13
%68 = load i64, i64* @M_PI
%69 = sitofp i64 %68 to double
%70 = fadd double %67, %69
%71 = fptosi double %70 to i64
%72 = call i64 @isAngleBetween(i64 %65, double %66, i64 %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %83
74: ; preds = %60
%75 = load double, double* %15
%76 = call i32 @cos(double %75)
%77 = load double, double* %16
%78 = call i32 @cos(double %77)
%79 = sdiv i32 %76, %78
%80 = call double @acos(i32 %79)
%81 = fneg double %80
%82 = load double*, double** %14
store double %81, double* %82
br label %91
83: ; preds = %60
%84 = load double, double* %15
%85 = call i32 @cos(double %84)
%86 = load double, double* %16
%87 = call i32 @cos(double %86)
%88 = sdiv i32 %85, %87
%89 = call double @acos(i32 %88)
%90 = load double*, double** %14
store double %89, double* %90
br label %91
91: ; preds = %83, %74
%92 = load double, double* %16
ret double %92
}

LLVM IR (-O2):
@M_PI_2 = constant double 0.000000e+00
@M_PI_4 = global i64 0
@M_PI = global i64 0
define double @calcGCCrossTrackError(double %0, double %1, double %2, double %3, double %4, double %5, double* nocapture writeonly %6) {
%8 = alloca double
%9 = bitcast double* %8 to i8*
%10 = call double @calcGreatCircleRoute(double %0, double %1, double %3, double %4, double* %8)
%11 = fcmp une double %0, 0.000000e+00
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load double, double* %8
%14 = call i32 @sin(double %13)
%15 = fsub double %10, %5
br label %20
16: ; preds = %7
%17 = fsub double %4, %2
%18 = load double, double* %8
%19 = call i32 @sin(double %18)
br label %20
20: ; preds = %16, %12
%21 = phi double [ %17, %16 ], [ %15, %12 ]
%22 = phi i32 [ %19, %16 ], [ %14, %12 ]
%23 = call i32 @sin(double %21)
%24 = mul nsw i32 %23, %22
%25 = call double @asin(i32 %24)
%26 = load i64, i64* @M_PI_4
%27 = sitofp i64 %26 to double
%28 = fadd double %27, %5
%29 = fptosi double %28 to i64
%30 = load i64, i64* @M_PI
%31 = sitofp i64 %30 to double
%32 = fadd double %31, %5
%33 = fptosi double %32 to i64
%34 = call i64 @isAngleBetween(i64 %29, double %10, i64 %33)
%35 = icmp eq i64 %34, 0
%36 = load double, double* %8
%37 = call i32 @cos(double %36)
%38 = call i32 @cos(double %25)
%39 = sdiv i32 %37, %38
%40 = call double @acos(i32 %39)
%41 = fneg double %40
%42 = select i1 %35, double %40, double %41
store double %42, double* %6
ret double %25
}