#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 atan2(double, double);
double cos(double);
int fabs(double);
double sin(double);
double heading(double lat1, double lon1, double lat2, double lon2) {
  double v1, v2;
  v1 = sin(lon1 - lon2) * cos(lat2);
  v2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2);
  if (fabs(v1) < 1e-15)
    v1 = 0.0;
  if (fabs(v2) < 1e-15)
    v2 = 0.0;
  return atan2(v1, v2);
}


x86 assembly (clang, -O0):
<heading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1060 <cos@plt>
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xdce(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1244 <heading+0x104>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xda6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    126c <heading+0x12c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1030 <atan2@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heading>:
sub    $0x38,%rsp
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
subsd  %xmm3,%xmm1
movsd  %xmm1,0x30(%rsp)
movapd %xmm1,%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x30(%rsp),%xmm0
call   1060 <cos@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  0x28(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
call   1040 <fabs@plt>
xorps  %xmm0,%xmm0
test   %eax,%eax
jle    120d <heading+0xcd>
movsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
xorpd  %xmm1,%xmm1
jle    122c <heading+0xec>
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
jmp    1030 <atan2@plt>

LLVM IR (-O0):
define double @heading(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%11 = load double, double* %6
%12 = load double, double* %8
%13 = fsub double %11, %12
%14 = call double @sin(double %13)
%15 = load double, double* %7
%16 = call double @cos(double %15)
%17 = fmul double %14, %16
store double %17, double* %9
%18 = load double, double* %5
%19 = call double @cos(double %18)
%20 = load double, double* %7
%21 = call double @sin(double %20)
%22 = load double, double* %5
%23 = call double @sin(double %22)
%24 = load double, double* %7
%25 = call double @cos(double %24)
%26 = fmul double %23, %25
%27 = load double, double* %6
%28 = load double, double* %8
%29 = fsub double %27, %28
%30 = call double @cos(double %29)
%31 = fmul double %26, %30
%32 = fneg double %31
%33 = call double @llvm.fmuladd.f64(double %19, double %21, double %32)
store double %33, double* %10
%34 = load double, double* %9
%35 = call i32 @fabs(double %34)
%36 = sitofp i32 %35 to double
%37 = fcmp olt double %36, 1.000000e-15
br i1 %37, label %38, label %39
38: ; preds = %4
store double 0.000000e+00, double* %9
br label %39
39: ; preds = %38, %4
%40 = load double, double* %10
%41 = call i32 @fabs(double %40)
%42 = sitofp i32 %41 to double
%43 = fcmp olt double %42, 1.000000e-15
br i1 %43, label %44, label %45
44: ; preds = %39
store double 0.000000e+00, double* %10
br label %45
45: ; preds = %44, %39
%46 = load double, double* %9
%47 = load double, double* %10
%48 = call double @atan2(double %46, double %47)
ret double %48
}

LLVM IR (-O2):
define double @heading(double %0, double %1, double %2, double %3) {
%5 = fsub double %1, %3
%6 = tail call double @sin(double %5)
%7 = tail call double @cos(double %2)
%8 = fmul double %6, %7
%9 = tail call double @cos(double %0)
%10 = tail call double @sin(double %2)
%11 = tail call double @sin(double %0)
%12 = tail call double @cos(double %2)
%13 = tail call double @cos(double %5)
%14 = fneg double %11
%15 = fmul double %12, %14
%16 = fmul double %15, %13
%17 = tail call double @llvm.fmuladd.f64(double %9, double %10, double %16)
%18 = tail call i32 @fabs(double %8)
%19 = icmp slt i32 %18, 1
%20 = select i1 %19, double 0.000000e+00, double %8
%21 = tail call i32 @fabs(double %17)
%22 = icmp slt i32 %21, 1
%23 = select i1 %22, double 0.000000e+00, double %17
%24 = tail call double @atan2(double %20, double %23)
ret double %24
}