#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 sin(double);
double distance(double latA, double lngA, double latB, double lngB) {
  double arcLatA = latA * 3.141592653589793238462643 / 180;
  double arcLatB = latB * 3.141592653589793238462643 / 180;
  double x = cos(arcLatA) * cos(arcLatB) *
             cos((lngA - lngB) * 3.141592653589793238462643 / 180);
  double y = sin(arcLatA) * sin(arcLatB);
  double s = x + y;
  if (s > 1) {
    s = 1;
  }
  if (s < -1) {
    s = -1;
  }
  double alpha = acos(s);
  return alpha * 6378137.0;
}


x86 assembly (clang, -O0):
<distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xebc(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  0xea7(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe9e(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xe89(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xe4c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe38(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xdd0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1247 <distance+0x117>
movsd  0xdbe(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdc9(%rip),%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1267 <distance+0x137>
movsd  0xdb6(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  0xda2(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
sub    $0x28,%rsp
movsd  %xmm3,0x10(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  0xeb8(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xeb4(%rip),%xmm3
divsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm1,%xmm2
divsd  %xmm3,%xmm2
movsd  %xmm2,0x18(%rsp)
call   1050 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x20(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
mulsd  0xe61(%rip),%xmm0
divsd  0xe61(%rip),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  0xe29(%rip),%xmm1
minsd  %xmm0,%xmm1
movsd  0xe25(%rip),%xmm0
maxsd  %xmm1,%xmm0
call   1030 <acos@plt>
mulsd  0xe1c(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
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
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%15 = load double, double* %5
%16 = fmul double %15, 0x400921FB54442D18
%17 = fdiv double %16, 1.800000e+02
store double %17, double* %9
%18 = load double, double* %7
%19 = fmul double %18, 0x400921FB54442D18
%20 = fdiv double %19, 1.800000e+02
store double %20, double* %10
%21 = load double, double* %9
%22 = call double @cos(double %21)
%23 = load double, double* %10
%24 = call double @cos(double %23)
%25 = fmul double %22, %24
%26 = load double, double* %6
%27 = load double, double* %8
%28 = fsub double %26, %27
%29 = fmul double %28, 0x400921FB54442D18
%30 = fdiv double %29, 1.800000e+02
%31 = call double @cos(double %30)
%32 = fmul double %25, %31
store double %32, double* %11
%33 = load double, double* %9
%34 = call double @sin(double %33)
%35 = load double, double* %10
%36 = call double @sin(double %35)
%37 = fmul double %34, %36
store double %37, double* %12
%38 = load double, double* %11
%39 = load double, double* %12
%40 = fadd double %38, %39
store double %40, double* %13
%41 = load double, double* %13
%42 = fcmp ogt double %41, 1.000000e+00
br i1 %42, label %43, label %44
43: ; preds = %4
store double 1.000000e+00, double* %13
br label %44
44: ; preds = %43, %4
%45 = load double, double* %13
%46 = fcmp olt double %45, -1.000000e+00
br i1 %46, label %47, label %48
47: ; preds = %44
store double -1.000000e+00, double* %13
br label %48
48: ; preds = %47, %44
%49 = load double, double* %13
%50 = call double @acos(double %49)
store double %50, double* %14
%51 = load double, double* %14
%52 = fmul double %51, 0x415854A640000000
ret double %52
}

LLVM IR (-O2):
define double @distance(double %0, double %1, double %2, double %3) {
%5 = fmul double %0, 0x400921FB54442D18
%6 = fdiv double %5, 1.800000e+02
%7 = fmul double %2, 0x400921FB54442D18
%8 = fdiv double %7, 1.800000e+02
%9 = tail call double @cos(double %6)
%10 = tail call double @cos(double %8)
%11 = fmul double %9, %10
%12 = fsub double %1, %3
%13 = fmul double %12, 0x400921FB54442D18
%14 = fdiv double %13, 1.800000e+02
%15 = tail call double @cos(double %14)
%16 = fmul double %11, %15
%17 = tail call double @sin(double %6)
%18 = tail call double @sin(double %8)
%19 = fmul double %17, %18
%20 = fadd double %16, %19
%21 = fcmp ogt double %20, 1.000000e+00
%22 = select i1 %21, double 1.000000e+00, double %20
%23 = fcmp olt double %22, -1.000000e+00
%24 = select i1 %23, double -1.000000e+00, double %22
%25 = tail call double @acos(double %24)
%26 = fmul double %25, 0x415854A640000000
ret double %26
}