#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(int);
double cos(double);
double sin(double);
int sqrt(double);
double great_circle_distance(double lat1, double lat2, double lon1,
                             double lon2) {
  double a, c, d, dlat, dlon;
  lat1 *= 0.017453293;
  lat2 *= 0.017453293;
  lon1 *= 0.017453293;
  lon2 *= 0.017453293;
  dlat = lat1 - lat2;
  dlon = lon1 - lon2;
  a = (((sin(dlat / 2.0)) * (sin(dlat / 2.0)))) +
      cos(lat1) * cos(lat2) * (((sin(dlon / 2.0))) * ((sin(dlon / 2.0))));
  c = 2.0 * asin(sqrt(a) > 1 ? 1 : sqrt(a));
  d = 3956.0 * c;
  return (d);
}


x86 assembly (clang, -O0):
<great_circle_distance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xea1(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe8f(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe7d(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe6b(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe2e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe13(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xdce(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xdb3(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  -0x68(%rbp),%xmm3
movsd  -0x60(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm2
movaps %xmm0,%xmm4
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <sqrt@plt>
cmp    $0x1,%eax
jle    12a2 <great_circle_distance+0x162>
mov    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    12af <great_circle_distance+0x16f>
movsd  -0x28(%rbp),%xmm0
call   1060 <sqrt@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%edi
call   1040 <asin@plt>
movaps %xmm0,%xmm1
movsd  0xd3e(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xd3d(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<great_circle_distance>:
sub    $0x28,%rsp
movsd  0xeb4(%rip),%xmm4
mulsd  %xmm4,%xmm0
movsd  %xmm0,(%rsp)
mulsd  %xmm4,%xmm1
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm4,%xmm2
mulsd  %xmm4,%xmm3
subsd  %xmm3,%xmm2
movsd  %xmm2,0x18(%rsp)
subsd  %xmm1,%xmm0
mulsd  0xe8b(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <sin@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0xe36(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1030 <sin@plt>
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  (%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    $0x1,%edi
cmp    $0x1,%eax
jg     122e <great_circle_distance+0xee>
movsd  0x8(%rsp),%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1040 <asin@plt>
addsd  %xmm0,%xmm0
mulsd  0xdd1(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @great_circle_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
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%14 = load double, double* %5
%15 = fmul double %14, 0x3F91DF46AA91ED06
store double %15, double* %5
%16 = load double, double* %6
%17 = fmul double %16, 0x3F91DF46AA91ED06
store double %17, double* %6
%18 = load double, double* %7
%19 = fmul double %18, 0x3F91DF46AA91ED06
store double %19, double* %7
%20 = load double, double* %8
%21 = fmul double %20, 0x3F91DF46AA91ED06
store double %21, double* %8
%22 = load double, double* %5
%23 = load double, double* %6
%24 = fsub double %22, %23
store double %24, double* %12
%25 = load double, double* %7
%26 = load double, double* %8
%27 = fsub double %25, %26
store double %27, double* %13
%28 = load double, double* %12
%29 = fdiv double %28, 2.000000e+00
%30 = call double @sin(double %29)
%31 = load double, double* %12
%32 = fdiv double %31, 2.000000e+00
%33 = call double @sin(double %32)
%34 = load double, double* %5
%35 = call double @cos(double %34)
%36 = load double, double* %6
%37 = call double @cos(double %36)
%38 = fmul double %35, %37
%39 = load double, double* %13
%40 = fdiv double %39, 2.000000e+00
%41 = call double @sin(double %40)
%42 = load double, double* %13
%43 = fdiv double %42, 2.000000e+00
%44 = call double @sin(double %43)
%45 = fmul double %41, %44
%46 = fmul double %38, %45
%47 = call double @llvm.fmuladd.f64(double %30, double %33, double %46)
store double %47, double* %9
%48 = load double, double* %9
%49 = call i32 @sqrt(double %48)
%50 = icmp sgt i32 %49, 1
br i1 %50, label %51, label %52
51: ; preds = %4
br label %55
52: ; preds = %4
%53 = load double, double* %9
%54 = call i32 @sqrt(double %53)
br label %55
55: ; preds = %52, %51
%56 = phi i32 [ 1, %51 ], [ %54, %52 ]
%57 = call double @asin(i32 %56)
%58 = fmul double 2.000000e+00, %57
store double %58, double* %10
%59 = load double, double* %10
%60 = fmul double 3.956000e+03, %59
store double %60, double* %11
%61 = load double, double* %11
ret double %61
}

LLVM IR (-O2):
define double @great_circle_distance(double %0, double %1, double %2, double %3) {
%5 = fmul double %0, 0x3F91DF46AA91ED06
%6 = fmul double %1, 0x3F91DF46AA91ED06
%7 = fmul double %2, 0x3F91DF46AA91ED06
%8 = fmul double %3, 0x3F91DF46AA91ED06
%9 = fsub double %5, %6
%10 = fsub double %7, %8
%11 = fmul double %9, 5.000000e-01
%12 = tail call double @sin(double %11)
%13 = tail call double @sin(double %11)
%14 = tail call double @cos(double %5)
%15 = tail call double @cos(double %6)
%16 = fmul double %14, %15
%17 = fmul double %10, 5.000000e-01
%18 = tail call double @sin(double %17)
%19 = tail call double @sin(double %17)
%20 = fmul double %18, %19
%21 = fmul double %16, %20
%22 = tail call double @llvm.fmuladd.f64(double %12, double %13, double %21)
%23 = tail call i32 @sqrt(double %22)
%24 = icmp sgt i32 %23, 1
br i1 %24, label %27, label %25
25: ; preds = %4
%26 = tail call i32 @sqrt(double %22)
br label %27
27: ; preds = %4, %25
%28 = phi i32 [ %26, %25 ], [ 1, %4 ]
%29 = tail call double @asin(i32 %28)
%30 = fmul double %29, 2.000000e+00
%31 = fmul double %30, 3.956000e+03
ret double %31
}