#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 asin(float);
double cos(float);
double sin(float);
float sqrt(float);
float earth_distance(float lat1, float lon1, float lat2, float lon2) {
  float xd, yd, zd, d;
  lat1 *= (3.14159265 / 180.0);
  lon1 *= (3.14159265 / 180.0);
  lat2 *= (3.14159265 / 180.0);
  lon2 *= (3.14159265 / 180.0);
  xd = 6371230.0 * (cos(lat2) * cos(lon2) - cos(lat1) * cos(lon1));
  yd = 6371230.0 * (cos(lat2) * sin(lon2) - cos(lat1) * sin(lon1));
  zd = 6371230.0 * (sin(lat2) - sin(lat1));
  d = sqrt(xd * xd + yd * yd + zd * zd);
  if (d / (2.0 * 6371230.0) < 0.001) {
    return d;
  } else {
    return 2.0 * 6371230.0 * asin(d / (2.0 * 6371230.0));
  }
}


x86 assembly (clang, -O0):
<earth_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  %xmm3,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeab(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8d(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe6f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe51(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x60(%rbp)
movss  -0x14(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x58(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x50(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <cos@plt>
movsd  -0x60(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm3,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xdc8(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x38(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm3,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xd47(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x30(%rbp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xd10(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
movss  -0x20(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
call   1060 <sqrt@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xcb2(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xc9e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    137b <earth_distance+0x23b>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    13b1 <earth_distance+0x271>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xc7c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1040 <asin@plt>
movaps %xmm0,%xmm1
movsd  0xc64(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<earth_distance>:
sub    $0x38,%rsp
cvtss2sd %xmm0,%xmm0
movsd  0xeb0(%rip),%xmm4
mulsd  %xmm4,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
mulsd  %xmm4,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
mulsd  %xmm4,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x18(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm3,%xmm1
mulsd  %xmm4,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x10(%rsp)
call   1050 <cos@plt>
movsd  %xmm0,0x30(%rsp)
movss  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x28(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x20(%rsp)
movss  0x8(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mulsd  0x30(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe15(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x30(%rsp)
movss  0x18(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x28(%rsp)
movss  0x10(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x20(%rsp)
movss  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x20(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0x28(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xdac(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  %xmm0,0x8(%rsp)
movss  0x18(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xd71(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  0x8(%rsp),%xmm2
mulss  %xmm2,%xmm2
movss  0x30(%rsp),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     12cc <earth_distance+0x18c>
sqrtss %xmm0,%xmm0
jmp    12d1 <earth_distance+0x191>
call   1060 <sqrt@plt>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
divsd  0xd30(%rip),%xmm1
movsd  0xd30(%rip),%xmm2
ucomisd %xmm1,%xmm2
ja     1306 <earth_distance+0x1c6>
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
call   1040 <asin@plt>
mulsd  0xd0e(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define float @earth_distance(float %0, float %1, float %2, float %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
%14 = load float, float* %6
%15 = fpext float %14 to double
%16 = fmul double %15, 0x3F91DF46A1FAE712
%17 = fptrunc double %16 to float
store float %17, float* %6
%18 = load float, float* %7
%19 = fpext float %18 to double
%20 = fmul double %19, 0x3F91DF46A1FAE712
%21 = fptrunc double %20 to float
store float %21, float* %7
%22 = load float, float* %8
%23 = fpext float %22 to double
%24 = fmul double %23, 0x3F91DF46A1FAE712
%25 = fptrunc double %24 to float
store float %25, float* %8
%26 = load float, float* %9
%27 = fpext float %26 to double
%28 = fmul double %27, 0x3F91DF46A1FAE712
%29 = fptrunc double %28 to float
store float %29, float* %9
%30 = load float, float* %8
%31 = call double @cos(float %30)
%32 = load float, float* %9
%33 = call double @cos(float %32)
%34 = load float, float* %6
%35 = call double @cos(float %34)
%36 = load float, float* %7
%37 = call double @cos(float %36)
%38 = fmul double %35, %37
%39 = fneg double %38
%40 = call double @llvm.fmuladd.f64(double %31, double %33, double %39)
%41 = fmul double 6.371230e+06, %40
%42 = fptrunc double %41 to float
store float %42, float* %10
%43 = load float, float* %8
%44 = call double @cos(float %43)
%45 = load float, float* %9
%46 = call double @sin(float %45)
%47 = load float, float* %6
%48 = call double @cos(float %47)
%49 = load float, float* %7
%50 = call double @sin(float %49)
%51 = fmul double %48, %50
%52 = fneg double %51
%53 = call double @llvm.fmuladd.f64(double %44, double %46, double %52)
%54 = fmul double 6.371230e+06, %53
%55 = fptrunc double %54 to float
store float %55, float* %11
%56 = load float, float* %8
%57 = call double @sin(float %56)
%58 = load float, float* %6
%59 = call double @sin(float %58)
%60 = fsub double %57, %59
%61 = fmul double 6.371230e+06, %60
%62 = fptrunc double %61 to float
store float %62, float* %12
%63 = load float, float* %10
%64 = load float, float* %10
%65 = load float, float* %11
%66 = load float, float* %11
%67 = fmul float %65, %66
%68 = call float @llvm.fmuladd.f32(float %63, float %64, float %67)
%69 = load float, float* %12
%70 = load float, float* %12
%71 = call float @llvm.fmuladd.f32(float %69, float %70, float %68)
%72 = call float @sqrt(float %71)
store float %72, float* %13
%73 = load float, float* %13
%74 = fpext float %73 to double
%75 = fdiv double %74, 0x41684DE780000000
%76 = fcmp olt double %75, 1.000000e-03
br i1 %76, label %77, label %79
77: ; preds = %4
%78 = load float, float* %13
store float %78, float* %5
br label %87
79: ; preds = %4
%80 = load float, float* %13
%81 = fpext float %80 to double
%82 = fdiv double %81, 0x41684DE780000000
%83 = fptrunc double %82 to float
%84 = call double @asin(float %83)
%85 = fmul double 0x41684DE780000000, %84
%86 = fptrunc double %85 to float
store float %86, float* %5
br label %87
87: ; preds = %79, %77
%88 = load float, float* %5
ret float %88
}

LLVM IR (-O2):
define float @earth_distance(float %0, float %1, float %2, float %3) {
%5 = fpext float %0 to double
%6 = fmul double %5, 0x3F91DF46A1FAE712
%7 = fptrunc double %6 to float
%8 = fpext float %1 to double
%9 = fmul double %8, 0x3F91DF46A1FAE712
%10 = fptrunc double %9 to float
%11 = fpext float %2 to double
%12 = fmul double %11, 0x3F91DF46A1FAE712
%13 = fptrunc double %12 to float
%14 = fpext float %3 to double
%15 = fmul double %14, 0x3F91DF46A1FAE712
%16 = fptrunc double %15 to float
%17 = tail call double @cos(float %13)
%18 = tail call double @cos(float %16)
%19 = tail call double @cos(float %7)
%20 = tail call double @cos(float %10)
%21 = fneg double %19
%22 = fmul double %20, %21
%23 = tail call double @llvm.fmuladd.f64(double %17, double %18, double %22)
%24 = fmul double %23, 6.371230e+06
%25 = fptrunc double %24 to float
%26 = tail call double @cos(float %13)
%27 = tail call double @sin(float %16)
%28 = tail call double @cos(float %7)
%29 = tail call double @sin(float %10)
%30 = fneg double %28
%31 = fmul double %29, %30
%32 = tail call double @llvm.fmuladd.f64(double %26, double %27, double %31)
%33 = fmul double %32, 6.371230e+06
%34 = fptrunc double %33 to float
%35 = tail call double @sin(float %13)
%36 = tail call double @sin(float %7)
%37 = fsub double %35, %36
%38 = fmul double %37, 6.371230e+06
%39 = fptrunc double %38 to float
%40 = fmul float %34, %34
%41 = tail call float @llvm.fmuladd.f32(float %25, float %25, float %40)
%42 = tail call float @llvm.fmuladd.f32(float %39, float %39, float %41)
%43 = tail call float @sqrt(float %42)
%44 = fpext float %43 to double
%45 = fdiv double %44, 0x41684DE780000000
%46 = fcmp olt double %45, 1.000000e-03
br i1 %46, label %52, label %47
47: ; preds = %4
%48 = fptrunc double %45 to float
%49 = tail call double @asin(float %48)
%50 = fmul double %49, 0x41684DE780000000
%51 = fptrunc double %50 to float
br label %52
52: ; preds = %4, %47
%53 = phi float [ %51, %47 ], [ %43, %4 ]
ret float %53
}