double arc_length(double lat1, double lon1, double lat2, double lon2,
                  double Re) {
  double phi1, lam1, phi2, lam2, beta;
  if (lat1 == lat2 && lon1 == lon2)
    return (double)0;
  phi1 = ((lat1)*3.141592653589793 / 180.0);
  lam1 = ((lon1)*3.141592653589793 / 180.0);
  phi2 = ((lat2)*3.141592653589793 / 180.0);
  lam2 = ((lon2)*3.141592653589793 / 180.0);
  beta = acos(cos(phi1) * cos(phi2) * cos(lam1 - lam2) + sin(phi1) * sin(phi2));
  return (double)(Re * beta);
}


x86 assembly (clang, -O0):
<arc_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    118d <arc_length+0x5d>
jp     118d <arc_length+0x5d>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jne    118d <arc_length+0x5d>
jp     118d <arc_length+0x5d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1293 <arc_length+0x163>
movsd  0xe73(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  0xe5e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe55(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  0xe40(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe37(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xe22(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe19(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xe04(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <sin@plt>
movsd  -0x70(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <acos@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arc_length>:
movapd %xmm0,%xmm5
ucomisd %xmm2,%xmm0
jne    1149 <arc_length+0x19>
jp     1149 <arc_length+0x19>
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm1
jne    1149 <arc_length+0x19>
jp     1149 <arc_length+0x19>
ret
sub    $0x38,%rsp
movsd  0xeab(%rip),%xmm0
mulsd  %xmm0,%xmm5
movapd %xmm5,%xmm6
movsd  0xea3(%rip),%xmm5
divsd  %xmm5,%xmm6
movsd  %xmm6,0x8(%rsp)
mulsd  %xmm0,%xmm2
divsd  %xmm5,%xmm2
movsd  %xmm2,0x18(%rsp)
unpcklpd %xmm3,%xmm1
mulpd  0xe87(%rip),%xmm1
divpd  0xe8f(%rip),%xmm1
movapd %xmm1,0x20(%rsp)
movapd %xmm6,%xmm0
movsd  %xmm4,0x30(%rsp)
call   1050 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movapd 0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm0
call   1030 <acos@plt>
mulsd  0x30(%rsp),%xmm0
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
define double @arc_length(double %0, double %1, double %2, double %3, double %4) {
%6 = fcmp oeq double %0, %2
%7 = fcmp oeq double %1, %3
%8 = and i1 %6, %7
br i1 %8, label %31, label %9
9: ; preds = %5
%10 = fmul double %0, 0x400921FB54442D18
%11 = fdiv double %10, 1.800000e+02
%12 = fmul double %2, 0x400921FB54442D18
%13 = fdiv double %12, 1.800000e+02
%14 = insertelement <2 x double> poison, double %1, i64 0
%15 = insertelement <2 x double> %14, double %3, i64 1
%16 = fmul <2 x double> %15, <double 0x400921FB54442D18, double 0x400921FB54442D18>
%17 = fdiv <2 x double> %16, <double 1.800000e+02, double 1.800000e+02>
%18 = tail call double @cos(double %11)
%19 = tail call double @cos(double %13)
%20 = fmul double %18, %19
%21 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%22 = fsub <2 x double> %17, %21
%23 = extractelement <2 x double> %22, i64 0
%24 = tail call double @cos(double %23)
%25 = tail call double @sin(double %11)
%26 = tail call double @sin(double %13)
%27 = fmul double %25, %26
%28 = tail call double @llvm.fmuladd.f64(double %20, double %24, double %27)
%29 = tail call double @acos(double %28)
%30 = fmul double %29, %4
br label %31
31: ; preds = %5, %9
%32 = phi double [ %30, %9 ], [ 0.000000e+00, %5 ]
ret double %32
}