void mat_mult_2d(double *out, double *a, double *b) {
  double lt, rt, lb, rb;
  lt = a[0] * b[0] + a[1] * b[2];
  rt = a[0] * b[1] + a[1] * b[3];
  lb = a[2] * b[0] + a[3] * b[2];
  rb = a[2] * b[1] + a[3] * b[3];
  *out++ = lt;
  *out++ = rt;
  *out++ = lb;
  *out = rb;
}


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

x86 assembly (clang, -O2):
<mat_mult_2d>:
movupd (%rdx),%xmm0
movupd 0x10(%rdx),%xmm1
movsd  (%rsi),%xmm2
movsd  0x8(%rsi),%xmm3
movsd  0x10(%rsi),%xmm4
movsd  0x18(%rsi),%xmm5
unpcklpd %xmm3,%xmm3
mulpd  %xmm1,%xmm3
unpcklpd %xmm2,%xmm2
mulpd  %xmm0,%xmm2
addpd  %xmm3,%xmm2
unpcklpd %xmm5,%xmm5
mulpd  %xmm1,%xmm5
unpcklpd %xmm4,%xmm4
mulpd  %xmm0,%xmm4
addpd  %xmm5,%xmm4
movupd %xmm2,(%rdi)
movupd %xmm4,0x10(%rdi)
ret

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

LLVM IR (-O2):
define void @mat_mult_2d(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2) {
%4 = load double, double* %1
%5 = getelementptr inbounds double, double* %1, i64 1
%6 = load double, double* %5
%7 = getelementptr inbounds double, double* %2, i64 2
%8 = bitcast double* %2 to <2 x double>*
%9 = load <2 x double>, <2 x double>* %8
%10 = bitcast double* %7 to <2 x double>*
%11 = load <2 x double>, <2 x double>* %10
%12 = insertelement <2 x double> poison, double %6, i64 0
%13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> zeroinitializer
%14 = fmul <2 x double> %13, %11
%15 = insertelement <2 x double> poison, double %4, i64 0
%16 = shufflevector <2 x double> %15, <2 x double> poison, <2 x i32> zeroinitializer
%17 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %16, <2 x double> %9, <2 x double> %14)
%18 = getelementptr inbounds double, double* %1, i64 2
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 3
%21 = load double, double* %20
%22 = insertelement <2 x double> poison, double %21, i64 0
%23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
%24 = fmul <2 x double> %11, %23
%25 = insertelement <2 x double> poison, double %19, i64 0
%26 = shufflevector <2 x double> %25, <2 x double> poison, <2 x i32> zeroinitializer
%27 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %9, <2 x double> %24)
%28 = getelementptr inbounds double, double* %0, i64 2
%29 = bitcast double* %0 to <2 x double>*
store <2 x double> %17, <2 x double>* %29
%30 = bitcast double* %28 to <2 x double>*
store <2 x double> %27, <2 x double>* %30
ret void
}