#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(int /*<<< orphan*/, int /*<<< orphan*/);
double cos(double);
double degreesToRadians(double);
double sin(double);
int /*<<< orphan*/ sqrt(int);
double distanceInKmBetweenEarthCoordinates(double lat1, double lon1,
                                           double lat2, double lon2) {
  double earthRadiusKm = 6371;
  double dLat = degreesToRadians(lat2 - lat1);
  double dLon = degreesToRadians(lon2 - lon1);
  lat1 = degreesToRadians(lat1);
  lat2 = degreesToRadians(lat2);
  double a = sin(dLat / 2) * sin(dLat / 2) +
             sin(dLon / 2) * sin(dLon / 2) * cos(lat1) * cos(lat2);
  double c = 2 * atan2(sqrt(a), sqrt(1 - a));
  return earthRadiusKm * c;
}


x86 assembly (clang, -O0):
<distanceInKmBetweenEarthCoordinates>:
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  0xe99(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe39(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe1e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe03(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xde8(%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   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <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)
cvttsd2si -0x40(%rbp),%edi
call   1070 <sqrt@plt>
mov    %eax,-0x4c(%rbp)
movsd  0xd69(%rip),%xmm0
subsd  -0x40(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <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
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distanceInKmBetweenEarthCoordinates>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm3,(%rsp)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,0x10(%rsp)
movapd %xmm0,%xmm1
movsd  %xmm0,0x18(%rsp)
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
call   1050 <degreesToRadians@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe38(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
mulsd  0xe09(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1040 <sin@plt>
movsd  %xmm0,0x28(%rsp)
movsd  (%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x28(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x20(%rsp),%xmm0
call   1060 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
cvttsd2si %xmm1,%edi
call   1070 <sqrt@plt>
mov    %eax,%ebx
movsd  0xd9e(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <atan2@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd7d(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

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