#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;
double cos(double);
scalar_t__ pow(double, int);
int sqrt(scalar_t__);
double distance(double from_lat, double from_lon, double to_lat,
                double to_lon) {
  double lambda, phi, phi_m;
  phi_m = (to_lat + from_lat) / 360.0 * M_PI;
  phi = (to_lat - from_lat) / 180.0 * M_PI;
  lambda = (to_lon - from_lon) / 180.0 * M_PI;
  return 6371009 * sqrt(phi * phi + pow(cos(phi_m) * lambda, 2));
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  0xeaa(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e7f(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  0xe7c(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e59(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xe56(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e33(%rip),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <cos@plt>
mulsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
cvtsi2sd %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1050 <sqrt@plt>
imul   $0x6136c1,%eax,%eax
cvtsi2sd %eax,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
sub    $0x18,%rsp
movapd %xmm0,%xmm4
addsd  %xmm2,%xmm4
divsd  0xebc(%rip),%xmm4
mov    0x2e9d(%rip),%rax
movsd  (%rax),%xmm5
mulsd  %xmm5,%xmm4
subsd  %xmm0,%xmm2
movsd  0xea9(%rip),%xmm0
divsd  %xmm0,%xmm2
mulsd  %xmm5,%xmm2
movsd  %xmm2,0x10(%rsp)
subsd  %xmm1,%xmm3
divsd  %xmm0,%xmm3
mulsd  %xmm3,%xmm5
movsd  %xmm5,0x8(%rsp)
movapd %xmm4,%xmm0
call   1030 <cos@plt>
mulsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1050 <sqrt@plt>
imul   $0x6136c1,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @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
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%12 = load double, double* %7
%13 = load double, double* %5
%14 = fadd double %12, %13
%15 = fdiv double %14, 3.600000e+02
%16 = load double, double* @M_PI
%17 = fmul double %15, %16
store double %17, double* %11
%18 = load double, double* %7
%19 = load double, double* %5
%20 = fsub double %18, %19
%21 = fdiv double %20, 1.800000e+02
%22 = load double, double* @M_PI
%23 = fmul double %21, %22
store double %23, double* %10
%24 = load double, double* %8
%25 = load double, double* %6
%26 = fsub double %24, %25
%27 = fdiv double %26, 1.800000e+02
%28 = load double, double* @M_PI
%29 = fmul double %27, %28
store double %29, double* %9
%30 = load double, double* %10
%31 = load double, double* %10
%32 = load double, double* %11
%33 = call double @cos(double %32)
%34 = load double, double* %9
%35 = fmul double %33, %34
%36 = call i64 @pow(double %35, i32 2)
%37 = sitofp i64 %36 to double
%38 = call double @llvm.fmuladd.f64(double %30, double %31, double %37)
%39 = fptosi double %38 to i64
%40 = call i32 @sqrt(i64 %39)
%41 = mul nsw i32 6371009, %40
%42 = sitofp i32 %41 to double
ret double %42
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @distance(double %0, double %1, double %2, double %3) {
%5 = fadd double %0, %2
%6 = fdiv double %5, 3.600000e+02
%7 = load double, double* @M_PI
%8 = fmul double %6, %7
%9 = fsub double %2, %0
%10 = fdiv double %9, 1.800000e+02
%11 = fmul double %10, %7
%12 = fsub double %3, %1
%13 = fdiv double %12, 1.800000e+02
%14 = fmul double %13, %7
%15 = tail call double @cos(double %8)
%16 = fmul double %15, %14
%17 = tail call i64 @pow(double %16, i32 2)
%18 = sitofp i64 %17 to double
%19 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %18)
%20 = fptosi double %19 to i64
%21 = tail call i32 @sqrt(i64 %20)
%22 = mul nsw i32 %21, 6371009
%23 = sitofp i32 %22 to double
ret double %23
}