void pack_MRxk(int k, const double *A, int incRowA, int incColA,
               double *buffer) {
  int i, j;
  for (j = 0; j < k; ++j) {
    for (i = 0; i < 8; ++i) {
      buffer[i] = A[i * incRowA];
    }
    buffer += 8;
    A += incColA;
  }
}


x86 assembly (clang, -O0):
<pack_MRxk>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1196 <pack_MRxk+0x96>
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    1167 <pack_MRxk+0x67>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x14(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112f <pack_MRxk+0x2f>
mov    -0x20(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    111c <pack_MRxk+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_MRxk>:
test   %edi,%edi
jle    1197 <pack_MRxk+0x97>
movslq %ecx,%rax
movslq %edx,%rcx
shl    $0x3,%rax
imul   $0x38,%rcx,%rdx
shl    $0x3,%rcx
sub    %rdx,%rax
nopl   (%rax)
movsd  (%rsi),%xmm0
movsd  %xmm0,(%r8)
movsd  (%rsi,%rcx,1),%xmm0
add    %rcx,%rsi
movsd  %xmm0,0x8(%r8)
movsd  (%rcx,%rsi,1),%xmm0
add    %rcx,%rsi
movsd  %xmm0,0x10(%r8)
movsd  (%rcx,%rsi,1),%xmm0
add    %rcx,%rsi
movsd  %xmm0,0x18(%r8)
movsd  (%rcx,%rsi,1),%xmm0
add    %rcx,%rsi
movsd  %xmm0,0x20(%r8)
movsd  (%rcx,%rsi,1),%xmm0
add    %rcx,%rsi
movsd  %xmm0,0x28(%r8)
movsd  (%rcx,%rsi,1),%xmm0
add    %rcx,%rsi
movsd  %xmm0,0x30(%r8)
movsd  (%rcx,%rsi,1),%xmm0
add    %rcx,%rsi
add    %rax,%rsi
movsd  %xmm0,0x38(%r8)
add    $0x40,%r8
add    $0xffffffff,%edi
jne    1120 <pack_MRxk+0x20>
ret

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

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