void 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_cols_b; ++j) {
      for (k = 0; k < num_cols_a; ++k) {
        (*matrix_c)[i][j] += matrix_a[i][k] * matrix_b[k][j];
      }
    }
  }
}


x86 assembly (clang, -O0):
<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 <matrix_multiplication+0xda>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    11c7 <matrix_multiplication+0xc7>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b4 <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 -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%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 <matrix_multiplication+0x4b>
jmp    11b9 <matrix_multiplication+0xb9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1138 <matrix_multiplication+0x38>
jmp    11cc <matrix_multiplication+0xcc>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1125 <matrix_multiplication+0x25>
pop    %rbp
ret

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

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