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


x86 assembly (clang, -O0):
<kernel_dgecp_2_3_lib4>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1128 <kernel_dgecp_2_3_lib4+0x28>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1137 <kernel_dgecp_2_3_lib4+0x37>
jmp    12b4 <kernel_dgecp_2_3_lib4+0x1b4>
movl   $0x4,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    1234 <kernel_dgecp_2_3_lib4+0x134>
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsd  0x38(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x20(%rax)
mov    -0x30(%rbp),%rax
movsd  0x20(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x28(%rax)
mov    -0x10(%rbp),%rax
movsd  0x58(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x40(%rax)
mov    -0x30(%rbp),%rax
movsd  0x40(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x48(%rax)
mov    -0x10(%rbp),%rax
movsd  0x78(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x60(%rax)
mov    -0x30(%rbp),%rax
movsd  0x60(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x68(%rax)
mov    -0x10(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x34(%rbp)
jmp    115d <kernel_dgecp_2_3_lib4+0x5d>
jmp    1239 <kernel_dgecp_2_3_lib4+0x139>
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1299 <kernel_dgecp_2_3_lib4+0x199>
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1239 <kernel_dgecp_2_3_lib4+0x139>
cmpl   $0x1,-0x4(%rbp)
jne    12b4 <kernel_dgecp_2_3_lib4+0x1b4>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dgecp_2_3_lib4>:
xor    %r11d,%r11d
cmp    $0x1,%edi
sete   %r11b
add    %esi,%r11d
test   %r11d,%r11d
jle    1296 <kernel_dgecp_2_3_lib4+0x196>
shl    $0x2,%ecx
movslq %ecx,%rcx
cmp    $0x4,%r11d
jb     11a8 <kernel_dgecp_2_3_lib4+0xa8>
lea    -0x3(%r11),%r9d
xor    %esi,%esi
nopl   0x0(%rax)
movsd  0x18(%rdx),%xmm0
movsd  %xmm0,(%r8)
movsd  (%rdx,%rcx,8),%xmm0
movsd  %xmm0,0x8(%r8)
movsd  0x38(%rdx),%xmm0
movsd  %xmm0,0x20(%r8)
movsd  0x20(%rdx,%rcx,8),%xmm0
movsd  %xmm0,0x28(%r8)
movsd  0x58(%rdx),%xmm0
movsd  %xmm0,0x40(%r8)
movsd  0x40(%rdx,%rcx,8),%xmm0
movsd  %xmm0,0x48(%r8)
movsd  0x78(%rdx),%xmm0
movsd  %xmm0,0x60(%r8)
movsd  0x60(%rdx,%rcx,8),%xmm0
movsd  %xmm0,0x68(%r8)
sub    $0xffffffffffffff80,%rdx
sub    $0xffffffffffffff80,%r8
add    $0x4,%esi
cmp    %r9d,%esi
jl     1130 <kernel_dgecp_2_3_lib4+0x30>
lea    (%rdx,%rcx,8),%rcx
cmp    %r11d,%esi
jl     11b7 <kernel_dgecp_2_3_lib4+0xb7>
jmp    1287 <kernel_dgecp_2_3_lib4+0x187>
lea    (%rdx,%rcx,8),%rcx
xor    %esi,%esi
cmp    %r11d,%esi
jge    1287 <kernel_dgecp_2_3_lib4+0x187>
mov    %r11d,%r10d
sub    %esi,%r10d
mov    %esi,%r9d
not    %r9d
add    %r11d,%r9d
and    $0x3,%r10d
je     120a <kernel_dgecp_2_3_lib4+0x10a>
neg    %r10d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0x18(%rdx),%xmm0
movsd  %xmm0,(%r8)
movsd  (%rcx),%xmm0
movsd  %xmm0,0x8(%r8)
add    $0x20,%rdx
add    $0x20,%rcx
add    $0x20,%r8
add    $0xffffffff,%eax
cmp    %eax,%r10d
jne    11e0 <kernel_dgecp_2_3_lib4+0xe0>
sub    %eax,%esi
cmp    $0x3,%r9d
jb     1287 <kernel_dgecp_2_3_lib4+0x187>
sub    %esi,%r11d
add    $0x78,%rdx
nopw   0x0(%rax,%rax,1)
movsd  -0x60(%rdx),%xmm0
movsd  %xmm0,(%r8)
movsd  (%rcx),%xmm0
movsd  %xmm0,0x8(%r8)
movsd  -0x40(%rdx),%xmm0
movsd  %xmm0,0x20(%r8)
movsd  0x20(%rcx),%xmm0
movsd  %xmm0,0x28(%r8)
movsd  -0x20(%rdx),%xmm0
movsd  %xmm0,0x40(%r8)
movsd  0x40(%rcx),%xmm0
movsd  %xmm0,0x48(%r8)
movsd  (%rdx),%xmm0
movsd  %xmm0,0x60(%r8)
movsd  0x60(%rcx),%xmm0
movsd  %xmm0,0x68(%r8)
sub    $0xffffffffffffff80,%rcx
sub    $0xffffffffffffff80,%r8
sub    $0xffffffffffffff80,%rdx
add    $0xfffffffc,%r11d
jne    1220 <kernel_dgecp_2_3_lib4+0x120>
cmp    $0x1,%edi
jne    1296 <kernel_dgecp_2_3_lib4+0x196>
movsd  (%rcx),%xmm0
movsd  %xmm0,0x8(%r8)
ret

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

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