void projectOnLine(const double *p, const double *q, double *v) {
  double pq[3];
  double tmp;
  pq[0] = p[0] - q[0];
  pq[1] = p[1] - q[1];
  pq[2] = p[2] - q[2];
  tmp = (p[0] * pq[0] + p[1] * pq[1] + p[2] * pq[2]) /
        (pq[0] * pq[0] + pq[1] * pq[1] + pq[2] * pq[2]);
  for (int i = 0; i < 3; i++)
    v[i] = p[i] - pq[i] * tmp;
}


x86 assembly (clang, -O0):
<projectOnLine>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x30(%rbp),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    122a <projectOnLine+0x12a>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movslq -0x3c(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm0
movsd  -0x38(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ca <projectOnLine+0xca>
pop    %rbp
ret

x86 assembly (clang, -O2):
<projectOnLine>:
movsd  (%rdi),%xmm3
movapd %xmm3,%xmm4
subsd  (%rsi),%xmm4
movsd  0x8(%rdi),%xmm5
movapd %xmm5,%xmm2
subsd  0x8(%rsi),%xmm2
movsd  0x10(%rdi),%xmm0
movapd %xmm0,%xmm1
subsd  0x10(%rsi),%xmm1
mulsd  %xmm2,%xmm5
movapd %xmm3,%xmm6
mulsd  %xmm4,%xmm6
addsd  %xmm5,%xmm6
mulsd  %xmm1,%xmm0
addsd  %xmm6,%xmm0
movapd %xmm2,%xmm5
mulsd  %xmm2,%xmm5
movapd %xmm4,%xmm6
mulsd  %xmm4,%xmm6
addsd  %xmm5,%xmm6
movapd %xmm1,%xmm5
mulsd  %xmm1,%xmm5
addsd  %xmm6,%xmm5
divsd  %xmm5,%xmm0
mulsd  %xmm0,%xmm4
subsd  %xmm4,%xmm3
movsd  %xmm3,(%rdx)
movsd  0x8(%rdi),%xmm3
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rdx)
movsd  0x10(%rdi),%xmm2
mulsd  %xmm1,%xmm0
subsd  %xmm0,%xmm2
movsd  %xmm2,0x10(%rdx)
ret

LLVM IR (-O0):
define void @projectOnLine(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca [3 x double]
%8 = alloca double
%9 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%10 = load double*, double** %4
%11 = getelementptr inbounds double, double* %10, i64 0
%12 = load double, double* %11
%13 = load double*, double** %5
%14 = getelementptr inbounds double, double* %13, i64 0
%15 = load double, double* %14
%16 = fsub double %12, %15
%17 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
store double %16, double* %17
%18 = load double*, double** %4
%19 = getelementptr inbounds double, double* %18, i64 1
%20 = load double, double* %19
%21 = load double*, double** %5
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load double, double* %22
%24 = fsub double %20, %23
%25 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 1
store double %24, double* %25
%26 = load double*, double** %4
%27 = getelementptr inbounds double, double* %26, i64 2
%28 = load double, double* %27
%29 = load double*, double** %5
%30 = getelementptr inbounds double, double* %29, i64 2
%31 = load double, double* %30
%32 = fsub double %28, %31
%33 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
store double %32, double* %33
%34 = load double*, double** %4
%35 = getelementptr inbounds double, double* %34, i64 0
%36 = load double, double* %35
%37 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%38 = load double, double* %37
%39 = load double*, double** %4
%40 = getelementptr inbounds double, double* %39, i64 1
%41 = load double, double* %40
%42 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 1
%43 = load double, double* %42
%44 = fmul double %41, %43
%45 = call double @llvm.fmuladd.f64(double %36, double %38, double %44)
%46 = load double*, double** %4
%47 = getelementptr inbounds double, double* %46, i64 2
%48 = load double, double* %47
%49 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
%50 = load double, double* %49
%51 = call double @llvm.fmuladd.f64(double %48, double %50, double %45)
%52 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%53 = load double, double* %52
%54 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 0
%55 = load double, double* %54
%56 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 1
%57 = load double, double* %56
%58 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 1
%59 = load double, double* %58
%60 = fmul double %57, %59
%61 = call double @llvm.fmuladd.f64(double %53, double %55, double %60)
%62 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
%63 = load double, double* %62
%64 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 2
%65 = load double, double* %64
%66 = call double @llvm.fmuladd.f64(double %63, double %65, double %61)
%67 = fdiv double %51, %66
store double %67, double* %8
store i32 0, i32* %9
br label %68
68: ; preds = %88, %3
%69 = load i32, i32* %9
%70 = icmp slt i32 %69, 3
br i1 %70, label %71, label %91
71: ; preds = %68
%72 = load double*, double** %4
%73 = load i32, i32* %9
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
%76 = load double, double* %75
%77 = load i32, i32* %9
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [3 x double], [3 x double]* %7, i64 0, i64 %78
%80 = load double, double* %79
%81 = load double, double* %8
%82 = fneg double %80
%83 = call double @llvm.fmuladd.f64(double %82, double %81, double %76)
%84 = load double*, double** %6
%85 = load i32, i32* %9
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %84, i64 %86
store double %83, double* %87
br label %88
88: ; preds = %71
%89 = load i32, i32* %9
%90 = add nsw i32 %89, 1
store i32 %90, i32* %9
br label %68
91: ; preds = %68
ret void
}

LLVM IR (-O2):
define void @projectOnLine(double* nocapture %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = load double, double* %0
%5 = load double, double* %1
%6 = fsub double %4, %5
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %1, i64 1
%10 = load double, double* %9
%11 = fsub double %8, %10
%12 = getelementptr inbounds double, double* %0, i64 2
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %1, i64 2
%15 = load double, double* %14
%16 = fsub double %13, %15
%17 = fmul double %8, %11
%18 = tail call double @llvm.fmuladd.f64(double %4, double %6, double %17)
%19 = tail call double @llvm.fmuladd.f64(double %13, double %16, double %18)
%20 = fmul double %11, %11
%21 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %20)
%22 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %21)
%23 = fdiv double %19, %22
%24 = fneg double %6
%25 = tail call double @llvm.fmuladd.f64(double %24, double %23, double %4)
store double %25, double* %2
%26 = load double, double* %7
%27 = fneg double %11
%28 = tail call double @llvm.fmuladd.f64(double %27, double %23, double %26)
%29 = getelementptr inbounds double, double* %2, i64 1
store double %28, double* %29
%30 = load double, double* %12
%31 = fneg double %16
%32 = tail call double @llvm.fmuladd.f64(double %31, double %23, double %30)
%33 = getelementptr inbounds double, double* %2, i64 2
store double %32, double* %33
ret void
}