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


x86 assembly (clang, -O0):
<MyGemm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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   $0x1,-0x2c(%rbp)
movsd  0xeba(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c8 <MyGemm+0xb8>
mov    -0x18(%rbp),%rcx
mov    -0x3c(%rbp),%eax
imul   -0x1c(%rbp),%eax
add    $0x0,%eax
cltq
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x28(%rbp),%r9
imul   $0x0,0x10(%rbp),%eax
add    -0x3c(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%r9
mov    0x18(%rbp),%r10
lea    -0x4(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x2c(%rbp),%r8
lea    0x10(%rbp),%r11
lea    0x20(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1030 <dger_@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1152 <MyGemm+0x42>
add    $0x60,%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    %edi,0xc(%rsp)
mov    %esi,0x8(%rsp)
movl   $0x1,0x4(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x10(%rsp)
test   %edx,%edx
jle    11a4 <MyGemm+0x94>
mov    %r9,%r14
mov    %rcx,%rbx
movslq %r8d,%r15
mov    %edx,%r12d
shl    $0x3,%r15
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
sub    $0x8,%rsp
lea    0x14(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    %rbx,%rcx
mov    %r13,%r8
mov    %r14,%r9
xor    %eax,%eax
lea    0x68(%rsp),%rbp
push   %rbp
push   0x68(%rsp)
lea    0x68(%rsp),%rbp
push   %rbp
call   1030 <dger_@plt>
add    $0x20,%rsp
add    %r15,%rbx
add    $0x8,%r14
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
%20 = alloca double
%21 = 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 1, i32* %19
store double 1.000000e+00, double* %20
store i32 0, i32* %21
br label %22
22: ; preds = %43, %9
%23 = load i32, i32* %21
%24 = load i32, i32* %12
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %46
26: ; preds = %22
%27 = load double*, double** %13
%28 = load i32, i32* %21
%29 = load i32, i32* %14
%30 = mul nsw i32 %28, %29
%31 = add nsw i32 %30, 0
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %27, i64 %32
%34 = load double*, double** %15
%35 = load i32, i32* %16
%36 = mul nsw i32 0, %35
%37 = load i32, i32* %21
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %34, i64 %39
%41 = load double*, double** %17
%42 = call i32 (i32*, i32*, double*, double*, i32*, double*, i32*, double*, i32*, ...) bitcast (i32 (...)* @dger_ to i32 (i32*, i32*, double*, double*, i32*, double*, i32*, double*, i32*, ...)*)(i32* %10, i32* %11, double* %20, double* %33, i32* %19, double* %40, i32* %16, double* %41, i32* %18)
br label %43
43: ; preds = %26
%44 = load i32, i32* %21
%45 = add nsw i32 %44, 1
store i32 %45, i32* %21
br label %22
46: ; preds = %22
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 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
store i32 %0, i32* %10
store i32 %1, i32* %11
store i32 %6, i32* %12
store i32 %8, i32* %13
%16 = bitcast i32* %14 to i8*
store i32 1, i32* %14
%17 = bitcast double* %15 to i8*
store double 1.000000e+00, double* %15
%18 = icmp sgt i32 %2, 0
br i1 %18, label %19, label %22
19: ; preds = %9
%20 = sext i32 %4 to i64
%21 = zext i32 %2 to i64
br label %23
22: ; preds = %23, %9
ret void
23: ; preds = %19, %23
%24 = phi i64 [ 0, %19 ], [ %29, %23 ]
%25 = mul nsw i64 %24, %20
%26 = getelementptr inbounds double, double* %3, i64 %25
%27 = getelementptr inbounds double, double* %5, i64 %24
%28 = call i32 (i32*, i32*, double*, double*, i32*, double*, i32*, double*, i32*, ...) bitcast (i32 (...)* @dger_ to i32 (i32*, i32*, double*, double*, i32*, double*, i32*, double*, i32*, ...)*)(i32* %10, i32* %11, double* %15, double* %26, i32* %14, double* %27, i32* %12, double* %7, i32* %13)
%29 = add nuw nsw i64 %24, 1
%30 = icmp eq i64 %29, %21
br i1 %30, label %22, label %23
}