void MyGemv(int m, int n, double *A, int ldA, double *x, int incx, double *y,
            int incy) {
  for (int j = 0; j < n; j++)
    Axpy(m, x[(j)*incx], &A[(j)*ldA + 0], 1, y, 1);
}


x86 assembly (clang, -O0):
<MyGemv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1196 <MyGemv+0x86>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x24(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%eax
imul   -0x14(%rbp),%eax
add    $0x0,%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    0x10(%rbp),%rcx
mov    $0x1,%r8d
mov    %r8d,%edx
mov    $0x1,%al
call   1030 <Axpy@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    113b <MyGemv+0x2b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MyGemv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    116e <MyGemv+0x5e>
mov    %r8,%r14
mov    %rdx,%rbx
mov    %edi,%r12d
movslq %r9d,%r13
movslq %ecx,%rbp
mov    %esi,%r15d
shl    $0x3,%rbp
shl    $0x3,%r13
nopl   0x0(%rax)
movsd  (%r14),%xmm0
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    0x40(%rsp),%rcx
mov    $0x1,%r8d
mov    $0x1,%al
call   1030 <Axpy@plt>
add    %rbp,%rbx
add    %r13,%r14
add    $0xffffffffffffffff,%r15
jne    1140 <MyGemv+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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