#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 */
int asin(int);
double cos(double);
double sin(double);
int sqrt(double);
double dist(double th1, double ph1, double th2, double ph2) {
  double dx, dy, dz;
  ph1 -= ph2;
  ph1 *= (3.1415926536 / 180), th1 *= (3.1415926536 / 180),
      th2 *= (3.1415926536 / 180);
  dz = sin(th1) - sin(th2);
  dx = cos(ph1) * cos(th1) - cos(th2);
  dy = sin(ph1) * cos(th1);
  return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * 6371;
}


x86 assembly (clang, -O0):
<dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe89(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe77(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe65(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <asin@plt>
shl    $0x1,%eax
imul   $0x18e3,%eax,%eax
cvtsi2sd %eax,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dist>:
sub    $0x38,%rsp
subsd  %xmm3,%xmm1
movsd  0xeb0(%rip),%xmm3
mulsd  %xmm3,%xmm1
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
mulsd  %xmm2,%xmm3
movsd  %xmm3,0x20(%rsp)
call   1030 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x28(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
call   1050 <cos@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x30(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x28(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
call   1040 <asin@plt>
imul   $0x31c6,%eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define double @dist(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
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%12 = load double, double* %8
%13 = load double, double* %6
%14 = fsub double %13, %12
store double %14, double* %6
%15 = load double, double* %6
%16 = fmul double %15, 0x3F91DF46A252DD11
store double %16, double* %6
%17 = load double, double* %5
%18 = fmul double %17, 0x3F91DF46A252DD11
store double %18, double* %5
%19 = load double, double* %7
%20 = fmul double %19, 0x3F91DF46A252DD11
store double %20, double* %7
%21 = load double, double* %5
%22 = call double @sin(double %21)
%23 = load double, double* %7
%24 = call double @sin(double %23)
%25 = fsub double %22, %24
store double %25, double* %11
%26 = load double, double* %6
%27 = call double @cos(double %26)
%28 = load double, double* %5
%29 = call double @cos(double %28)
%30 = load double, double* %7
%31 = call double @cos(double %30)
%32 = fneg double %31
%33 = call double @llvm.fmuladd.f64(double %27, double %29, double %32)
store double %33, double* %9
%34 = load double, double* %6
%35 = call double @sin(double %34)
%36 = load double, double* %5
%37 = call double @cos(double %36)
%38 = fmul double %35, %37
store double %38, double* %10
%39 = load double, double* %9
%40 = load double, double* %9
%41 = load double, double* %10
%42 = load double, double* %10
%43 = fmul double %41, %42
%44 = call double @llvm.fmuladd.f64(double %39, double %40, double %43)
%45 = load double, double* %11
%46 = load double, double* %11
%47 = call double @llvm.fmuladd.f64(double %45, double %46, double %44)
%48 = call i32 @sqrt(double %47)
%49 = sdiv i32 %48, 2
%50 = call i32 @asin(i32 %49)
%51 = mul nsw i32 %50, 2
%52 = mul nsw i32 %51, 6371
%53 = sitofp i32 %52 to double
ret double %53
}

LLVM IR (-O2):
define double @dist(double %0, double %1, double %2, double %3) {
%5 = fsub double %1, %3
%6 = fmul double %5, 0x3F91DF46A252DD11
%7 = fmul double %0, 0x3F91DF46A252DD11
%8 = fmul double %2, 0x3F91DF46A252DD11
%9 = tail call double @sin(double %7)
%10 = tail call double @sin(double %8)
%11 = fsub double %9, %10
%12 = tail call double @cos(double %6)
%13 = tail call double @cos(double %7)
%14 = tail call double @cos(double %8)
%15 = fneg double %14
%16 = tail call double @llvm.fmuladd.f64(double %12, double %13, double %15)
%17 = tail call double @sin(double %6)
%18 = tail call double @cos(double %7)
%19 = fmul double %17, %18
%20 = fmul double %19, %19
%21 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %20)
%22 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %21)
%23 = tail call i32 @sqrt(double %22)
%24 = sdiv i32 %23, 2
%25 = tail call i32 @asin(i32 %24)
%26 = mul nsw i32 %25, 12742
%27 = sitofp i32 %26 to double
ret double %27
}