void glmMultMatrix2d(double result[4], const double m1[4], const double m2[4]) {
  double sum;
  int x, y, i;
  for (x = 0; x < 2; x++) {
    for (y = 0; y < 2; y++) {
      sum = 0;
      for (i = 0; i < 2; i++)
        sum += m1[y + 2 * i] * m2[2 * x + i];
      result[y + 2 * x] = sum;
    }
  }
}


x86 assembly (clang, -O0):
<glmMultMatrix2d>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jge    11d4 <glmMultMatrix2d+0xd4>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jge    11c1 <glmMultMatrix2d+0xc1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    1197 <glmMultMatrix2d+0x97>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%edx
shl    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1141 <glmMultMatrix2d+0x41>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%edx
shl    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1128 <glmMultMatrix2d+0x28>
jmp    11c6 <glmMultMatrix2d+0xc6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1117 <glmMultMatrix2d+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<glmMultMatrix2d>:
movsd  (%rsi),%xmm1
movsd  0x10(%rsi),%xmm2
mulsd  (%rdx),%xmm1
xorpd  %xmm0,%xmm0
addsd  %xmm0,%xmm1
mulsd  0x8(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rdi)
movsd  0x8(%rsi),%xmm1
mulsd  (%rdx),%xmm1
movsd  0x18(%rsi),%xmm2
addsd  %xmm0,%xmm1
mulsd  0x8(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rdi)
movsd  (%rsi),%xmm1
movsd  0x10(%rsi),%xmm2
mulsd  0x10(%rdx),%xmm1
mulsd  0x18(%rdx),%xmm2
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rdi)
movsd  0x8(%rsi),%xmm1
movsd  0x18(%rsi),%xmm2
mulsd  0x10(%rdx),%xmm1
addsd  %xmm0,%xmm1
mulsd  0x18(%rdx),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x18(%rdi)
ret

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

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