void kernel_dgecp_2_0_lib4(int tri, int kmax, double *A, double *B) {
  if (tri == 1) {
    kmax += 1;
  }
  if (kmax <= 0)
    return;
  const int bs = 4;
  int k;
  for (k = 0; k < kmax - 3; k += 4) {
    B[0 + bs * 0] = A[0 + bs * 0];
    B[1 + bs * 0] = A[1 + bs * 0];
    B[0 + bs * 1] = A[0 + bs * 1];
    B[1 + bs * 1] = A[1 + bs * 1];
    B[0 + bs * 2] = A[0 + bs * 2];
    B[1 + bs * 2] = A[1 + bs * 2];
    B[0 + bs * 3] = A[0 + bs * 3];
    B[1 + bs * 3] = A[1 + bs * 3];
    A += 16;
    B += 16;
  }
  for (; k < kmax; k++) {
    B[0 + bs * 0] = A[0 + bs * 0];
    B[1 + bs * 0] = A[1 + bs * 0];
    A += 4;
    B += 4;
  }
  if (tri == 1) {
    B[1 + bs * 0] = A[1 + bs * 0];
  }
}


x86 assembly (clang, -O0):
<kernel_dgecp_2_0_lib4>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1125 <kernel_dgecp_2_0_lib4+0x25>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1134 <kernel_dgecp_2_0_lib4+0x34>
jmp    1280 <kernel_dgecp_2_0_lib4+0x180>
movl   $0x4,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    120b <kernel_dgecp_2_0_lib4+0x10b>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x20(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x20(%rax)
mov    -0x10(%rbp),%rax
movsd  0x28(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x28(%rax)
mov    -0x10(%rbp),%rax
movsd  0x40(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x40(%rax)
mov    -0x10(%rbp),%rax
movsd  0x48(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x48(%rax)
mov    -0x10(%rbp),%rax
movsd  0x60(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x60(%rax)
mov    -0x10(%rbp),%rax
movsd  0x68(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x68(%rax)
mov    -0x10(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
jmp    1142 <kernel_dgecp_2_0_lib4+0x42>
jmp    1210 <kernel_dgecp_2_0_lib4+0x110>
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1264 <kernel_dgecp_2_0_lib4+0x164>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1210 <kernel_dgecp_2_0_lib4+0x110>
cmpl   $0x1,-0x4(%rbp)
jne    1280 <kernel_dgecp_2_0_lib4+0x180>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dgecp_2_0_lib4>:
xor    %r10d,%r10d
cmp    $0x1,%edi
sete   %r10b
add    %esi,%r10d
test   %r10d,%r10d
jle    125b <kernel_dgecp_2_0_lib4+0x15b>
xor    %esi,%esi
cmp    $0x4,%r10d
jb     118e <kernel_dgecp_2_0_lib4+0x8e>
lea    -0x3(%r10),%r8d
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rdx),%xmm0
movsd  %xmm0,(%rcx)
movsd  0x8(%rdx),%xmm0
movsd  %xmm0,0x8(%rcx)
movsd  0x20(%rdx),%xmm0
movsd  %xmm0,0x20(%rcx)
movsd  0x28(%rdx),%xmm0
movsd  %xmm0,0x28(%rcx)
movsd  0x40(%rdx),%xmm0
movsd  %xmm0,0x40(%rcx)
movsd  0x48(%rdx),%xmm0
movsd  %xmm0,0x48(%rcx)
movsd  0x60(%rdx),%xmm0
movsd  %xmm0,0x60(%rcx)
movsd  0x68(%rdx),%xmm0
movsd  %xmm0,0x68(%rcx)
sub    $0xffffffffffffff80,%rdx
sub    $0xffffffffffffff80,%rcx
add    $0x4,%esi
cmp    %r8d,%esi
jl     1130 <kernel_dgecp_2_0_lib4+0x30>
cmp    %r10d,%esi
jge    124c <kernel_dgecp_2_0_lib4+0x14c>
mov    %r10d,%r9d
sub    %esi,%r9d
mov    %esi,%r8d
not    %r8d
add    %r10d,%r8d
and    $0x3,%r9d
je     11e4 <kernel_dgecp_2_0_lib4+0xe4>
neg    %r9d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdx),%xmm0
movsd  %xmm0,(%rcx)
movsd  0x8(%rdx),%xmm0
movsd  %xmm0,0x8(%rcx)
add    $0x20,%rdx
add    $0x20,%rcx
add    $0xffffffff,%eax
cmp    %eax,%r9d
jne    11c0 <kernel_dgecp_2_0_lib4+0xc0>
sub    %eax,%esi
cmp    $0x3,%r8d
jb     124c <kernel_dgecp_2_0_lib4+0x14c>
sub    %esi,%r10d
nopl   (%rax)
movsd  (%rdx),%xmm0
movsd  %xmm0,(%rcx)
movsd  0x8(%rdx),%xmm0
movsd  %xmm0,0x8(%rcx)
movsd  0x20(%rdx),%xmm0
movsd  %xmm0,0x20(%rcx)
movsd  0x28(%rdx),%xmm0
movsd  %xmm0,0x28(%rcx)
movsd  0x40(%rdx),%xmm0
movsd  %xmm0,0x40(%rcx)
movsd  0x48(%rdx),%xmm0
movsd  %xmm0,0x48(%rcx)
movsd  0x60(%rdx),%xmm0
movsd  %xmm0,0x60(%rcx)
movsd  0x68(%rdx),%xmm0
movsd  %xmm0,0x68(%rcx)
sub    $0xffffffffffffff80,%rdx
sub    $0xffffffffffffff80,%rcx
add    $0xfffffffc,%r10d
jne    11f0 <kernel_dgecp_2_0_lib4+0xf0>
cmp    $0x1,%edi
jne    125b <kernel_dgecp_2_0_lib4+0x15b>
movsd  0x8(%rdx),%xmm0
movsd  %xmm0,0x8(%rcx)
ret

LLVM IR (-O0):
define void @kernel_dgecp_2_0_lib4(i32 %0, i32 %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
br label %16
16: ; preds = %13, %4
%17 = load i32, i32* %6
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
br label %106
20: ; preds = %16
store i32 4, i32* %9
store i32 0, i32* %10
br label %21
21: ; preds = %71, %20
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 3
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %74
26: ; preds = %21
%27 = load double*, double** %7
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double, double* %28
%30 = load double*, double** %8
%31 = getelementptr inbounds double, double* %30, i64 0
store double %29, double* %31
%32 = load double*, double** %7
%33 = getelementptr inbounds double, double* %32, i64 1
%34 = load double, double* %33
%35 = load double*, double** %8
%36 = getelementptr inbounds double, double* %35, i64 1
store double %34, double* %36
%37 = load double*, double** %7
%38 = getelementptr inbounds double, double* %37, i64 4
%39 = load double, double* %38
%40 = load double*, double** %8
%41 = getelementptr inbounds double, double* %40, i64 4
store double %39, double* %41
%42 = load double*, double** %7
%43 = getelementptr inbounds double, double* %42, i64 5
%44 = load double, double* %43
%45 = load double*, double** %8
%46 = getelementptr inbounds double, double* %45, i64 5
store double %44, double* %46
%47 = load double*, double** %7
%48 = getelementptr inbounds double, double* %47, i64 8
%49 = load double, double* %48
%50 = load double*, double** %8
%51 = getelementptr inbounds double, double* %50, i64 8
store double %49, double* %51
%52 = load double*, double** %7
%53 = getelementptr inbounds double, double* %52, i64 9
%54 = load double, double* %53
%55 = load double*, double** %8
%56 = getelementptr inbounds double, double* %55, i64 9
store double %54, double* %56
%57 = load double*, double** %7
%58 = getelementptr inbounds double, double* %57, i64 12
%59 = load double, double* %58
%60 = load double*, double** %8
%61 = getelementptr inbounds double, double* %60, i64 12
store double %59, double* %61
%62 = load double*, double** %7
%63 = getelementptr inbounds double, double* %62, i64 13
%64 = load double, double* %63
%65 = load double*, double** %8
%66 = getelementptr inbounds double, double* %65, i64 13
store double %64, double* %66
%67 = load double*, double** %7
%68 = getelementptr inbounds double, double* %67, i64 16
store double* %68, double** %7
%69 = load double*, double** %8
%70 = getelementptr inbounds double, double* %69, i64 16
store double* %70, double** %8
br label %71
71: ; preds = %26
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 4
store i32 %73, i32* %10
br label %21
74: ; preds = %21
br label %75
75: ; preds = %94, %74
%76 = load i32, i32* %10
%77 = load i32, i32* %6
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %97
79: ; preds = %75
%80 = load double*, double** %7
%81 = getelementptr inbounds double, double* %80, i64 0
%82 = load double, double* %81
%83 = load double*, double** %8
%84 = getelementptr inbounds double, double* %83, i64 0
store double %82, double* %84
%85 = load double*, double** %7
%86 = getelementptr inbounds double, double* %85, i64 1
%87 = load double, double* %86
%88 = load double*, double** %8
%89 = getelementptr inbounds double, double* %88, i64 1
store double %87, double* %89
%90 = load double*, double** %7
%91 = getelementptr inbounds double, double* %90, i64 4
store double* %91, double** %7
%92 = load double*, double** %8
%93 = getelementptr inbounds double, double* %92, i64 4
store double* %93, double** %8
br label %94
94: ; preds = %79
%95 = load i32, i32* %10
%96 = add nsw i32 %95, 1
store i32 %96, i32* %10
br label %75
97: ; preds = %75
%98 = load i32, i32* %5
%99 = icmp eq i32 %98, 1
br i1 %99, label %100, label %106
100: ; preds = %97
%101 = load double*, double** %7
%102 = getelementptr inbounds double, double* %101, i64 1
%103 = load double, double* %102
%104 = load double*, double** %8
%105 = getelementptr inbounds double, double* %104, i64 1
store double %103, double* %105
br label %106
106: ; preds = %19, %100, %97
ret void
}

LLVM IR (-O2):
define void @kernel_dgecp_2_0_lib4(i32 %0, i32 %1, double* nocapture %2, double* nocapture writeonly %3) {
%5 = icmp eq i32 %0, 1
%6 = zext i1 %5 to i32
%7 = add i32 %6, %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %112, label %9
9: ; preds = %4
%10 = add nsw i32 %7, -3
%11 = icmp ugt i32 %7, 3
br i1 %11, label %45, label %12
12: ; preds = %45, %9
%13 = phi double* [ %2, %9 ], [ %71, %45 ]
%14 = phi double* [ %3, %9 ], [ %72, %45 ]
%15 = phi i32 [ 0, %9 ], [ %73, %45 ]
%16 = icmp slt i32 %15, %7
br i1 %16, label %17, label %105
17: ; preds = %12
%18 = add i32 %6, %1
%19 = sub i32 %18, %15
%20 = xor i32 %15, -1
%21 = add i32 %18, %20
%22 = and i32 %19, 3
%23 = icmp eq i32 %22, 0
br i1 %23, label %38, label %24
24: ; preds = %17, %24
%25 = phi i32 [ %35, %24 ], [ %15, %17 ]
%26 = phi double* [ %34, %24 ], [ %14, %17 ]
%27 = phi double* [ %33, %24 ], [ %13, %17 ]
%28 = phi i32 [ %36, %24 ], [ 0, %17 ]
%29 = load double, double* %27
store double %29, double* %26
%30 = getelementptr inbounds double, double* %27, i64 1
%31 = load double, double* %30
%32 = getelementptr inbounds double, double* %26, i64 1
store double %31, double* %32
%33 = getelementptr inbounds double, double* %27, i64 4
%34 = getelementptr inbounds double, double* %26, i64 4
%35 = add nuw nsw i32 %25, 1
%36 = add i32 %28, 1
%37 = icmp eq i32 %36, %22
br i1 %37, label %38, label %24
38: ; preds = %24, %17
%39 = phi double* [ undef, %17 ], [ %33, %24 ]
%40 = phi double* [ undef, %17 ], [ %34, %24 ]
%41 = phi i32 [ %15, %17 ], [ %35, %24 ]
%42 = phi double* [ %14, %17 ], [ %34, %24 ]
%43 = phi double* [ %13, %17 ], [ %33, %24 ]
%44 = icmp ult i32 %21, 3
br i1 %44, label %105, label %75
45: ; preds = %9, %45
%46 = phi i32 [ %73, %45 ], [ 0, %9 ]
%47 = phi double* [ %72, %45 ], [ %3, %9 ]
%48 = phi double* [ %71, %45 ], [ %2, %9 ]
%49 = load double, double* %48
store double %49, double* %47
%50 = getelementptr inbounds double, double* %48, i64 1
%51 = load double, double* %50
%52 = getelementptr inbounds double, double* %47, i64 1
store double %51, double* %52
%53 = getelementptr inbounds double, double* %48, i64 4
%54 = load double, double* %53
%55 = getelementptr inbounds double, double* %47, i64 4
store double %54, double* %55
%56 = getelementptr inbounds double, double* %48, i64 5
%57 = load double, double* %56
%58 = getelementptr inbounds double, double* %47, i64 5
store double %57, double* %58
%59 = getelementptr inbounds double, double* %48, i64 8
%60 = load double, double* %59
%61 = getelementptr inbounds double, double* %47, i64 8
store double %60, double* %61
%62 = getelementptr inbounds double, double* %48, i64 9
%63 = load double, double* %62
%64 = getelementptr inbounds double, double* %47, i64 9
store double %63, double* %64
%65 = getelementptr inbounds double, double* %48, i64 12
%66 = load double, double* %65
%67 = getelementptr inbounds double, double* %47, i64 12
store double %66, double* %67
%68 = getelementptr inbounds double, double* %48, i64 13
%69 = load double, double* %68
%70 = getelementptr inbounds double, double* %47, i64 13
store double %69, double* %70
%71 = getelementptr inbounds double, double* %48, i64 16
%72 = getelementptr inbounds double, double* %47, i64 16
%73 = add nuw nsw i32 %46, 4
%74 = icmp slt i32 %73, %10
br i1 %74, label %45, label %12
75: ; preds = %38, %75
%76 = phi i32 [ %103, %75 ], [ %41, %38 ]
%77 = phi double* [ %102, %75 ], [ %42, %38 ]
%78 = phi double* [ %101, %75 ], [ %43, %38 ]
%79 = load double, double* %78
store double %79, double* %77
%80 = getelementptr inbounds double, double* %78, i64 1
%81 = load double, double* %80
%82 = getelementptr inbounds double, double* %77, i64 1
store double %81, double* %82
%83 = getelementptr inbounds double, double* %78, i64 4
%84 = getelementptr inbounds double, double* %77, i64 4
%85 = load double, double* %83
store double %85, double* %84
%86 = getelementptr inbounds double, double* %78, i64 5
%87 = load double, double* %86
%88 = getelementptr inbounds double, double* %77, i64 5
store double %87, double* %88
%89 = getelementptr inbounds double, double* %78, i64 8
%90 = getelementptr inbounds double, double* %77, i64 8
%91 = load double, double* %89
store double %91, double* %90
%92 = getelementptr inbounds double, double* %78, i64 9
%93 = load double, double* %92
%94 = getelementptr inbounds double, double* %77, i64 9
store double %93, double* %94
%95 = getelementptr inbounds double, double* %78, i64 12
%96 = getelementptr inbounds double, double* %77, i64 12
%97 = load double, double* %95
store double %97, double* %96
%98 = getelementptr inbounds double, double* %78, i64 13
%99 = load double, double* %98
%100 = getelementptr inbounds double, double* %77, i64 13
store double %99, double* %100
%101 = getelementptr inbounds double, double* %78, i64 16
%102 = getelementptr inbounds double, double* %77, i64 16
%103 = add nuw nsw i32 %76, 4
%104 = icmp eq i32 %103, %7
br i1 %104, label %105, label %75
105: ; preds = %38, %75, %12
%106 = phi double* [ %13, %12 ], [ %39, %38 ], [ %101, %75 ]
%107 = phi double* [ %14, %12 ], [ %40, %38 ], [ %102, %75 ]
br i1 %5, label %108, label %112
108: ; preds = %105
%109 = getelementptr inbounds double, double* %106, i64 1
%110 = load double, double* %109
%111 = getelementptr inbounds double, double* %107, i64 1
store double %110, double* %111
br label %112
112: ; preds = %105, %108, %4
ret void
}