#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 deg2rad(double);
int /*<<< orphan*/ printf(char *, double, ...);
double sin(double);
int /*<<< orphan*/ sqrt(int);
double get_distance(double lat0, double lon0, double lat1, double lon1) {
  printf("lat0: %lf lon0: %lf lat1: %lf lon1: %lf \n", lat0, lon0, lat1, lon1);
  double dLat = deg2rad(lat1 - lat0);
  double dLon = deg2rad(lon1 - lon0);
  double a = sin(dLat / 2) * sin(dLat / 2) + cos(deg2rad(lat0)) *
                                                 cos(deg2rad(lat1)) *
                                                 sin(dLon / 2) * sin(dLon / 2);
  double c = 2 * atan2(sqrt(a), sqrt(1 - a));
  double d = 6378137 * c;
  printf("distance (m): %lf\n", d);
  return d;
}


x86 assembly (clang, -O0):
<get_distance>:
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  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
lea    0xe7e(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1050 <deg2rad@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1050 <deg2rad@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe1f(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <sin@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <deg2rad@plt>
call   1070 <cos@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <deg2rad@plt>
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdd0(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xda9(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <sin@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,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%edi
call   1080 <sqrt@plt>
mov    %eax,-0x4c(%rbp)
movsd  0xd60(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sqrt@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
call   1030 <atan2@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd2c(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xd58(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x48(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_distance>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm3,0x28(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x20(%rsp)
lea    0xe94(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
call   1050 <deg2rad@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x28(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
call   1050 <deg2rad@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe39(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1060 <sin@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1050 <deg2rad@plt>
call   1070 <cos@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <deg2rad@plt>
call   1070 <cos@plt>
mulsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xdd7(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1060 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <sin@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0x28(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
cvttsd2si %xmm1,%edi
call   1080 <sqrt@plt>
mov    %eax,%ebx
movsd  0xd8e(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1080 <sqrt@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <atan2@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xd6d(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xd92(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"lat0: %lf lon0: %lf lat1: %lf lon1: %lf \0A\00"
@.str.1 = [19 x i8] c"distance (m): %lf\0A\00"
define double @get_distance(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
%14 = load double, double* %5
%15 = load double, double* %6
%16 = load double, double* %7
%17 = load double, double* %8
%18 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), double %14, double %15, double %16, double %17)
%19 = load double, double* %7
%20 = load double, double* %5
%21 = fsub double %19, %20
%22 = call double @deg2rad(double %21)
store double %22, double* %9
%23 = load double, double* %8
%24 = load double, double* %6
%25 = fsub double %23, %24
%26 = call double @deg2rad(double %25)
store double %26, double* %10
%27 = load double, double* %9
%28 = fdiv double %27, 2.000000e+00
%29 = call double @sin(double %28)
%30 = load double, double* %9
%31 = fdiv double %30, 2.000000e+00
%32 = call double @sin(double %31)
%33 = load double, double* %5
%34 = call double @deg2rad(double %33)
%35 = call double @cos(double %34)
%36 = load double, double* %7
%37 = call double @deg2rad(double %36)
%38 = call double @cos(double %37)
%39 = fmul double %35, %38
%40 = load double, double* %10
%41 = fdiv double %40, 2.000000e+00
%42 = call double @sin(double %41)
%43 = fmul double %39, %42
%44 = load double, double* %10
%45 = fdiv double %44, 2.000000e+00
%46 = call double @sin(double %45)
%47 = fmul double %43, %46
%48 = call double @llvm.fmuladd.f64(double %29, double %32, double %47)
store double %48, double* %11
%49 = load double, double* %11
%50 = fptosi double %49 to i32
%51 = call i32 @sqrt(i32 %50)
%52 = load double, double* %11
%53 = fsub double 1.000000e+00, %52
%54 = fptosi double %53 to i32
%55 = call i32 @sqrt(i32 %54)
%56 = call i32 @atan2(i32 %51, i32 %55)
%57 = mul nsw i32 2, %56
%58 = sitofp i32 %57 to double
store double %58, double* %12
%59 = load double, double* %12
%60 = fmul double 0x415854A640000000, %59
store double %60, double* %13
%61 = load double, double* %13
%62 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %61)
%63 = load double, double* %13
ret double %63
}

LLVM IR (-O2):
@.str = [42 x i8] c"lat0: %lf lon0: %lf lat1: %lf lon1: %lf \0A\00"
@.str.1 = [19 x i8] c"distance (m): %lf\0A\00"
define double @get_distance(double %0, double %1, double %2, double %3) {
%5 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), double %0, double %1, double %2, double %3)
%6 = fsub double %2, %0
%7 = tail call double @deg2rad(double %6)
%8 = fsub double %3, %1
%9 = tail call double @deg2rad(double %8)
%10 = fmul double %7, 5.000000e-01
%11 = tail call double @sin(double %10)
%12 = tail call double @sin(double %10)
%13 = tail call double @deg2rad(double %0)
%14 = tail call double @cos(double %13)
%15 = tail call double @deg2rad(double %2)
%16 = tail call double @cos(double %15)
%17 = fmul double %14, %16
%18 = fmul double %9, 5.000000e-01
%19 = tail call double @sin(double %18)
%20 = fmul double %17, %19
%21 = tail call double @sin(double %18)
%22 = fmul double %20, %21
%23 = tail call double @llvm.fmuladd.f64(double %11, double %12, double %22)
%24 = fptosi double %23 to i32
%25 = tail call i32 @sqrt(i32 %24)
%26 = fsub double 1.000000e+00, %23
%27 = fptosi double %26 to i32
%28 = tail call i32 @sqrt(i32 %27)
%29 = tail call i32 @atan2(i32 %25, i32 %28)
%30 = shl nsw i32 %29, 1
%31 = sitofp i32 %30 to double
%32 = fmul double %31, 0x415854A640000000
%33 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %32)
ret double %32
}