void vec_mmult_3d(double *out, double *mat, double *v) {
  *(out++) = v[0] * mat[0] + v[1] * mat[3] + v[2] * mat[6];
  *(out++) = v[0] * mat[1] + v[1] * mat[4] + v[2] * mat[7];
  *(out) = v[0] * mat[2] + v[1] * mat[5] + v[2] * mat[8];
}


x86 assembly (clang, -O0):
<vec_mmult_3d>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x18(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x30(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x20(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x38(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm2
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
mulsd  0x28(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x40(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_mmult_3d>:
movsd  (%rdx),%xmm0
movsd  0x8(%rdx),%xmm1
mulsd  0x18(%rsi),%xmm1
mulsd  (%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x10(%rdx),%xmm1
mulsd  0x30(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi)
movsd  (%rdx),%xmm0
movsd  0x8(%rdx),%xmm1
mulsd  0x20(%rsi),%xmm1
mulsd  0x8(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x10(%rdx),%xmm1
mulsd  0x38(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rdi)
movsd  (%rdx),%xmm0
movsd  0x8(%rdx),%xmm1
mulsd  0x28(%rsi),%xmm1
mulsd  0x10(%rsi),%xmm0
addsd  %xmm1,%xmm0
movsd  0x10(%rdx),%xmm1
mulsd  0x40(%rsi),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rdi)
ret

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

LLVM IR (-O2):
define void @vec_mmult_3d(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2) {
%4 = load double, double* %2
%5 = load double, double* %1
%6 = getelementptr inbounds double, double* %2, i64 1
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %1, i64 3
%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* %2, i64 2
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %1, i64 6
%15 = load double, double* %14
%16 = tail call double @llvm.fmuladd.f64(double %13, double %15, double %11)
%17 = getelementptr inbounds double, double* %0, i64 1
store double %16, double* %0
%18 = load double, double* %2
%19 = getelementptr inbounds double, double* %1, i64 1
%20 = load double, double* %19
%21 = load double, double* %6
%22 = getelementptr inbounds double, double* %1, i64 4
%23 = load double, double* %22
%24 = fmul double %21, %23
%25 = tail call double @llvm.fmuladd.f64(double %18, double %20, double %24)
%26 = load double, double* %12
%27 = getelementptr inbounds double, double* %1, i64 7
%28 = load double, double* %27
%29 = tail call double @llvm.fmuladd.f64(double %26, double %28, double %25)
%30 = getelementptr inbounds double, double* %0, i64 2
store double %29, double* %17
%31 = load double, double* %2
%32 = getelementptr inbounds double, double* %1, i64 2
%33 = load double, double* %32
%34 = load double, double* %6
%35 = getelementptr inbounds double, double* %1, i64 5
%36 = load double, double* %35
%37 = fmul double %34, %36
%38 = tail call double @llvm.fmuladd.f64(double %31, double %33, double %37)
%39 = load double, double* %12
%40 = getelementptr inbounds double, double* %1, i64 8
%41 = load double, double* %40
%42 = tail call double @llvm.fmuladd.f64(double %39, double %41, double %38)
store double %42, double* %30
ret void
}