void mat4_mul(const float a[4][4], const float b[4][4], float out[4][4]) {
  int i, j, k;
  float ret[4][4] = {};
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      ret[j][i] = 0.0;
      for (k = 0; k < 4; ++k) {
        ret[j][i] += a[k][i] * b[j][k];
      }
    }
  }
  mat4_copy(ret, out);
}


x86 assembly (clang, -O0):
<mat4_mul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    121b <mat4_mul+0xfb>
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    1208 <mat4_mul+0xe8>
movslq -0x20(%rbp),%rcx
lea    -0x70(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rax,%rcx,4)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11f5 <mat4_mul+0xd5>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
movslq -0x20(%rbp),%rcx
lea    -0x70(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1188 <mat4_mul+0x68>
jmp    11fa <mat4_mul+0xda>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115c <mat4_mul+0x3c>
jmp    120d <mat4_mul+0xed>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <mat4_mul+0x2b>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <mat4_copy@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4_mul>:
sub    $0x58,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xorps  %xmm15,%xmm15
movss  0x3c(%rsi),%xmm0
movaps %xmm0,0x40(%rsp)
movss  0x38(%rsi),%xmm10
movss  0x34(%rsi),%xmm12
movss  0x30(%rsi),%xmm14
movss  0x2c(%rsi),%xmm9
movss  0x28(%rsi),%xmm8
movss  0x24(%rsi),%xmm7
movss  0x20(%rsi),%xmm6
movss  0x1c(%rsi),%xmm5
movss  (%rsi),%xmm1
movss  0x4(%rsi),%xmm4
movss  0x8(%rsi),%xmm3
movss  0xc(%rsi),%xmm2
shufps $0x0,%xmm2,%xmm2
shufps $0x0,%xmm3,%xmm3
shufps $0x0,%xmm4,%xmm4
shufps $0x0,%xmm1,%xmm1
movups (%rdi),%xmm13
movups 0x10(%rdi),%xmm11
mulps  %xmm13,%xmm1
addps  %xmm15,%xmm1
mulps  %xmm11,%xmm4
addps  %xmm1,%xmm4
movups 0x20(%rdi),%xmm15
mulps  %xmm15,%xmm3
addps  %xmm4,%xmm3
movups 0x30(%rdi),%xmm1
mulps  %xmm1,%xmm2
addps  %xmm3,%xmm2
movss  0x18(%rsi),%xmm3
movss  0x14(%rsi),%xmm4
movss  0x10(%rsi),%xmm0
movaps %xmm2,(%rsp)
shufps $0x0,%xmm4,%xmm4
shufps $0x0,%xmm0,%xmm0
mulps  %xmm13,%xmm0
xorps  %xmm2,%xmm2
addps  %xmm2,%xmm0
mulps  %xmm11,%xmm4
addps  %xmm0,%xmm4
shufps $0x0,%xmm3,%xmm3
mulps  %xmm15,%xmm3
addps  %xmm4,%xmm3
shufps $0x0,%xmm5,%xmm5
mulps  %xmm1,%xmm5
addps  %xmm3,%xmm5
movaps %xmm5,0x10(%rsp)
shufps $0x0,%xmm7,%xmm7
shufps $0x0,%xmm6,%xmm6
mulps  %xmm13,%xmm6
addps  %xmm2,%xmm6
xorps  %xmm0,%xmm0
mulps  %xmm11,%xmm7
addps  %xmm6,%xmm7
shufps $0x0,%xmm8,%xmm8
mulps  %xmm15,%xmm8
addps  %xmm7,%xmm8
shufps $0x0,%xmm9,%xmm9
mulps  %xmm1,%xmm9
addps  %xmm8,%xmm9
movaps %xmm9,0x20(%rsp)
shufps $0x0,%xmm14,%xmm14
mulps  %xmm13,%xmm14
addps  %xmm0,%xmm14
shufps $0x0,%xmm12,%xmm12
mulps  %xmm11,%xmm12
addps  %xmm14,%xmm12
shufps $0x0,%xmm10,%xmm10
mulps  %xmm15,%xmm10
addps  %xmm12,%xmm10
movaps 0x40(%rsp),%xmm0
shufps $0x0,%xmm0,%xmm0
mulps  %xmm1,%xmm0
addps  %xmm10,%xmm0
movaps %xmm0,0x30(%rsp)
mov    %rsp,%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1030 <mat4_copy@plt>
add    $0x58,%rsp
ret

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

LLVM IR (-O2):
define void @mat4_mul([4 x float]* nocapture %0, [4 x float]* nocapture %1, [4 x float]* %2) {
%4 = alloca [4 x [4 x float]]
%5 = bitcast [4 x [4 x float]]* %4 to i8*
%6 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 3, i64 3
%7 = load float, float* %6
%8 = insertelement <4 x float> poison, float %7, i64 0
%9 = shufflevector <4 x float> %8, <4 x float> poison, <4 x i32> zeroinitializer
%10 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 3, i64 2
%11 = load float, float* %10
%12 = insertelement <4 x float> poison, float %11, i64 0
%13 = shufflevector <4 x float> %12, <4 x float> poison, <4 x i32> zeroinitializer
%14 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 3, i64 1
%15 = load float, float* %14
%16 = insertelement <4 x float> poison, float %15, i64 0
%17 = shufflevector <4 x float> %16, <4 x float> poison, <4 x i32> zeroinitializer
%18 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 3, i64 0
%19 = load float, float* %18
%20 = insertelement <4 x float> poison, float %19, i64 0
%21 = shufflevector <4 x float> %20, <4 x float> poison, <4 x i32> zeroinitializer
%22 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 2, i64 3
%23 = load float, float* %22
%24 = insertelement <4 x float> poison, float %23, i64 0
%25 = shufflevector <4 x float> %24, <4 x float> poison, <4 x i32> zeroinitializer
%26 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 2, i64 2
%27 = load float, float* %26
%28 = insertelement <4 x float> poison, float %27, i64 0
%29 = shufflevector <4 x float> %28, <4 x float> poison, <4 x i32> zeroinitializer
%30 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 2, i64 1
%31 = load float, float* %30
%32 = insertelement <4 x float> poison, float %31, i64 0
%33 = shufflevector <4 x float> %32, <4 x float> poison, <4 x i32> zeroinitializer
%34 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 2, i64 0
%35 = load float, float* %34
%36 = insertelement <4 x float> poison, float %35, i64 0
%37 = shufflevector <4 x float> %36, <4 x float> poison, <4 x i32> zeroinitializer
%38 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 1, i64 3
%39 = load float, float* %38
%40 = insertelement <4 x float> poison, float %39, i64 0
%41 = shufflevector <4 x float> %40, <4 x float> poison, <4 x i32> zeroinitializer
%42 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 1, i64 2
%43 = load float, float* %42
%44 = insertelement <4 x float> poison, float %43, i64 0
%45 = shufflevector <4 x float> %44, <4 x float> poison, <4 x i32> zeroinitializer
%46 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 1, i64 1
%47 = load float, float* %46
%48 = insertelement <4 x float> poison, float %47, i64 0
%49 = shufflevector <4 x float> %48, <4 x float> poison, <4 x i32> zeroinitializer
%50 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 1, i64 0
%51 = load float, float* %50
%52 = insertelement <4 x float> poison, float %51, i64 0
%53 = shufflevector <4 x float> %52, <4 x float> poison, <4 x i32> zeroinitializer
%54 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 3
%55 = load float, float* %54
%56 = insertelement <4 x float> poison, float %55, i64 0
%57 = shufflevector <4 x float> %56, <4 x float> poison, <4 x i32> zeroinitializer
%58 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 2
%59 = load float, float* %58
%60 = insertelement <4 x float> poison, float %59, i64 0
%61 = shufflevector <4 x float> %60, <4 x float> poison, <4 x i32> zeroinitializer
%62 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 1
%63 = load float, float* %62
%64 = insertelement <4 x float> poison, float %63, i64 0
%65 = shufflevector <4 x float> %64, <4 x float> poison, <4 x i32> zeroinitializer
%66 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 0
%67 = load float, float* %66
%68 = insertelement <4 x float> poison, float %67, i64 0
%69 = shufflevector <4 x float> %68, <4 x float> poison, <4 x i32> zeroinitializer
%70 = bitcast [4 x float]* %0 to <4 x float>*
%71 = load <4 x float>, <4 x float>* %70
%72 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %71, <4 x float> %69, <4 x float> zeroinitializer)
%73 = getelementptr inbounds [4 x float], [4 x float]* %0, i64 1, i64 0
%74 = bitcast float* %73 to <4 x float>*
%75 = load <4 x float>, <4 x float>* %74
%76 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %75, <4 x float> %65, <4 x float> %72)
%77 = getelementptr inbounds [4 x float], [4 x float]* %0, i64 2, i64 0
%78 = bitcast float* %77 to <4 x float>*
%79 = load <4 x float>, <4 x float>* %78
%80 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %79, <4 x float> %61, <4 x float> %76)
%81 = getelementptr inbounds [4 x float], [4 x float]* %0, i64 3, i64 0
%82 = bitcast float* %81 to <4 x float>*
%83 = load <4 x float>, <4 x float>* %82
%84 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %83, <4 x float> %57, <4 x float> %80)
%85 = bitcast [4 x [4 x float]]* %4 to <4 x float>*
store <4 x float> %84, <4 x float>* %85
%86 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %4, i64 0, i64 1, i64 0
%87 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %71, <4 x float> %53, <4 x float> zeroinitializer)
%88 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %75, <4 x float> %49, <4 x float> %87)
%89 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %79, <4 x float> %45, <4 x float> %88)
%90 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %83, <4 x float> %41, <4 x float> %89)
%91 = bitcast float* %86 to <4 x float>*
store <4 x float> %90, <4 x float>* %91
%92 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %4, i64 0, i64 2, i64 0
%93 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %71, <4 x float> %37, <4 x float> zeroinitializer)
%94 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %75, <4 x float> %33, <4 x float> %93)
%95 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %79, <4 x float> %29, <4 x float> %94)
%96 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %83, <4 x float> %25, <4 x float> %95)
%97 = bitcast float* %92 to <4 x float>*
store <4 x float> %96, <4 x float>* %97
%98 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %4, i64 0, i64 3, i64 0
%99 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %71, <4 x float> %21, <4 x float> zeroinitializer)
%100 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %75, <4 x float> %17, <4 x float> %99)
%101 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %79, <4 x float> %13, <4 x float> %100)
%102 = call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %83, <4 x float> %9, <4 x float> %101)
%103 = bitcast float* %98 to <4 x float>*
store <4 x float> %102, <4 x float>* %103
%104 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %4, i64 0, i64 0
%105 = call i32 ([4 x float]*, [4 x float]*, ...) bitcast (i32 (...)* @mat4_copy to i32 ([4 x float]*, [4 x float]*, ...)*)([4 x float]* %104, [4 x float]* %2)
ret void
}