#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) {
  const double earthR = 6371000;
  double x = cos(latA * M_PI / 180) * cos(latB * M_PI / 180) *
             cos((lngA - lngB) * M_PI / 180);
  double y = sin(latA * M_PI / 180) * sin(latB * M_PI / 180);
  double s = x + y;
  if (s > 1) {
    s = 1;
  }
  if (s < -1) {
    s = -1;
  }
  double alpha = acos(s);
  double distance = alpha * earthR;
  return distance;
}


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
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e83(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe97(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2e5d(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe71(%rip),%xmm1
divsd  %xmm1,%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    0x2e26(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe3a(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2df4(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xe08(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    0x2dce(%rip),%rax
mulsd  (%rax),%xmm0
movsd  0xde2(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xda4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1273 <distance+0x143>
movsd  0xd92(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd9d(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    1293 <distance+0x163>
movsd  0xd8a(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  0xd66(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

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

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 = tail call double @cos(double %7)
%9 = load double, double* @M_PI
%10 = fmul double %9, %2
%11 = fdiv double %10, 1.800000e+02
%12 = tail call double @cos(double %11)
%13 = fmul double %8, %12
%14 = fsub double %1, %3
%15 = load double, double* @M_PI
%16 = fmul double %14, %15
%17 = fdiv double %16, 1.800000e+02
%18 = tail call double @cos(double %17)
%19 = fmul double %13, %18
%20 = load double, double* @M_PI
%21 = fmul double %20, %0
%22 = fdiv double %21, 1.800000e+02
%23 = tail call double @sin(double %22)
%24 = load double, double* @M_PI
%25 = fmul double %24, %2
%26 = fdiv double %25, 1.800000e+02
%27 = tail call double @sin(double %26)
%28 = fmul double %23, %27
%29 = fadd double %19, %28
%30 = fcmp ogt double %29, 1.000000e+00
%31 = select i1 %30, double 1.000000e+00, double %29
%32 = fcmp olt double %31, -1.000000e+00
%33 = select i1 %32, double -1.000000e+00, double %31
%34 = tail call double @acos(double %33)
%35 = fmul double %34, 6.371000e+06
ret double %35
}