void remove_component3d(double *v1, double *unit, double *result) {
  double dot;
  dot = v1[0] * unit[0] + v1[1] * unit[1] + v1[2] * unit[2];
  result[0] = v1[0] - unit[0] * dot;
  result[1] = v1[1] - unit[1] * dot;
  result[2] = v1[2] - unit[2] * dot;
}


x86 assembly (clang, -O0):
<remove_component3d>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x20(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  -0x20(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  -0x20(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
pop    %rbp
ret

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

LLVM IR (-O0):
define void @remove_component3d(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%8 = load double*, double** %4
%9 = getelementptr inbounds double, double* %8, i64 0
%10 = load double, double* %9
%11 = load double*, double** %5
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = load double*, double** %4
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = load double*, double** %5
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = fmul double %16, %19
%21 = call double @llvm.fmuladd.f64(double %10, double %13, double %20)
%22 = load double*, double** %4
%23 = getelementptr inbounds double, double* %22, i64 2
%24 = load double, double* %23
%25 = load double*, double** %5
%26 = getelementptr inbounds double, double* %25, i64 2
%27 = load double, double* %26
%28 = call double @llvm.fmuladd.f64(double %24, double %27, double %21)
store double %28, double* %7
%29 = load double*, double** %4
%30 = getelementptr inbounds double, double* %29, i64 0
%31 = load double, double* %30
%32 = load double*, double** %5
%33 = getelementptr inbounds double, double* %32, i64 0
%34 = load double, double* %33
%35 = load double, double* %7
%36 = fneg double %34
%37 = call double @llvm.fmuladd.f64(double %36, double %35, double %31)
%38 = load double*, double** %6
%39 = getelementptr inbounds double, double* %38, i64 0
store double %37, double* %39
%40 = load double*, double** %4
%41 = getelementptr inbounds double, double* %40, i64 1
%42 = load double, double* %41
%43 = load double*, double** %5
%44 = getelementptr inbounds double, double* %43, i64 1
%45 = load double, double* %44
%46 = load double, double* %7
%47 = fneg double %45
%48 = call double @llvm.fmuladd.f64(double %47, double %46, double %42)
%49 = load double*, double** %6
%50 = getelementptr inbounds double, double* %49, i64 1
store double %48, double* %50
%51 = load double*, double** %4
%52 = getelementptr inbounds double, double* %51, i64 2
%53 = load double, double* %52
%54 = load double*, double** %5
%55 = getelementptr inbounds double, double* %54, i64 2
%56 = load double, double* %55
%57 = load double, double* %7
%58 = fneg double %56
%59 = call double @llvm.fmuladd.f64(double %58, double %57, double %53)
%60 = load double*, double** %6
%61 = getelementptr inbounds double, double* %60, i64 2
store double %59, double* %61
ret void
}

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