#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;
int atan2(int /*<<< orphan*/, int /*<<< orphan*/);
double cos(double);
double sin(double);
int /*<<< orphan*/ sqrt(double);
double geom_distance_between_coordinates(double lat1, double lon1, double lat2,
                                         double lon2) {
  double R = 6371;
  double dLat = (lat2 - lat1) * (M_PI / 180.0);
  double dLon = (lon2 - lon1) * (M_PI / 180.0);
  lat1 = lat1 * (M_PI / 180.0);
  lat2 = lat2 * (M_PI / 180.0);
  double a = sin(dLat / 2.0) * sin(dLat / 2.0) +
             sin(dLon / 2.0) * sin(dLon / 2.0) * cos(lat1) * cos(lat2);
  double c = 2 * atan2(sqrt(a), sqrt(1.0 - a));
  return R * c * 1000.0;
}


x86 assembly (clang, -O0):
<geom_distance_between_coordinates>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
mov    0x2e6b(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe8f(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    0x2e41(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe65(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e1c(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe40(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2df7(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xe1b(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdf9(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdde(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xdc3(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xda8(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1060 <sqrt@plt>
mov    %eax,-0x4c(%rbp)
movsd  0xd29(%rip),%xmm0
subsd  -0x40(%rbp),%xmm0
call   1060 <sqrt@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
call   1030 <atan2@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  0xcef(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geom_distance_between_coordinates>:
push   %rbx
sub    $0x30,%rsp
movapd %xmm2,%xmm5
mov    0x2e98(%rip),%rax
movsd  (%rax),%xmm4
divsd  0xea4(%rip),%xmm4
subsd  %xmm0,%xmm5
mulsd  %xmm4,%xmm5
subsd  %xmm1,%xmm3
mulsd  %xmm4,%xmm3
movsd  %xmm3,(%rsp)
mulsd  %xmm4,%xmm0
movsd  %xmm0,0x18(%rsp)
mulsd  %xmm2,%xmm4
movsd  %xmm4,0x28(%rsp)
movapd %xmm5,%xmm0
mulsd  0xe77(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <sin@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
mulsd  0xe48(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1040 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x28(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%ebx
movsd  0xddd(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
call   1060 <sqrt@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <atan2@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xdc0(%rip),%xmm0
mulsd  0xdc0(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

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