void MyGemm(int m, int n, int k, double *A, int ldA, double *B, int ldB,
            double *C, int ldC) {
  for (int j = 0; j < n; ++j)
    MyGemv(m, n, A, ldA, &B[(j)*ldB + 0], 1, &C[(j)*ldC + 0], 1);
}


x86 assembly (clang, -O0):
<MyGemm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b0 <MyGemm+0xa0>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%eax
imul   0x10(%rbp),%eax
add    $0x0,%eax
cltq
shl    $0x3,%rax
add    %rax,%r8
mov    0x18(%rbp),%rax
mov    -0x2c(%rbp),%r9d
imul   0x20(%rbp),%r9d
add    $0x0,%r9d
movslq %r9d,%r9
shl    $0x3,%r9
add    %r9,%rax
mov    $0x1,%r9d
mov    %rax,(%rsp)
movl   $0x1,0x8(%rsp)
mov    $0x0,%al
call   1030 <MyGemv@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113e <MyGemm+0x2e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MyGemm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0x4(%rsp)
test   %esi,%esi
jle    1194 <MyGemm+0x84>
mov    %r9,%rbx
mov    %r8d,%r13d
mov    %rcx,%r14
mov    %edi,%r15d
mov    0x58(%rsp),%rbp
movslq 0x50(%rsp),%rax
movslq 0x60(%rsp),%rdx
mov    0x4(%rsp),%r12d
shl    $0x3,%rdx
mov    %rdx,0x8(%rsp)
shl    $0x3,%rax
mov    %rax,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    0x4(%rsp),%esi
mov    %r14,%rdx
mov    %r13d,%ecx
mov    %rbx,%r8
mov    $0x1,%r9d
xor    %eax,%eax
push   $0x1
push   %rbp
call   1030 <MyGemv@plt>
add    $0x10,%rsp
add    0x8(%rsp),%rbp
add    0x10(%rsp),%rbx
add    $0xffffffffffffffff,%r12
jne    1160 <MyGemm+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @MyGemm(i32 %0, i32 %1, i32 %2, double* %3, i32 %4, double* %5, i32 %6, double* %7, i32 %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
%14 = alloca i32
%15 = alloca double*
%16 = alloca i32
%17 = alloca double*
%18 = alloca i32
%19 = alloca i32
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store double* %3, double** %13
store i32 %4, i32* %14
store double* %5, double** %15
store i32 %6, i32* %16
store double* %7, double** %17
store i32 %8, i32* %18
store i32 0, i32* %19
br label %20
20: ; preds = %44, %9
%21 = load i32, i32* %19
%22 = load i32, i32* %11
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %47
24: ; preds = %20
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = load double*, double** %13
%28 = load i32, i32* %14
%29 = load double*, double** %15
%30 = load i32, i32* %19
%31 = load i32, i32* %16
%32 = mul nsw i32 %30, %31
%33 = add nsw i32 %32, 0
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %29, i64 %34
%36 = load double*, double** %17
%37 = load i32, i32* %19
%38 = load i32, i32* %18
%39 = mul nsw i32 %37, %38
%40 = add nsw i32 %39, 0
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %36, i64 %41
%43 = call i32 (i32, i32, double*, i32, double*, i32, double*, i32, ...) bitcast (i32 (...)* @MyGemv to i32 (i32, i32, double*, i32, double*, i32, double*, i32, ...)*)(i32 %25, i32 %26, double* %27, i32 %28, double* %35, i32 1, double* %42, i32 1)
br label %44
44: ; preds = %24
%45 = load i32, i32* %19
%46 = add nsw i32 %45, 1
store i32 %46, i32* %19
br label %20
47: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @MyGemm(i32 %0, i32 %1, i32 %2, double* %3, i32 %4, double* %5, i32 %6, double* %7, i32 %8) {
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = sext i32 %6 to i64
%13 = sext i32 %8 to i64
%14 = zext i32 %1 to i64
br label %16
15: ; preds = %16, %9
ret void
16: ; preds = %11, %16
%17 = phi i64 [ 0, %11 ], [ %23, %16 ]
%18 = mul nsw i64 %17, %12
%19 = getelementptr inbounds double, double* %5, i64 %18
%20 = mul nsw i64 %17, %13
%21 = getelementptr inbounds double, double* %7, i64 %20
%22 = tail call i32 (i32, i32, double*, i32, double*, i32, double*, i32, ...) bitcast (i32 (...)* @MyGemv to i32 (i32, i32, double*, i32, double*, i32, double*, i32, ...)*)(i32 %0, i32 %1, double* %3, i32 %4, double* %19, i32 1, double* %21, i32 1)
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %14
br i1 %24, label %15, label %16
}