double XoLength(v)
float *v;
{
  double r = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
  if (r > 0)
    return (sqrt(r));
  return (0.0);
}


x86 assembly (clang, -O0):
<XoLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulss  0x4(%rax),%xmm0
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    118f <XoLength+0x7f>
movsd  -0x18(%rbp),%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1197 <XoLength+0x87>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XoLength>:
movss  (%rdi),%xmm0
movss  0x4(%rdi),%xmm1
mulss  %xmm1,%xmm1
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
movss  0x8(%rdi),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
ucomiss %xmm2,%xmm1
jbe    1151 <XoLength+0x41>
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1152 <XoLength+0x42>
sqrtsd %xmm0,%xmm0
ret
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
define double @XoLength(float* %0) {
%2 = alloca double
%3 = alloca float*
%4 = alloca double
store float* %0, float** %3
%5 = load float*, float** %3
%6 = getelementptr inbounds float, float* %5, i64 0
%7 = load float, float* %6
%8 = load float*, float** %3
%9 = getelementptr inbounds float, float* %8, i64 0
%10 = load float, float* %9
%11 = load float*, float** %3
%12 = getelementptr inbounds float, float* %11, i64 1
%13 = load float, float* %12
%14 = load float*, float** %3
%15 = getelementptr inbounds float, float* %14, i64 1
%16 = load float, float* %15
%17 = fmul float %13, %16
%18 = call float @llvm.fmuladd.f32(float %7, float %10, float %17)
%19 = load float*, float** %3
%20 = getelementptr inbounds float, float* %19, i64 2
%21 = load float, float* %20
%22 = load float*, float** %3
%23 = getelementptr inbounds float, float* %22, i64 2
%24 = load float, float* %23
%25 = call float @llvm.fmuladd.f32(float %21, float %24, float %18)
%26 = fpext float %25 to double
store double %26, double* %4
%27 = load double, double* %4
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %32
29: ; preds = %1
%30 = load double, double* %4
%31 = call double @sqrt(double %30)
store double %31, double* %2
br label %33
32: ; preds = %1
store double 0.000000e+00, double* %2
br label %33
33: ; preds = %32, %29
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
define double @XoLength(float* nocapture %0) {
%2 = load float, float* %0
%3 = getelementptr inbounds float, float* %0, i64 1
%4 = load float, float* %3
%5 = fmul float %4, %4
%6 = tail call float @llvm.fmuladd.f32(float %2, float %2, float %5)
%7 = getelementptr inbounds float, float* %0, i64 2
%8 = load float, float* %7
%9 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %6)
%10 = fcmp ogt float %9, 0.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = fpext float %9 to double
%13 = tail call double @sqrt(double %12)
br label %14
14: ; preds = %1, %11
%15 = phi double [ %13, %11 ], [ 0.000000e+00, %1 ]
ret double %15
}