#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 M_PI;
int atan2(int /*<<< orphan*/, int /*<<< orphan*/);
double cos(double);
double sin(double);
int /*<<< orphan*/ sqrt(int);
double haversine_dist(double latA, double lonA, double latB, double lonB) {
  double R = 6371;
  double dlat = latB - latA;
  double dlon = lonB - lonA;
  double sinlat = sin((dlat / 2) * (M_PI / 180));
  double sinlon = sin((dlon / 2) * (M_PI / 180));
  double a = sinlat * sinlat + sinlon * sinlon * cos(latA * (M_PI / 180)) *
                                   cos(latB * (M_PI / 180));
  double c = 2 * atan2(sqrt(a), sqrt(1 - a));
  double d = R * c;
  return d;
}


x86 assembly (clang, -O0):
<haversine_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe71(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe3d(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x8(%rbp),%xmm0
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1050 <cos@plt>
movsd  -0x80(%rbp),%xmm1
movsd  -0x78(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cvttsd2si -0x50(%rbp),%edi
call   1060 <sqrt@plt>
mov    %eax,-0x64(%rbp)
movsd  0xd56(%rip),%xmm0
subsd  -0x50(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    -0x64(%rbp),%edi
mov    %eax,%esi
call   1030 <atan2@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<haversine_dist>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
subsd  %xmm0,%xmm2
subsd  %xmm1,%xmm3
movsd  %xmm3,(%rsp)
mulsd  0xe9a(%rip),%xmm2
mov    0x2e7b(%rip),%rbx
movslq (%rbx),%rax
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x7,%ecx
add    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  %xmm2,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm1
mulsd  0xe56(%rip),%xmm1
movslq (%rbx),%rax
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x7,%ecx
add    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  %xmm1,%xmm0
call   1040 <sin@plt>
mulsd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movslq (%rbx),%rax
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x7,%ecx
add    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movslq (%rbx),%rax
imul   $0xffffffffb60b60b7,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x7,%ecx
add    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0x18(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
cvttsd2si %xmm1,%edi
call   1060 <sqrt@plt>
mov    %eax,%ebx
movsd  0xd9b(%rip),%xmm0
subsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <atan2@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd7a(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@M_PI = global i32 0
define double @haversine_dist(double %0, double %1, double %2, double %3) {
%5 = fsub double %2, %0
%6 = fsub double %3, %1
%7 = fmul double %5, 5.000000e-01
%8 = load i32, i32* @M_PI
%9 = sdiv i32 %8, 180
%10 = sitofp i32 %9 to double
%11 = fmul double %7, %10
%12 = tail call double @sin(double %11)
%13 = fmul double %6, 5.000000e-01
%14 = load i32, i32* @M_PI
%15 = sdiv i32 %14, 180
%16 = sitofp i32 %15 to double
%17 = fmul double %13, %16
%18 = tail call double @sin(double %17)
%19 = fmul double %18, %18
%20 = load i32, i32* @M_PI
%21 = sdiv i32 %20, 180
%22 = sitofp i32 %21 to double
%23 = fmul double %22, %0
%24 = tail call double @cos(double %23)
%25 = fmul double %19, %24
%26 = load i32, i32* @M_PI
%27 = sdiv i32 %26, 180
%28 = sitofp i32 %27 to double
%29 = fmul double %28, %2
%30 = tail call double @cos(double %29)
%31 = fmul double %25, %30
%32 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %31)
%33 = fptosi double %32 to i32
%34 = tail call i32 @sqrt(i32 %33)
%35 = fsub double 1.000000e+00, %32
%36 = fptosi double %35 to i32
%37 = tail call i32 @sqrt(i32 %36)
%38 = tail call i32 @atan2(i32 %34, i32 %37)
%39 = shl nsw i32 %38, 1
%40 = sitofp i32 %39 to double
%41 = fmul double %40, 6.371000e+03
ret double %41
}