void transposed_matrix_multiplication(double **matrix_a, double **matrix_b,
                                      double ***matrix_c, int num_rows_a,
                                      int num_cols_a, int num_rows_b,
                                      int num_cols_b) {
  int i, j, k;
  for (i = 0; i < num_rows_a; ++i) {
    for (j = 0; j < num_rows_b; ++j) {
      for (k = 0; k < num_cols_a; ++k) {
        (*matrix_c)[i][j] += matrix_a[i][k] * matrix_b[j][k];
      }
    }
  }
}


x86 assembly (clang, -O0):
<transposed_matrix_multiplication>:
push   %rbp
mov    %rsp,%rbp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11da <transposed_matrix_multiplication+0xda>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11c7 <transposed_matrix_multiplication+0xc7>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b4 <transposed_matrix_multiplication+0xb4>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    114b <transposed_matrix_multiplication+0x4b>
jmp    11b9 <transposed_matrix_multiplication+0xb9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1138 <transposed_matrix_multiplication+0x38>
jmp    11cc <transposed_matrix_multiplication+0xcc>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1125 <transposed_matrix_multiplication+0x25>
pop    %rbp
ret

x86 assembly (clang, -O2):
<transposed_matrix_multiplication>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %ecx,%ecx
jle    11d4 <transposed_matrix_multiplication+0xd4>
mov    %ecx,%r10d
mov    %r9d,%r14d
mov    %r8d,%r11d
mov    %r11d,%r12d
and    $0xfffffffe,%r12d
xor    %r15d,%r15d
jmp    113d <transposed_matrix_multiplication+0x3d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r10,%r15
je     11d4 <transposed_matrix_multiplication+0xd4>
test   %r9d,%r9d
jle    1130 <transposed_matrix_multiplication+0x30>
xor    %ecx,%ecx
jmp    1159 <transposed_matrix_multiplication+0x59>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %r14,%rcx
je     1130 <transposed_matrix_multiplication+0x30>
test   %r8d,%r8d
jle    1150 <transposed_matrix_multiplication+0x50>
mov    (%rdi,%r15,8),%rax
mov    (%rsi,%rcx,8),%r13
mov    (%rdx),%rbx
mov    (%rbx,%r15,8),%rbx
movsd  (%rbx,%rcx,8),%xmm0
xor    %ebp,%ebp
cmp    $0x1,%r8d
je     11b4 <transposed_matrix_multiplication+0xb4>
nopw   0x0(%rax,%rax,1)
movsd  (%rax,%rbp,8),%xmm1
mulsd  0x0(%r13,%rbp,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
movsd  0x8(%rax,%rbp,8),%xmm0
mulsd  0x8(%r13,%rbp,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rcx,8)
add    $0x2,%rbp
cmp    %rbp,%r12
jne    1180 <transposed_matrix_multiplication+0x80>
test   $0x1,%r11b
je     1150 <transposed_matrix_multiplication+0x50>
movsd  (%rax,%rbp,8),%xmm1
mulsd  0x0(%r13,%rbp,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
jmp    1150 <transposed_matrix_multiplication+0x50>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @transposed_matrix_multiplication(double** nocapture %0, double** nocapture %1, double*** nocapture %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %67
9: ; preds = %7
%10 = icmp sgt i32 %5, 0
%11 = icmp sgt i32 %4, 0
%12 = zext i32 %3 to i64
%13 = zext i32 %5 to i64
%14 = zext i32 %4 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %4, 1
%17 = and i64 %14, 4294967294
%18 = icmp eq i64 %15, 0
br label %19
19: ; preds = %9, %64
%20 = phi i64 [ 0, %9 ], [ %65, %64 ]
br i1 %10, label %21, label %64
21: ; preds = %19
%22 = getelementptr inbounds double*, double** %0, i64 %20
br label %23
23: ; preds = %21, %61
%24 = phi i64 [ 0, %21 ], [ %62, %61 ]
br i1 %11, label %25, label %61
25: ; preds = %23
%26 = load double*, double** %22
%27 = getelementptr inbounds double*, double** %1, i64 %24
%28 = load double*, double** %27
%29 = load double**, double*** %2
%30 = getelementptr inbounds double*, double** %29, i64 %20
%31 = load double*, double** %30
%32 = getelementptr inbounds double, double* %31, i64 %24
%33 = load double, double* %32
br i1 %16, label %52, label %34
34: ; preds = %25, %34
%35 = phi double [ %48, %34 ], [ %33, %25 ]
%36 = phi i64 [ %49, %34 ], [ 0, %25 ]
%37 = phi i64 [ %50, %34 ], [ 0, %25 ]
%38 = getelementptr inbounds double, double* %26, i64 %36
%39 = load double, double* %38
%40 = getelementptr inbounds double, double* %28, i64 %36
%41 = load double, double* %40
%42 = tail call double @llvm.fmuladd.f64(double %39, double %41, double %35)
store double %42, double* %32
%43 = or i64 %36, 1
%44 = getelementptr inbounds double, double* %26, i64 %43
%45 = load double, double* %44
%46 = getelementptr inbounds double, double* %28, i64 %43
%47 = load double, double* %46
%48 = tail call double @llvm.fmuladd.f64(double %45, double %47, double %42)
store double %48, double* %32
%49 = add nuw nsw i64 %36, 2
%50 = add i64 %37, 2
%51 = icmp eq i64 %50, %17
br i1 %51, label %52, label %34
52: ; preds = %34, %25
%53 = phi double [ %33, %25 ], [ %48, %34 ]
%54 = phi i64 [ 0, %25 ], [ %49, %34 ]
br i1 %18, label %61, label %55
55: ; preds = %52
%56 = getelementptr inbounds double, double* %26, i64 %54
%57 = load double, double* %56
%58 = getelementptr inbounds double, double* %28, i64 %54
%59 = load double, double* %58
%60 = tail call double @llvm.fmuladd.f64(double %57, double %59, double %53)
store double %60, double* %32
br label %61
61: ; preds = %55, %52, %23
%62 = add nuw nsw i64 %24, 1
%63 = icmp eq i64 %62, %13
br i1 %63, label %64, label %23
64: ; preds = %61, %19
%65 = add nuw nsw i64 %20, 1
%66 = icmp eq i64 %65, %12
br i1 %66, label %67, label %19
67: ; preds = %64, %7
ret void
}