#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 acos(double);
double cos(double);
double sin(double);
double distance(double latA, double lngA, double latB, double lngB) {
  double arcLatA = latA * M_PI / 180;
  double arcLatB = latB * M_PI / 180;
  double x = cos(arcLatA) * cos(arcLatB) * cos((lngA - lngB) * M_PI / 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  -0x8(%rbp),%xmm0
mov    0x2e90(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xea4(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e6f(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe83(%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
mov    0x2e1f(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe33(%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  0xdcb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    124c <distance+0x11c>
movsd  0xdb9(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdbc(%rip),%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    126c <distance+0x13c>
movsd  0xda9(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  0xd95(%rip),%xmm0
mulsd  -0x50(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distance>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm3,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
mov    0x2ea0(%rip),%rbx
movsd  (%rbx),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea8(%rip),%xmm3
divsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
mulsd  %xmm2,%xmm1
divsd  %xmm3,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1050 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
mulsd  (%rbx),%xmm0
divsd  0xe56(%rip),%xmm0
call   1050 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x28(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  0xe1d(%rip),%xmm1
minsd  %xmm0,%xmm1
movsd  0xe19(%rip),%xmm0
maxsd  %xmm1,%xmm0
call   1030 <acos@plt>
mulsd  0xe10(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
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
%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 = load double, double* @M_PI
%17 = fmul double %15, %16
%18 = fdiv double %17, 1.800000e+02
store double %18, double* %9
%19 = load double, double* %7
%20 = load double, double* @M_PI
%21 = fmul double %19, %20
%22 = fdiv double %21, 1.800000e+02
store double %22, double* %10
%23 = load double, double* %9
%24 = call double @cos(double %23)
%25 = load double, double* %10
%26 = call double @cos(double %25)
%27 = fmul double %24, %26
%28 = load double, double* %6
%29 = load double, double* %8
%30 = fsub double %28, %29
%31 = load double, double* @M_PI
%32 = fmul double %30, %31
%33 = fdiv double %32, 1.800000e+02
%34 = call double @cos(double %33)
%35 = fmul double %27, %34
store double %35, double* %11
%36 = load double, double* %9
%37 = call double @sin(double %36)
%38 = load double, double* %10
%39 = call double @sin(double %38)
%40 = fmul double %37, %39
store double %40, double* %12
%41 = load double, double* %11
%42 = load double, double* %12
%43 = fadd double %41, %42
store double %43, double* %13
%44 = load double, double* %13
%45 = fcmp ogt double %44, 1.000000e+00
br i1 %45, label %46, label %47
46: ; preds = %4
store double 1.000000e+00, double* %13
br label %47
47: ; preds = %46, %4
%48 = load double, double* %13
%49 = fcmp olt double %48, -1.000000e+00
br i1 %49, label %50, label %51
50: ; preds = %47
store double -1.000000e+00, double* %13
br label %51
51: ; preds = %50, %47
%52 = load double, double* %13
%53 = call double @acos(double %52)
store double %53, double* %14
%54 = load double, double* %14
%55 = fmul double %54, 0x415854A640000000
ret double %55
}

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