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


x86 assembly (clang, -O0):
<haversineDistance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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  0xe80(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe62(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe44(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <cos@plt>
movss  -0x28(%rbp),%xmm2
movaps %xmm0,%xmm1
movss  -0x24(%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   1030 <sin@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x20(%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
call   1060 <sqrt@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <asin@plt>
shl    $0x1,%eax
imul   $0x18e3,%eax,%eax
cltq
add    $0x30,%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,(%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   1030 <sin@plt>
movss  %xmm0,0x8(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <sin@plt>
movss  0x8(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x8(%rsp)
movss  (%rsp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,0x14(%rsp)
movss  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movss  %xmm0,0x4(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <cos@plt>
movss  0x4(%rsp),%xmm1
mulss  0x14(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  (%rsp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,(%rsp)
movss  0x10(%rsp),%xmm0
call   1050 <cos@plt>
mulss  (%rsp),%xmm0
mulss  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm1,%xmm0
movss  0x8(%rsp),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1040 <asin@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
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%12 = load float, float* %8
%13 = load float, float* %6
%14 = fsub float %13, %12
store float %14, float* %6
%15 = load float, float* %6
%16 = fpext float %15 to double
%17 = fmul double %16, 0x3F91DF46A252DD11
%18 = fptrunc double %17 to float
store float %18, float* %6
%19 = load float, float* %5
%20 = fpext float %19 to double
%21 = fmul double %20, 0x3F91DF46A252DD11
%22 = fptrunc double %21 to float
store float %22, float* %5
%23 = load float, float* %7
%24 = fpext float %23 to double
%25 = fmul double %24, 0x3F91DF46A252DD11
%26 = fptrunc double %25 to float
store float %26, float* %7
%27 = load float, float* %5
%28 = call float @sin(float %27)
%29 = load float, float* %7
%30 = call float @sin(float %29)
%31 = fsub float %28, %30
store float %31, float* %11
%32 = load float, float* %6
%33 = call float @cos(float %32)
%34 = load float, float* %5
%35 = call float @cos(float %34)
%36 = load float, float* %7
%37 = call float @cos(float %36)
%38 = fneg float %37
%39 = call float @llvm.fmuladd.f32(float %33, float %35, float %38)
store float %39, float* %9
%40 = load float, float* %6
%41 = call float @sin(float %40)
%42 = load float, float* %5
%43 = call float @cos(float %42)
%44 = fmul float %41, %43
store float %44, float* %10
%45 = load float, float* %9
%46 = load float, float* %9
%47 = load float, float* %10
%48 = load float, float* %10
%49 = fmul float %47, %48
%50 = call float @llvm.fmuladd.f32(float %45, float %46, float %49)
%51 = load float, float* %11
%52 = load float, float* %11
%53 = call float @llvm.fmuladd.f32(float %51, float %52, float %50)
%54 = call i32 @sqrt(float %53)
%55 = sdiv i32 %54, 2
%56 = call i32 @asin(i32 %55)
%57 = mul nsw i32 %56, 2
%58 = mul nsw i32 %57, 6371
%59 = sext i32 %58 to i64
ret i64 %59
}

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 = tail call i32 @sqrt(float %28)
%30 = sdiv i32 %29, 2
%31 = tail call i32 @asin(i32 %30)
%32 = mul nsw i32 %31, 12742
%33 = sext i32 %32 to i64
ret i64 %33
}