#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 pow(int /*<<< orphan*/, int);
int /*<<< orphan*/ sin(double);
int /*<<< orphan*/ sqrt(int);
double ll_distance_km(double lat1, double lon1, double lat2, double lon2) {
  double a;
  lat1 *= M_PI / 180;
  lon1 *= M_PI / 180;
  lat2 *= M_PI / 180;
  lon2 *= M_PI / 180;
  a = pow(sin((lat2 - lat1) / 2), 2) +
      cos(lat1) * cos(lat2) * pow(sin((lon2 - lon1) / 2), 2);
  return (6371 * 2 * atan2(sqrt(a), sqrt(1 - a)));
}


x86 assembly (clang, -O0):
<ll_distance_km>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    $0xb4,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xdb8(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x28(%rbp),%edi
call   1070 <sqrt@plt>
mov    %eax,-0x2c(%rbp)
movsd  0xd6c(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   1030 <atan2@plt>
imul   $0x31c6,%eax,%eax
cvtsi2sd %eax,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ll_distance_km>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm4
mov    0x2e88(%rip),%rax
movslq (%rax),%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  %xmm0,%xmm4
movsd  %xmm4,(%rsp)
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
mulsd  %xmm3,%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movapd %xmm2,%xmm0
subsd  %xmm4,%xmm0
mulsd  0xe4a(%rip),%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xe00(%rip),%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
mov    %eax,%ebx
movsd  0xdd2(%rip),%xmm0
subsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <atan2@plt>
imul   $0x31c6,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@M_PI = global i32 0
define double @ll_distance_km(double %0, double %1, double %2, double %3) {
%5 = load i32, i32* @M_PI
%6 = sdiv i32 %5, 180
%7 = sitofp i32 %6 to double
%8 = fmul double %7, %0
%9 = fmul double %7, %1
%10 = fmul double %7, %2
%11 = fmul double %7, %3
%12 = fsub double %10, %8
%13 = fmul double %12, 5.000000e-01
%14 = tail call i32 @sin(double %13)
%15 = tail call double @pow(i32 %14, i32 2)
%16 = tail call double @cos(double %8)
%17 = tail call double @cos(double %10)
%18 = fmul double %16, %17
%19 = fsub double %11, %9
%20 = fmul double %19, 5.000000e-01
%21 = tail call i32 @sin(double %20)
%22 = tail call double @pow(i32 %21, i32 2)
%23 = tail call double @llvm.fmuladd.f64(double %18, double %22, double %15)
%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 = mul nsw i32 %29, 12742
%31 = sitofp i32 %30 to double
ret double %31
}