#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 acos(double);
double cos(double);
double fabs(double);
double sin(double);
float distance(double lat1, double lon1, double lat2, double lon2, int units) {
  double a, b, p, dtheta, d;
  double R[2] = {3958.754, 6370.997}, PI = 3.141592654;
  double DEG2RAD = (PI / 180.0), RAD2DEG = (180.0 / PI);
  if ((units < 0) || (units > 1))
    units = 0;
  if (lat1 > 90.0)
    lat1 -= 180.0;
  if (lat2 > 90.0)
    lat2 -= 180.0;
  a = lat1 * DEG2RAD;
  b = lat2 * DEG2RAD;
  p = fabs(lon1 - lon2) * DEG2RAD;
  dtheta = (sin(a) * sin(b)) + (cos(a) * cos(b) * cos(p));
  dtheta = acos(dtheta) * RAD2DEG;
  d = (dtheta * PI * R[units]) / 180.0;
  return (float)d;
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xed4(%rip),%rax
mov    %rax,-0x58(%rbp)
movsd  0xe98(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xe6d(%rip),%xmm0
divsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11b1 <distance+0x81>
cmpl   $0x1,-0x24(%rbp)
jle    11b8 <distance+0x88>
movl   $0x0,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe4b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e5 <distance+0xb5>
movsd  -0x8(%rbp),%xmm0
movsd  0xe24(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe1e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1212 <distance+0xe2>
movsd  -0x18(%rbp),%xmm0
movsd  0xdf7(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movaps 0xddf(%rip),%xmm1
pand   %xmm1,%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x40(%rbp),%xmm0
call   1050 <cos@plt>
movsd  -0x90(%rbp),%xmm1
ff
movsd  -0x88(%rbp),%xmm2
ff
movaps %xmm0,%xmm3
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <acos@plt>
mulsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
movslq -0x24(%rbp),%rax
mulsd  -0x60(%rbp,%rax,8),%xmm0
movsd  0xcfa(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
push   %rbx
sub    $0x40,%rsp
movsd  0xec3(%rip),%xmm4
movapd %xmm0,%xmm5
addsd  %xmm4,%xmm5
movsd  0xebb(%rip),%xmm6
movapd %xmm6,%xmm7
cmpltsd %xmm0,%xmm7
andpd  %xmm7,%xmm5
andnpd %xmm0,%xmm7
orpd   %xmm5,%xmm7
addsd  %xmm2,%xmm4
cmpltsd %xmm2,%xmm6
andpd  %xmm6,%xmm4
andnpd %xmm2,%xmm6
xor    %ebx,%ebx
cmp    $0x2,%edi
cmovb  %edi,%ebx
orpd   %xmm4,%xmm6
movsd  0xe89(%rip),%xmm2
movapd %xmm7,%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm0,0x10(%rsp)
mulsd  %xmm2,%xmm6
movapd %xmm6,(%rsp)
subsd  %xmm3,%xmm1
andpd  0xe86(%rip),%xmm1
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x30(%rsp)
call   1040 <sin@plt>
movsd  %xmm0,0x38(%rsp)
movaps (%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x28(%rsp)
movaps 0x10(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movapd (%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x30(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mulsd  0x38(%rsp),%xmm1
addsd  %xmm1,%xmm0
call   1030 <acos@plt>
mulsd  0xdf8(%rip),%xmm0
mulsd  0xdf8(%rip),%xmm0
lea    0xe11(%rip),%rax
mulsd  (%rax,%rbx,8),%xmm0
divsd  0xdec(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.distance.R = [2 x double] [double 0x40AEED820C49BA5E, double 0x40B8E2FF3B645A1D]
define float @distance(double %0, double %1, double %2, double %3, i32 %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca [2 x double]
%17 = alloca double
%18 = alloca double
%19 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store i32 %4, i32* %10
%20 = bitcast [2 x double]* %16 to i8*
store double 0x400921FB54524550, double* %17
%21 = load double, double* %17
%22 = fdiv double %21, 1.800000e+02
store double %22, double* %18
%23 = load double, double* %17
%24 = fdiv double 1.800000e+02, %23
store double %24, double* %19
%25 = load i32, i32* %10
%26 = icmp slt i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %5
%28 = load i32, i32* %10
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %27, %5
store i32 0, i32* %10
br label %31
31: ; preds = %30, %27
%32 = load double, double* %6
%33 = fcmp ogt double %32, 9.000000e+01
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load double, double* %6
%36 = fsub double %35, 1.800000e+02
store double %36, double* %6
br label %37
37: ; preds = %34, %31
%38 = load double, double* %8
%39 = fcmp ogt double %38, 9.000000e+01
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load double, double* %8
%42 = fsub double %41, 1.800000e+02
store double %42, double* %8
br label %43
43: ; preds = %40, %37
%44 = load double, double* %6
%45 = load double, double* %18
%46 = fmul double %44, %45
store double %46, double* %11
%47 = load double, double* %8
%48 = load double, double* %18
%49 = fmul double %47, %48
store double %49, double* %12
%50 = load double, double* %7
%51 = load double, double* %9
%52 = fsub double %50, %51
%53 = call double @llvm.fabs.f64(double %52)
%54 = load double, double* %18
%55 = fmul double %53, %54
store double %55, double* %13
%56 = load double, double* %11
%57 = call double @sin(double %56)
%58 = load double, double* %12
%59 = call double @sin(double %58)
%60 = load double, double* %11
%61 = call double @cos(double %60)
%62 = load double, double* %12
%63 = call double @cos(double %62)
%64 = fmul double %61, %63
%65 = load double, double* %13
%66 = call double @cos(double %65)
%67 = fmul double %64, %66
%68 = call double @llvm.fmuladd.f64(double %57, double %59, double %67)
store double %68, double* %14
%69 = load double, double* %14
%70 = call double @acos(double %69)
%71 = load double, double* %19
%72 = fmul double %70, %71
store double %72, double* %14
%73 = load double, double* %14
%74 = load double, double* %17
%75 = fmul double %73, %74
%76 = load i32, i32* %10
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [2 x double], [2 x double]* %16, i64 0, i64 %77
%79 = load double, double* %78
%80 = fmul double %75, %79
%81 = fdiv double %80, 1.800000e+02
store double %81, double* %15
%82 = load double, double* %15
%83 = fptrunc double %82 to float
ret float %83
}

LLVM IR (-O2):
@__const.distance.R = [2 x double] [double 0x40AEED820C49BA5E, double 0x40B8E2FF3B645A1D]
define float @distance(double %0, double %1, double %2, double %3, i32 %4) {
%6 = fcmp ogt double %0, 9.000000e+01
%7 = fadd double %0, -1.800000e+02
%8 = select i1 %6, double %7, double %0
%9 = fcmp ogt double %2, 9.000000e+01
%10 = fadd double %2, -1.800000e+02
%11 = select i1 %9, double %10, double %2
%12 = icmp ugt i32 %4, 1
%13 = select i1 %12, i32 0, i32 %4
%14 = fmul double %8, 0x3F91DF46A25CA311
%15 = fmul double %11, 0x3F91DF46A25CA311
%16 = fsub double %1, %3
%17 = tail call double @llvm.fabs.f64(double %16)
%18 = fmul double %17, 0x3F91DF46A25CA311
%19 = tail call double @sin(double %14)
%20 = tail call double @sin(double %15)
%21 = tail call double @cos(double %14)
%22 = tail call double @cos(double %15)
%23 = fmul double %21, %22
%24 = tail call double @cos(double %18)
%25 = fmul double %23, %24
%26 = tail call double @llvm.fmuladd.f64(double %19, double %20, double %25)
%27 = tail call double @acos(double %26)
%28 = fmul double %27, 0x404CA5DC1A53B118
%29 = fmul double %28, 0x400921FB54524550
%30 = zext i32 %13 to i64
%31 = getelementptr inbounds [2 x double], [2 x double]* @__const.distance.R, i64 0, i64 %30
%32 = load double, double* %31
%33 = fmul double %32, %29
%34 = fdiv double %33, 1.800000e+02
%35 = fptrunc double %34 to float
ret float %35
}