double wcsdist(x1, y1, x2, y2)
double x1, y1;
double x2, y2;
{
  double r, diffi;
  double pos1[3], pos2[3], w, diff;
  int i;
  r = 1.0;
  d2v3(x1, y1, r, pos1);
  d2v3(x2, y2, r, pos2);
  w = 0.0;
  for (i = 0; i < 3; i++) {
    diffi = pos1[i] - pos2[i];
    w = w + (diffi * diffi);
  }
  w = w / 4.0;
  if (w > 1.0)
    w = 1.0;
  diff = 2.0 * atan2(sqrt(w), sqrt(1.0 - w));
  diff = raddeg(diff);
  return (diff);
}


x86 assembly (clang, -O0):
<wcsdist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    -0x50(%rbp),%rdi
mov    $0x3,%al
call   1050 <d2v3@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    -0x70(%rbp),%rdi
mov    $0x3,%al
call   1050 <d2v3@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movl   $0x0,-0x84(%rbp)
cmpl   $0x3,-0x84(%rbp)
jge    120e <wcsdist+0xce>
movslq -0x84(%rbp),%rax
movsd  -0x50(%rbp,%rax,8),%xmm0
movslq -0x84(%rbp),%rax
subsd  -0x70(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x78(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11b2 <wcsdist+0x72>
movsd  -0x78(%rbp),%xmm0
movsd  0xded(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  0xdcf(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1248 <wcsdist+0x108>
movsd  0xdbd(%rip),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  0xd9e(%rip),%xmm0
subsd  -0x78(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
call   1030 <atan2@plt>
movaps %xmm0,%xmm1
movsd  0xd89(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
mov    $0x1,%al
call   1040 <raddeg@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsdist>:
sub    $0x48,%rsp
movsd  %xmm3,(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  0xea9(%rip),%xmm2
lea    0x30(%rsp),%rdi
mov    $0x3,%al
call   1050 <d2v3@plt>
lea    0x10(%rsp),%rdi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0xe85(%rip),%xmm2
mov    $0x3,%al
call   1050 <d2v3@plt>
movsd  0xe76(%rip),%xmm2
movsd  0x30(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
subsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm0
xorpd  %xmm3,%xmm3
addsd  %xmm3,%xmm0
subsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x40(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xe36(%rip),%xmm0
movapd %xmm2,%xmm1
minsd  %xmm0,%xmm1
ucomisd %xmm3,%xmm1
jb     11e9 <wcsdist+0xa9>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    1208 <wcsdist+0xc8>
movapd %xmm1,%xmm0
movsd  %xmm1,(%rsp)
call   1060 <sqrt@plt>
movsd  (%rsp),%xmm1
xorpd  %xmm3,%xmm3
movsd  0xdf8(%rip),%xmm2
subsd  %xmm1,%xmm2
ucomisd %xmm3,%xmm2
jb     121b <wcsdist+0xdb>
xorps  %xmm1,%xmm1
sqrtsd %xmm2,%xmm1
jmp    1232 <wcsdist+0xf2>
movsd  %xmm0,(%rsp)
movapd %xmm2,%xmm0
call   1060 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm0
call   1030 <atan2@plt>
addsd  %xmm0,%xmm0
mov    $0x1,%al
call   1040 <raddeg@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x48,%rsp
ret

LLVM IR (-O0):
define double @wcsdist(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 [3 x double]
%12 = alloca [3 x double]
%13 = alloca double
%14 = alloca double
%15 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
store double 1.000000e+00, double* %9
%16 = load double, double* %5
%17 = load double, double* %6
%18 = load double, double* %9
%19 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 0
%20 = call i32 (double, double, double, double*, ...) bitcast (i32 (...)* @d2v3 to i32 (double, double, double, double*, ...)*)(double %16, double %17, double %18, double* %19)
%21 = load double, double* %7
%22 = load double, double* %8
%23 = load double, double* %9
%24 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 0
%25 = call i32 (double, double, double, double*, ...) bitcast (i32 (...)* @d2v3 to i32 (double, double, double, double*, ...)*)(double %21, double %22, double %23, double* %24)
store double 0.000000e+00, double* %13
store i32 0, i32* %15
br label %26
26: ; preds = %43, %4
%27 = load i32, i32* %15
%28 = icmp slt i32 %27, 3
br i1 %28, label %29, label %46
29: ; preds = %26
%30 = load i32, i32* %15
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [3 x double], [3 x double]* %11, i64 0, i64 %31
%33 = load double, double* %32
%34 = load i32, i32* %15
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [3 x double], [3 x double]* %12, i64 0, i64 %35
%37 = load double, double* %36
%38 = fsub double %33, %37
store double %38, double* %10
%39 = load double, double* %13
%40 = load double, double* %10
%41 = load double, double* %10
%42 = call double @llvm.fmuladd.f64(double %40, double %41, double %39)
store double %42, double* %13
br label %43
43: ; preds = %29
%44 = load i32, i32* %15
%45 = add nsw i32 %44, 1
store i32 %45, i32* %15
br label %26
46: ; preds = %26
%47 = load double, double* %13
%48 = fdiv double %47, 4.000000e+00
store double %48, double* %13
%49 = load double, double* %13
%50 = fcmp ogt double %49, 1.000000e+00
br i1 %50, label %51, label %52
51: ; preds = %46
store double 1.000000e+00, double* %13
br label %52
52: ; preds = %51, %46
%53 = load double, double* %13
%54 = call double @sqrt(double %53)
%55 = load double, double* %13
%56 = fsub double 1.000000e+00, %55
%57 = call double @sqrt(double %56)
%58 = call double @atan2(double %54, double %57)
%59 = fmul double 2.000000e+00, %58
store double %59, double* %14
%60 = load double, double* %14
%61 = call i32 (double, ...) bitcast (i32 (...)* @raddeg to i32 (double, ...)*)(double %60)
%62 = sitofp i32 %61 to double
store double %62, double* %14
%63 = load double, double* %14
ret double %63
}

LLVM IR (-O2):
define double @wcsdist(double %0, double %1, double %2, double %3) {
%5 = alloca [3 x double]
%6 = alloca [3 x double]
%7 = bitcast [3 x double]* %5 to i8*
%8 = bitcast [3 x double]* %6 to i8*
%9 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%10 = call i32 (double, double, double, double*, ...) bitcast (i32 (...)* @d2v3 to i32 (double, double, double, double*, ...)*)(double %0, double %1, double 1.000000e+00, double* %9)
%11 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%12 = call i32 (double, double, double, double*, ...) bitcast (i32 (...)* @d2v3 to i32 (double, double, double, double*, ...)*)(double %2, double %3, double 1.000000e+00, double* %11)
%13 = load double, double* %9
%14 = load double, double* %11
%15 = fsub double %13, %14
%16 = call double @llvm.fmuladd.f64(double %15, double %15, double 0.000000e+00)
%17 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 1
%18 = load double, double* %17
%19 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 1
%20 = load double, double* %19
%21 = fsub double %18, %20
%22 = call double @llvm.fmuladd.f64(double %21, double %21, double %16)
%23 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
%24 = load double, double* %23
%25 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 2
%26 = load double, double* %25
%27 = fsub double %24, %26
%28 = call double @llvm.fmuladd.f64(double %27, double %27, double %22)
%29 = fmul double %28, 2.500000e-01
%30 = fcmp ogt double %29, 1.000000e+00
%31 = select i1 %30, double 1.000000e+00, double %29
%32 = call double @sqrt(double %31)
%33 = fsub double 1.000000e+00, %31
%34 = call double @sqrt(double %33)
%35 = call double @atan2(double %32, double %34)
%36 = fmul double %35, 2.000000e+00
%37 = call i32 (double, ...) bitcast (i32 (...)* @raddeg to i32 (double, ...)*)(double %36)
%38 = sitofp i32 %37 to double
ret double %38
}