void pack_kxNR(int k, const double *B, int incRowB, int incColB,
               double *buffer) {
  int i, j;
  for (i = 0; i < k; ++i) {
    for (j = 0; j < 4; ++j) {
      buffer[j] = B[j * incColB];
    }
    buffer += 4;
    B += incRowB;
  }
}


x86 assembly (clang, -O0):
<pack_kxNR>:
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,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1196 <pack_kxNR+0x96>
movl   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x28(%rbp)
jge    1167 <pack_kxNR+0x67>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112f <pack_kxNR+0x2f>
mov    -0x20(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    111c <pack_kxNR+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<pack_kxNR>:
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    11f0 <pack_kxNR+0xf0>
movslq %ecx,%r9
cmp    $0x1,%edi
je     11b7 <pack_kxNR+0xb7>
movslq %edx,%rdx
mov    %edi,%ecx
and    $0xfffffffe,%ecx
lea    0x0(,%r9,8),%r11
lea    (%r11,%r11,2),%r10
mov    %r9,%rax
shl    $0x4,%rax
lea    0x0(,%rdx,8),%r14
lea    (%r10,%rdx,8),%r15
lea    (%rax,%rdx,8),%r12
lea    (%r11,%rdx,8),%rbx
shl    $0x4,%rdx
xchg   %ax,%ax
movsd  (%rsi),%xmm0
movsd  %xmm0,(%r8)
movsd  (%rsi,%r11,1),%xmm0
movsd  %xmm0,0x8(%r8)
movsd  (%rsi,%rax,1),%xmm0
movsd  %xmm0,0x10(%r8)
movsd  (%rsi,%r10,1),%xmm0
movsd  %xmm0,0x18(%r8)
movsd  (%rsi,%r14,1),%xmm0
movsd  %xmm0,0x20(%r8)
movsd  (%rsi,%rbx,1),%xmm0
movsd  %xmm0,0x28(%r8)
movsd  (%rsi,%r12,1),%xmm0
movsd  %xmm0,0x30(%r8)
movsd  (%rsi,%r15,1),%xmm0
movsd  %xmm0,0x38(%r8)
add    $0x40,%r8
add    %rdx,%rsi
add    $0xfffffffe,%ecx
jne    1150 <pack_kxNR+0x50>
test   $0x1,%dil
je     11f0 <pack_kxNR+0xf0>
lea    (%r9,%r9,1),%rax
lea    (%r9,%r9,2),%rcx
movsd  (%rsi),%xmm0
movsd  %xmm0,(%r8)
movsd  (%rsi,%r9,8),%xmm0
movsd  %xmm0,0x8(%r8)
movsd  (%rsi,%rax,8),%xmm0
movsd  %xmm0,0x10(%r8)
movsd  (%rsi,%rcx,8),%xmm0
movsd  %xmm0,0x18(%r8)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @pack_kxNR(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* %11
br label %13
13: ; preds = %43, %5
%14 = load i32, i32* %11
%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* %12
br label %18
18: ; preds = %33, %17
%19 = load i32, i32* %12
%20 = icmp slt i32 %19, 4
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = load double*, double** %7
%23 = load i32, i32* %12
%24 = load i32, i32* %9
%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* %12
%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* %12
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
br label %18
36: ; preds = %18
%37 = load double*, double** %10
%38 = getelementptr inbounds double, double* %37, i64 4
store double* %38, double** %10
%39 = load i32, i32* %8
%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* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %13
46: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @pack_kxNR(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 %61
7: ; preds = %5
%8 = sext i32 %2 to i64
%9 = sext i32 %3 to i64
%10 = shl nsw i64 %9, 1
%11 = mul nsw i64 %9, 3
%12 = and i32 %0, 1
%13 = icmp eq i32 %0, 1
br i1 %13, label %46, label %14
14: ; preds = %7
%15 = and i32 %0, -2
br label %16
16: ; preds = %16, %14
%17 = phi double* [ %4, %14 ], [ %42, %16 ]
%18 = phi double* [ %1, %14 ], [ %43, %16 ]
%19 = phi i32 [ 0, %14 ], [ %44, %16 ]
%20 = load double, double* %18
store double %20, double* %17
%21 = getelementptr inbounds double, double* %18, i64 %9
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %17, i64 1
store double %22, double* %23
%24 = getelementptr inbounds double, double* %18, i64 %10
%25 = load double, double* %24
%26 = getelementptr inbounds double, double* %17, i64 2
store double %25, double* %26
%27 = getelementptr inbounds double, double* %18, i64 %11
%28 = load double, double* %27
%29 = getelementptr inbounds double, double* %17, i64 3
store double %28, double* %29
%30 = getelementptr inbounds double, double* %17, i64 4
%31 = getelementptr inbounds double, double* %18, i64 %8
%32 = load double, double* %31
store double %32, double* %30
%33 = getelementptr inbounds double, double* %31, i64 %9
%34 = load double, double* %33
%35 = getelementptr inbounds double, double* %17, i64 5
store double %34, double* %35
%36 = getelementptr inbounds double, double* %31, i64 %10
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %17, i64 6
store double %37, double* %38
%39 = getelementptr inbounds double, double* %31, i64 %11
%40 = load double, double* %39
%41 = getelementptr inbounds double, double* %17, i64 7
store double %40, double* %41
%42 = getelementptr inbounds double, double* %17, i64 8
%43 = getelementptr inbounds double, double* %31, i64 %8
%44 = add i32 %19, 2
%45 = icmp eq i32 %44, %15
br i1 %45, label %46, label %16
46: ; preds = %16, %7
%47 = phi double* [ %4, %7 ], [ %42, %16 ]
%48 = phi double* [ %1, %7 ], [ %43, %16 ]
%49 = icmp eq i32 %12, 0
br i1 %49, label %61, label %50
50: ; preds = %46
%51 = load double, double* %48
store double %51, double* %47
%52 = getelementptr inbounds double, double* %48, i64 %9
%53 = load double, double* %52
%54 = getelementptr inbounds double, double* %47, i64 1
store double %53, double* %54
%55 = getelementptr inbounds double, double* %48, i64 %10
%56 = load double, double* %55
%57 = getelementptr inbounds double, double* %47, i64 2
store double %56, double* %57
%58 = getelementptr inbounds double, double* %48, i64 %11
%59 = load double, double* %58
%60 = getelementptr inbounds double, double* %47, i64 3
store double %59, double* %60
br label %61
61: ; preds = %50, %46, %5
ret void
}