void matmul(double dst[20][40], double A[20][30], double B[30][40]) {
  for (int i = 0; i < 20; i++) {
    for (int j = 0; j < 40; j++) {
      dst[i][j] = 0;
      for (int k = 0; k < 30; k++) {
        dst[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<matmul>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jge    11f3 <matmul+0xf3>
movl   $0x0,-0x20(%rbp)
cmpl   $0x28,-0x20(%rbp)
jge    11e0 <matmul+0xe0>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x140,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1e,-0x24(%rbp)
jge    11cd <matmul+0xcd>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0xf0,%rcx,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x140,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x140,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1157 <matmul+0x57>
jmp    11d2 <matmul+0xd2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1128 <matmul+0x28>
jmp    11e5 <matmul+0xe5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <matmul+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<matmul>:
xor    %r8d,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rdx,%r9
xor    %r10d,%r10d
cs nopw 0x0(%rax,%rax,1)
lea    (%r8,%r8,4),%rax
shl    $0x6,%rax
add    %rdi,%rax
lea    (%rax,%r10,8),%r11
movq   $0x0,(%rax,%r10,8)
xorpd  %xmm0,%xmm0
mov    $0x1,%eax
mov    %r9,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  -0x8(%rsi,%rax,8),%xmm1
mulsd  (%rcx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r11)
movsd  (%rsi,%rax,8),%xmm0
mulsd  0x140(%rcx),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r11)
add    $0x2,%rax
add    $0x280,%rcx
cmp    $0x1f,%rax
jne    1150 <matmul+0x50>
add    $0x1,%r10
add    $0x8,%r9
cmp    $0x28,%r10
jne    1120 <matmul+0x20>
add    $0x1,%r8
add    $0xf0,%rsi
cmp    $0x14,%r8
jne    1110 <matmul+0x10>
ret

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

LLVM IR (-O2):
define void @matmul([40 x double]* nocapture %0, [30 x double]* nocapture %1, [40 x double]* nocapture %2) {
br label %4
4: ; preds = %3, %7
%5 = phi i64 [ 0, %3 ], [ %8, %7 ]
br label %10
6: ; preds = %7
ret void
7: ; preds = %13
%8 = add nuw nsw i64 %5, 1
%9 = icmp eq i64 %8, 20
br i1 %9, label %6, label %4
10: ; preds = %4, %13
%11 = phi i64 [ 0, %4 ], [ %14, %13 ]
%12 = getelementptr inbounds [40 x double], [40 x double]* %0, i64 %5, i64 %11
store double 0.000000e+00, double* %12
br label %16
13: ; preds = %16
%14 = add nuw nsw i64 %11, 1
%15 = icmp eq i64 %14, 40
br i1 %15, label %7, label %10
16: ; preds = %16, %10
%17 = phi double [ 0.000000e+00, %10 ], [ %29, %16 ]
%18 = phi i64 [ 0, %10 ], [ %30, %16 ]
%19 = getelementptr inbounds [30 x double], [30 x double]* %1, i64 %5, i64 %18
%20 = load double, double* %19
%21 = getelementptr inbounds [40 x double], [40 x double]* %2, i64 %18, i64 %11
%22 = load double, double* %21
%23 = tail call double @llvm.fmuladd.f64(double %20, double %22, double %17)
store double %23, double* %12
%24 = or i64 %18, 1
%25 = getelementptr inbounds [30 x double], [30 x double]* %1, i64 %5, i64 %24
%26 = load double, double* %25
%27 = getelementptr inbounds [40 x double], [40 x double]* %2, i64 %24, i64 %11
%28 = load double, double* %27
%29 = tail call double @llvm.fmuladd.f64(double %26, double %28, double %23)
store double %29, double* %12
%30 = add nuw nsw i64 %18, 2
%31 = icmp eq i64 %30, 30
br i1 %31, label %13, label %16
}