#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 atan2(float, int);
float cos(float);
float sin(float);
int sqrt(int);
long haversineDistance(float lat1, float lon1, float lat2, float lon2) {
  float dx, dy, dz, a, b;
  lon1 -= lon2;
  lon1 *= (3.1415926536 / 180), lat1 *= (3.1415926536 / 180),
      lat2 *= (3.1415926536 / 180);
  dz = sin(lat1) - sin(lat2);
  dx = cos(lon1) * cos(lat1) - cos(lat2);
  dy = sin(lon1) * cos(lat1);
  a = (dx * dx + dy * dy + dz * dz);
  b = sqrt(a) / 2;
  return 2 * 6371 * atan2(b, sqrt(1 - b * b));
}


x86 assembly (clang, -O0):
<haversineDistance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  -0x10(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe88(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe6a(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe4c(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0xc(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x38(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <cos@plt>
movss  -0x34(%rbp),%xmm2
movaps %xmm0,%xmm1
movss  -0x30(%rbp),%xmm0
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
movss  -0x18(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
cvttss2si -0x20(%rbp),%edi
call   1060 <sqrt@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm1,%xmm0
movss  0xd19(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1060 <sqrt@plt>
movss  -0x28(%rbp),%xmm0
mov    %eax,%edi
call   1030 <atan2@plt>
imul   $0x31c6,%eax,%eax
cltq
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<haversineDistance>:
sub    $0x18,%rsp
subss  %xmm3,%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xeac(%rip),%xmm3
mulsd  %xmm3,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
mulsd  %xmm3,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
mulsd  %xmm3,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0xc(%rsp)
call   1040 <sin@plt>
movss  %xmm0,(%rsp)
movss  0xc(%rsp),%xmm0
call   1040 <sin@plt>
movss  (%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
movss  0x4(%rsp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,0x14(%rsp)
movss  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <cos@plt>
movss  0x8(%rsp),%xmm1
mulss  0x14(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  0x4(%rsp),%xmm0
call   1040 <sin@plt>
movss  %xmm0,0x4(%rsp)
movss  0x10(%rsp),%xmm0
call   1050 <cos@plt>
mulss  0x4(%rsp),%xmm0
mulss  %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
cvttss2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
movss  %xmm0,(%rsp)
mulss  %xmm0,%xmm0
movss  0xdae(%rip),%xmm1
subss  %xmm0,%xmm1
cvttss2si %xmm1,%edi
call   1060 <sqrt@plt>
movss  (%rsp),%xmm0
mov    %eax,%edi
call   1030 <atan2@plt>
imul   $0x31c6,%eax,%eax
cltq
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i64 @haversineDistance(float %0, float %1, float %2, float %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%14 = load float, float* %8
%15 = load float, float* %6
%16 = fsub float %15, %14
store float %16, float* %6
%17 = load float, float* %6
%18 = fpext float %17 to double
%19 = fmul double %18, 0x3F91DF46A252DD11
%20 = fptrunc double %19 to float
store float %20, float* %6
%21 = load float, float* %5
%22 = fpext float %21 to double
%23 = fmul double %22, 0x3F91DF46A252DD11
%24 = fptrunc double %23 to float
store float %24, float* %5
%25 = load float, float* %7
%26 = fpext float %25 to double
%27 = fmul double %26, 0x3F91DF46A252DD11
%28 = fptrunc double %27 to float
store float %28, float* %7
%29 = load float, float* %5
%30 = call float @sin(float %29)
%31 = load float, float* %7
%32 = call float @sin(float %31)
%33 = fsub float %30, %32
store float %33, float* %11
%34 = load float, float* %6
%35 = call float @cos(float %34)
%36 = load float, float* %5
%37 = call float @cos(float %36)
%38 = load float, float* %7
%39 = call float @cos(float %38)
%40 = fneg float %39
%41 = call float @llvm.fmuladd.f32(float %35, float %37, float %40)
store float %41, float* %9
%42 = load float, float* %6
%43 = call float @sin(float %42)
%44 = load float, float* %5
%45 = call float @cos(float %44)
%46 = fmul float %43, %45
store float %46, float* %10
%47 = load float, float* %9
%48 = load float, float* %9
%49 = load float, float* %10
%50 = load float, float* %10
%51 = fmul float %49, %50
%52 = call float @llvm.fmuladd.f32(float %47, float %48, float %51)
%53 = load float, float* %11
%54 = load float, float* %11
%55 = call float @llvm.fmuladd.f32(float %53, float %54, float %52)
store float %55, float* %12
%56 = load float, float* %12
%57 = fptosi float %56 to i32
%58 = call i32 @sqrt(i32 %57)
%59 = sdiv i32 %58, 2
%60 = sitofp i32 %59 to float
store float %60, float* %13
%61 = load float, float* %13
%62 = load float, float* %13
%63 = load float, float* %13
%64 = fneg float %62
%65 = call float @llvm.fmuladd.f32(float %64, float %63, float 1.000000e+00)
%66 = fptosi float %65 to i32
%67 = call i32 @sqrt(i32 %66)
%68 = call i32 @atan2(float %61, i32 %67)
%69 = mul nsw i32 12742, %68
%70 = sext i32 %69 to i64
ret i64 %70
}

LLVM IR (-O2):
define i64 @haversineDistance(float %0, float %1, float %2, float %3) {
%5 = fsub float %1, %3
%6 = fpext float %5 to double
%7 = fmul double %6, 0x3F91DF46A252DD11
%8 = fptrunc double %7 to float
%9 = fpext float %0 to double
%10 = fmul double %9, 0x3F91DF46A252DD11
%11 = fptrunc double %10 to float
%12 = fpext float %2 to double
%13 = fmul double %12, 0x3F91DF46A252DD11
%14 = fptrunc double %13 to float
%15 = tail call float @sin(float %11)
%16 = tail call float @sin(float %14)
%17 = fsub float %15, %16
%18 = tail call float @cos(float %8)
%19 = tail call float @cos(float %11)
%20 = tail call float @cos(float %14)
%21 = fneg float %20
%22 = tail call float @llvm.fmuladd.f32(float %18, float %19, float %21)
%23 = tail call float @sin(float %8)
%24 = tail call float @cos(float %11)
%25 = fmul float %23, %24
%26 = fmul float %25, %25
%27 = tail call float @llvm.fmuladd.f32(float %22, float %22, float %26)
%28 = tail call float @llvm.fmuladd.f32(float %17, float %17, float %27)
%29 = fptosi float %28 to i32
%30 = tail call i32 @sqrt(i32 %29)
%31 = sdiv i32 %30, 2
%32 = sitofp i32 %31 to float
%33 = fneg float %32
%34 = tail call float @llvm.fmuladd.f32(float %33, float %32, float 1.000000e+00)
%35 = fptosi float %34 to i32
%36 = tail call i32 @sqrt(i32 %35)
%37 = tail call i32 @atan2(float %32, i32 %36)
%38 = mul nsw i32 %37, 12742
%39 = sext i32 %38 to i64
ret i64 %39
}