#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 */
scalar_t__ EDOM;
double asin(double);
double cos(double);
scalar_t__ errno;
double sin(double);
double sqrt(double);
double gcdist(double lat1, double lon1, double lat2, double lon2) {
  double res;
  double sdlat, sdlon;
  errno = 0;
  sdlat = sin((lat1 - lat2) / 2.0);
  sdlon = sin((lon1 - lon2) / 2.0);
  res = sqrt(sdlat * sdlat + cos(lat1) * cos(lat2) * sdlon * sdlon);
  if (res > 1.0) {
    res = 1.0;
  } else if (res < -1.0) {
    res = -1.0;
  }
  res = asin(res);
  if ((errno == EDOM)) {
    errno = 0;
    return 0;
  }
  return 2.0 * res;
}


x86 assembly (clang, -O0):
<gcdist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
mov    0x2e75(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  0xe6c(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <cos@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdea(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1232 <gcdist+0xf2>
movsd  0xdd8(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1257 <gcdist+0x117>
movsd  0xdd6(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1252 <gcdist+0x112>
movsd  0xdc3(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1257 <gcdist+0x117>
movsd  -0x30(%rbp),%xmm0
call   1040 <asin@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%rax
mov    0x2d71(%rip),%rcx
cmp    (%rcx),%rax
jne    129b <gcdist+0x15b>
mov    0x2d51(%rip),%rax
movq   $0x0,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ad <gcdist+0x16d>
movsd  0xd65(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcdist>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    0x2e74(%rip),%rbx
movq   $0x0,(%rbx)
subsd  %xmm2,%xmm0
mulsd  0xe89(%rip),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x18(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
mulsd  0xe6a(%rip),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movsd  0x28(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jb     11f3 <gcdist+0xb3>
sqrtsd %xmm0,%xmm0
jmp    11f8 <gcdist+0xb8>
call   1060 <sqrt@plt>
movsd  0xe08(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     121c <gcdist+0xdc>
movsd  0xe02(%rip),%xmm2
ucomisd %xmm0,%xmm2
movapd %xmm0,%xmm1
jbe    121c <gcdist+0xdc>
movapd %xmm2,%xmm1
movapd %xmm1,%xmm0
call   1040 <asin@plt>
mov    (%rbx),%rax
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%rax
jne    1241 <gcdist+0x101>
movq   $0x0,(%rbx)
xorpd  %xmm0,%xmm0
jmp    1245 <gcdist+0x105>
addsd  %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@EDOM = global i64 0
define double @gcdist(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
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store i64 0, i64* @errno
%13 = load double, double* %6
%14 = load double, double* %8
%15 = fsub double %13, %14
%16 = fdiv double %15, 2.000000e+00
%17 = call double @sin(double %16)
store double %17, double* %11
%18 = load double, double* %7
%19 = load double, double* %9
%20 = fsub double %18, %19
%21 = fdiv double %20, 2.000000e+00
%22 = call double @sin(double %21)
store double %22, double* %12
%23 = load double, double* %11
%24 = load double, double* %11
%25 = load double, double* %6
%26 = call double @cos(double %25)
%27 = load double, double* %8
%28 = call double @cos(double %27)
%29 = fmul double %26, %28
%30 = load double, double* %12
%31 = fmul double %29, %30
%32 = load double, double* %12
%33 = fmul double %31, %32
%34 = call double @llvm.fmuladd.f64(double %23, double %24, double %33)
%35 = call double @sqrt(double %34)
store double %35, double* %10
%36 = load double, double* %10
%37 = fcmp ogt double %36, 1.000000e+00
br i1 %37, label %38, label %39
38: ; preds = %4
store double 1.000000e+00, double* %10
br label %44
39: ; preds = %4
%40 = load double, double* %10
%41 = fcmp olt double %40, -1.000000e+00
br i1 %41, label %42, label %43
42: ; preds = %39
store double -1.000000e+00, double* %10
br label %43
43: ; preds = %42, %39
br label %44
44: ; preds = %43, %38
%45 = load double, double* %10
%46 = call double @asin(double %45)
store double %46, double* %10
%47 = load i64, i64* @errno
%48 = load i64, i64* @EDOM
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %44
store i64 0, i64* @errno
store double 0.000000e+00, double* %5
br label %54
51: ; preds = %44
%52 = load double, double* %10
%53 = fmul double 2.000000e+00, %52
store double %53, double* %5
br label %54
54: ; preds = %51, %50
%55 = load double, double* %5
ret double %55
}

LLVM IR (-O2):
@errno = global i64 0
@EDOM = global i64 0
define double @gcdist(double %0, double %1, double %2, double %3) {
store i64 0, i64* @errno
%5 = fsub double %0, %2
%6 = fmul double %5, 5.000000e-01
%7 = tail call double @sin(double %6)
%8 = fsub double %1, %3
%9 = fmul double %8, 5.000000e-01
%10 = tail call double @sin(double %9)
%11 = tail call double @cos(double %0)
%12 = tail call double @cos(double %2)
%13 = fmul double %11, %12
%14 = fmul double %10, %13
%15 = fmul double %10, %14
%16 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %15)
%17 = tail call double @sqrt(double %16)
%18 = fcmp ogt double %17, 1.000000e+00
br i1 %18, label %22, label %19
19: ; preds = %4
%20 = fcmp olt double %17, -1.000000e+00
br i1 %20, label %21, label %22
21: ; preds = %19
br label %22
22: ; preds = %4, %19, %21
%23 = phi double [ -1.000000e+00, %21 ], [ %17, %19 ], [ 1.000000e+00, %4 ]
%24 = tail call double @asin(double %23)
%25 = load i64, i64* @errno
%26 = load i64, i64* @EDOM
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %22
store i64 0, i64* @errno
br label %31
29: ; preds = %22
%30 = fmul double %24, 2.000000e+00
br label %31
31: ; preds = %29, %28
%32 = phi double [ 0.000000e+00, %28 ], [ %30, %29 ]
ret double %32
}