#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 M_PI;
double atan2(double, double);
double cos(double);
double fmod(double, double);
double sin(double);
double geom_bearing_between_coordinates(double lat1, double lon1, double lat2,
                                        double lon2) {
  double dLon = (lon2 - lon1) * (M_PI / 180.0);
  lat1 = lat1 * (M_PI / 180.0);
  lat2 = lat2 * (M_PI / 180.0);
  double y = sin(dLon) * cos(lat2);
  double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
  return fmod((atan2(y, x) * (180.0 / M_PI)) + 360.0, 360.0);
}


x86 assembly (clang, -O0):
<geom_bearing_between_coordinates>:
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  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    0x2e7b(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe8f(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e56(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe6a(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e31(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe45(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%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,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <cos@plt>
movsd  -0x50(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x40(%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,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1030 <atan2@plt>
movsd  0xd6b(%rip),%xmm1
mov    0x2d44(%rip),%rax
divsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd4c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xd40(%rip),%xmm1
call   1040 <fmod@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_bearing_between_coordinates>:
push   %rbx
sub    $0x30,%rsp
subsd  %xmm1,%xmm3
mov    0x2e98(%rip),%rbx
movsd  (%rbx),%xmm1
divsd  0xea4(%rip),%xmm1
mulsd  %xmm1,%xmm3
movsd  %xmm3,0x28(%rsp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm2,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm3,%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   1060 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x28(%rsp),%xmm0
call   1060 <cos@plt>
movsd  (%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
call   1030 <atan2@plt>
movsd  0xde0(%rip),%xmm1
divsd  (%rbx),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdd8(%rip),%xmm1
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
jmp    1040 <fmod@plt>

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @geom_bearing_between_coordinates(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
%11 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%12 = load double, double* %8
%13 = load double, double* %6
%14 = fsub double %12, %13
%15 = load double, double* @M_PI
%16 = fdiv double %15, 1.800000e+02
%17 = fmul double %14, %16
store double %17, double* %9
%18 = load double, double* %5
%19 = load double, double* @M_PI
%20 = fdiv double %19, 1.800000e+02
%21 = fmul double %18, %20
store double %21, double* %5
%22 = load double, double* %7
%23 = load double, double* @M_PI
%24 = fdiv double %23, 1.800000e+02
%25 = fmul double %22, %24
store double %25, double* %7
%26 = load double, double* %9
%27 = call double @sin(double %26)
%28 = load double, double* %7
%29 = call double @cos(double %28)
%30 = fmul double %27, %29
store double %30, double* %10
%31 = load double, double* %5
%32 = call double @cos(double %31)
%33 = load double, double* %7
%34 = call double @sin(double %33)
%35 = load double, double* %5
%36 = call double @sin(double %35)
%37 = load double, double* %7
%38 = call double @cos(double %37)
%39 = fmul double %36, %38
%40 = load double, double* %9
%41 = call double @cos(double %40)
%42 = fmul double %39, %41
%43 = fneg double %42
%44 = call double @llvm.fmuladd.f64(double %32, double %34, double %43)
store double %44, double* %11
%45 = load double, double* %10
%46 = load double, double* %11
%47 = call double @atan2(double %45, double %46)
%48 = load double, double* @M_PI
%49 = fdiv double 1.800000e+02, %48
%50 = call double @llvm.fmuladd.f64(double %47, double %49, double 3.600000e+02)
%51 = call double @fmod(double %50, double 3.600000e+02)
ret double %51
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @geom_bearing_between_coordinates(double %0, double %1, double %2, double %3) {
%5 = fsub double %3, %1
%6 = load double, double* @M_PI
%7 = fdiv double %6, 1.800000e+02
%8 = fmul double %5, %7
%9 = fmul double %7, %0
%10 = fmul double %7, %2
%11 = tail call double @sin(double %8)
%12 = tail call double @cos(double %10)
%13 = fmul double %11, %12
%14 = tail call double @cos(double %9)
%15 = tail call double @sin(double %10)
%16 = tail call double @sin(double %9)
%17 = tail call double @cos(double %10)
%18 = tail call double @cos(double %8)
%19 = fneg double %16
%20 = fmul double %17, %19
%21 = fmul double %20, %18
%22 = tail call double @llvm.fmuladd.f64(double %14, double %15, double %21)
%23 = tail call double @atan2(double %13, double %22)
%24 = load double, double* @M_PI
%25 = fdiv double 1.800000e+02, %24
%26 = tail call double @llvm.fmuladd.f64(double %23, double %25, double 3.600000e+02)
%27 = tail call double @fmod(double %26, double 3.600000e+02)
ret double %27
}