void mulmm(double *result, const double *s1, const double *s2) {
  int i, j, k;
  for (i = 0; i < 4; i++)
    for (j = 0; j < 4; j++) {
      double dest = 0;
      for (k = 0; k < 4; k++)
        dest += s1[(i + (k << 2))] * s2[(k + (j << 2))];
      result[(i + (j << 2))] = (double)dest;
    }
}


x86 assembly (clang, -O0):
<mulmm>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11d6 <mulmm+0xd6>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    11c3 <mulmm+0xc3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1199 <mulmm+0x99>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <mulmm+0x41>
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1128 <mulmm+0x28>
jmp    11c8 <mulmm+0xc8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <mulmm+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<mulmm>:
mov    $0xfffffffffffffffc,%rax
xorpd  %xmm0,%xmm0
nopl   0x0(%rax,%rax,1)
movsd  0x20(%rsi,%rax,8),%xmm1
movsd  0x40(%rsi,%rax,8),%xmm2
mulsd  (%rdx),%xmm1
addsd  %xmm0,%xmm1
mulsd  0x8(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  0x60(%rsi,%rax,8),%xmm1
mulsd  0x10(%rdx),%xmm1
addsd  %xmm2,%xmm1
movsd  0x80(%rsi,%rax,8),%xmm2
mulsd  0x18(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x20(%rdi,%rax,8)
movsd  0x20(%rsi,%rax,8),%xmm1
movsd  0x40(%rsi,%rax,8),%xmm2
mulsd  0x20(%rdx),%xmm1
addsd  %xmm0,%xmm1
mulsd  0x28(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  0x60(%rsi,%rax,8),%xmm1
mulsd  0x30(%rdx),%xmm1
addsd  %xmm2,%xmm1
movsd  0x80(%rsi,%rax,8),%xmm2
mulsd  0x38(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x40(%rdi,%rax,8)
movsd  0x20(%rsi,%rax,8),%xmm1
mulsd  0x40(%rdx),%xmm1
movsd  0x40(%rsi,%rax,8),%xmm2
addsd  %xmm0,%xmm1
mulsd  0x48(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  0x60(%rsi,%rax,8),%xmm1
mulsd  0x50(%rdx),%xmm1
addsd  %xmm2,%xmm1
movsd  0x80(%rsi,%rax,8),%xmm2
mulsd  0x58(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x60(%rdi,%rax,8)
movsd  0x20(%rsi,%rax,8),%xmm1
movsd  0x40(%rsi,%rax,8),%xmm2
mulsd  0x60(%rdx),%xmm1
mulsd  0x68(%rdx),%xmm2
addsd  %xmm0,%xmm1
movsd  0x60(%rsi,%rax,8),%xmm3
mulsd  0x70(%rdx),%xmm3
addsd  %xmm1,%xmm2
movsd  0x80(%rsi,%rax,8),%xmm1
mulsd  0x78(%rdx),%xmm1
addsd  %xmm2,%xmm3
addsd  %xmm3,%xmm1
movsd  %xmm1,0x80(%rdi,%rax,8)
inc    %rax
jne    1110 <mulmm+0x10>
ret

LLVM IR (-O0):
define void @mulmm(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
store i32 0, i32* %7
br label %11
11: ; preds = %57, %3
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %60
14: ; preds = %11
store i32 0, i32* %8
br label %15
15: ; preds = %53, %14
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %56
18: ; preds = %15
store double 0.000000e+00, double* %10
store i32 0, i32* %9
br label %19
19: ; preds = %41, %18
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %44
22: ; preds = %19
%23 = load double*, double** %5
%24 = load i32, i32* %7
%25 = load i32, i32* %9
%26 = shl i32 %25, 2
%27 = add nsw i32 %24, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %23, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %6
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = shl i32 %33, 2
%35 = add nsw i32 %32, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %31, i64 %36
%38 = load double, double* %37
%39 = load double, double* %10
%40 = call double @llvm.fmuladd.f64(double %30, double %38, double %39)
store double %40, double* %10
br label %41
41: ; preds = %22
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %19
44: ; preds = %19
%45 = load double, double* %10
%46 = load double*, double** %4
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = shl i32 %48, 2
%50 = add nsw i32 %47, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %46, i64 %51
store double %45, double* %52
br label %53
53: ; preds = %44
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %15
56: ; preds = %15
br label %57
57: ; preds = %56
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %11
60: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @mulmm(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2) {
%4 = getelementptr inbounds double, double* %2, i64 1
%5 = getelementptr inbounds double, double* %2, i64 2
%6 = getelementptr inbounds double, double* %2, i64 3
%7 = getelementptr inbounds double, double* %2, i64 4
%8 = getelementptr inbounds double, double* %2, i64 5
%9 = getelementptr inbounds double, double* %2, i64 6
%10 = getelementptr inbounds double, double* %2, i64 7
%11 = getelementptr inbounds double, double* %2, i64 8
%12 = getelementptr inbounds double, double* %2, i64 9
%13 = getelementptr inbounds double, double* %2, i64 10
%14 = getelementptr inbounds double, double* %2, i64 11
%15 = getelementptr inbounds double, double* %2, i64 12
%16 = getelementptr inbounds double, double* %2, i64 13
%17 = getelementptr inbounds double, double* %2, i64 14
%18 = getelementptr inbounds double, double* %2, i64 15
br label %19
19: ; preds = %3, %19
%20 = phi i64 [ 0, %3 ], [ %80, %19 ]
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
%23 = load double, double* %2
%24 = tail call double @llvm.fmuladd.f64(double %22, double %23, double 0.000000e+00)
%25 = add nuw nsw i64 %20, 4
%26 = getelementptr inbounds double, double* %1, i64 %25
%27 = load double, double* %26
%28 = load double, double* %4
%29 = tail call double @llvm.fmuladd.f64(double %27, double %28, double %24)
%30 = add nuw nsw i64 %20, 8
%31 = getelementptr inbounds double, double* %1, i64 %30
%32 = load double, double* %31
%33 = load double, double* %5
%34 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %29)
%35 = add nuw nsw i64 %20, 12
%36 = getelementptr inbounds double, double* %1, i64 %35
%37 = load double, double* %36
%38 = load double, double* %6
%39 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %34)
%40 = getelementptr inbounds double, double* %0, i64 %20
store double %39, double* %40
%41 = load double, double* %21
%42 = load double, double* %7
%43 = tail call double @llvm.fmuladd.f64(double %41, double %42, double 0.000000e+00)
%44 = load double, double* %26
%45 = load double, double* %8
%46 = tail call double @llvm.fmuladd.f64(double %44, double %45, double %43)
%47 = load double, double* %31
%48 = load double, double* %9
%49 = tail call double @llvm.fmuladd.f64(double %47, double %48, double %46)
%50 = load double, double* %36
%51 = load double, double* %10
%52 = tail call double @llvm.fmuladd.f64(double %50, double %51, double %49)
%53 = getelementptr inbounds double, double* %0, i64 %25
store double %52, double* %53
%54 = load double, double* %21
%55 = load double, double* %11
%56 = tail call double @llvm.fmuladd.f64(double %54, double %55, double 0.000000e+00)
%57 = load double, double* %26
%58 = load double, double* %12
%59 = tail call double @llvm.fmuladd.f64(double %57, double %58, double %56)
%60 = load double, double* %31
%61 = load double, double* %13
%62 = tail call double @llvm.fmuladd.f64(double %60, double %61, double %59)
%63 = load double, double* %36
%64 = load double, double* %14
%65 = tail call double @llvm.fmuladd.f64(double %63, double %64, double %62)
%66 = getelementptr inbounds double, double* %0, i64 %30
store double %65, double* %66
%67 = load double, double* %21
%68 = load double, double* %15
%69 = tail call double @llvm.fmuladd.f64(double %67, double %68, double 0.000000e+00)
%70 = load double, double* %26
%71 = load double, double* %16
%72 = tail call double @llvm.fmuladd.f64(double %70, double %71, double %69)
%73 = load double, double* %31
%74 = load double, double* %17
%75 = tail call double @llvm.fmuladd.f64(double %73, double %74, double %72)
%76 = load double, double* %36
%77 = load double, double* %18
%78 = tail call double @llvm.fmuladd.f64(double %76, double %77, double %75)
%79 = getelementptr inbounds double, double* %0, i64 %35
store double %78, double* %79
%80 = add nuw nsw i64 %20, 1
%81 = icmp eq i64 %80, 4
br i1 %81, label %82, label %19
82: ; preds = %19
ret void
}