void kernel_align_panel_2_3_lib4(int kmax, double *A0, int sda, double *B) {
  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;
  }
}


x86 assembly (clang, -O0):
<kernel_align_panel_2_3_lib4>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1121 <kernel_align_panel_2_3_lib4+0x21>
jmp    1283 <kernel_align_panel_2_3_lib4+0x183>
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    -0x4(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    121e <kernel_align_panel_2_3_lib4+0x11e>
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    1147 <kernel_align_panel_2_3_lib4+0x47>
jmp    1223 <kernel_align_panel_2_3_lib4+0x123>
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1283 <kernel_align_panel_2_3_lib4+0x183>
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    1223 <kernel_align_panel_2_3_lib4+0x123>
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_align_panel_2_3_lib4>:
test   %edi,%edi
jle    1267 <kernel_align_panel_2_3_lib4+0x167>
shl    $0x2,%edx
movslq %edx,%rax
cmp    $0x4,%edi
jb     1197 <kernel_align_panel_2_3_lib4+0x97>
lea    -0x3(%rdi),%r8d
xor    %edx,%edx
nopl   (%rax)
movsd  0x18(%rsi),%xmm0
movsd  %xmm0,(%rcx)
movsd  (%rsi,%rax,8),%xmm0
movsd  %xmm0,0x8(%rcx)
movsd  0x38(%rsi),%xmm0
movsd  %xmm0,0x20(%rcx)
movsd  0x20(%rsi,%rax,8),%xmm0
movsd  %xmm0,0x28(%rcx)
movsd  0x58(%rsi),%xmm0
movsd  %xmm0,0x40(%rcx)
movsd  0x40(%rsi,%rax,8),%xmm0
movsd  %xmm0,0x48(%rcx)
movsd  0x78(%rsi),%xmm0
movsd  %xmm0,0x60(%rcx)
movsd  0x60(%rsi,%rax,8),%xmm0
movsd  %xmm0,0x68(%rcx)
sub    $0xffffffffffffff80,%rsi
sub    $0xffffffffffffff80,%rcx
add    $0x4,%edx
cmp    %r8d,%edx
jl     1120 <kernel_align_panel_2_3_lib4+0x20>
mov    %edi,%r9d
and    $0xfffffffc,%r9d
lea    (%rsi,%rax,8),%rax
cmp    %edi,%r9d
jl     11a7 <kernel_align_panel_2_3_lib4+0xa7>
jmp    1267 <kernel_align_panel_2_3_lib4+0x167>
lea    (%rsi,%rax,8),%rax
xor    %r9d,%r9d
cmp    %edi,%r9d
jge    1267 <kernel_align_panel_2_3_lib4+0x167>
mov    %r9d,%r8d
not    %r8d
add    %edi,%r8d
mov    %edi,%r10d
and    $0x3,%r10d
je     11e9 <kernel_align_panel_2_3_lib4+0xe9>
neg    %r10d
xor    %edx,%edx
xchg   %ax,%ax
movsd  0x18(%rsi),%xmm0
movsd  %xmm0,(%rcx)
movsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rcx)
add    $0x20,%rsi
add    $0x20,%rax
add    $0x20,%rcx
add    $0xffffffff,%edx
cmp    %edx,%r10d
jne    11c0 <kernel_align_panel_2_3_lib4+0xc0>
sub    %edx,%r9d
cmp    $0x3,%r8d
jb     1267 <kernel_align_panel_2_3_lib4+0x167>
sub    %r9d,%edi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x18(%rsi,%rdx,1),%xmm0
movsd  %xmm0,(%rcx,%rdx,1)
movsd  (%rax,%rdx,1),%xmm0
movsd  %xmm0,0x8(%rcx,%rdx,1)
movsd  0x38(%rsi,%rdx,1),%xmm0
movsd  %xmm0,0x20(%rcx,%rdx,1)
movsd  0x20(%rax,%rdx,1),%xmm0
movsd  %xmm0,0x28(%rcx,%rdx,1)
movsd  0x58(%rsi,%rdx,1),%xmm0
movsd  %xmm0,0x40(%rcx,%rdx,1)
movsd  0x40(%rax,%rdx,1),%xmm0
movsd  %xmm0,0x48(%rcx,%rdx,1)
movsd  0x78(%rsi,%rdx,1),%xmm0
movsd  %xmm0,0x60(%rcx,%rdx,1)
movsd  0x60(%rax,%rdx,1),%xmm0
movsd  %xmm0,0x68(%rcx,%rdx,1)
sub    $0xffffffffffffff80,%rdx
add    $0xfffffffc,%edi
jne    1200 <kernel_align_panel_2_3_lib4+0x100>
ret

LLVM IR (-O0):
define void @kernel_align_panel_2_3_lib4(i32 %0, double* %1, i32 %2, double* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
store i32 %0, i32* %5
store double* %1, double** %6
store i32 %2, i32* %7
store double* %3, double** %8
%12 = load i32, i32* %5
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %4
br label %101
15: ; preds = %4
store i32 4, i32* %9
%16 = load double*, double** %6
%17 = load i32, i32* %7
%18 = mul nsw i32 4, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %16, i64 %19
store double* %20, double** %10
store i32 0, i32* %11
br label %21
21: ; preds = %73, %15
%22 = load i32, i32* %11
%23 = load i32, i32* %5
%24 = sub nsw i32 %23, 3
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %76
26: ; preds = %21
%27 = load double*, double** %6
%28 = getelementptr inbounds double, double* %27, i64 3
%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** %10
%33 = getelementptr inbounds double, double* %32, i64 0
%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** %6
%38 = getelementptr inbounds double, double* %37, i64 7
%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** %10
%43 = getelementptr inbounds double, double* %42, i64 4
%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** %6
%48 = getelementptr inbounds double, double* %47, i64 11
%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** %10
%53 = getelementptr inbounds double, double* %52, i64 8
%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** %6
%58 = getelementptr inbounds double, double* %57, i64 15
%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** %10
%63 = getelementptr inbounds double, double* %62, i64 12
%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** %6
%68 = getelementptr inbounds double, double* %67, i64 16
store double* %68, double** %6
%69 = load double*, double** %10
%70 = getelementptr inbounds double, double* %69, i64 16
store double* %70, double** %10
%71 = load double*, double** %8
%72 = getelementptr inbounds double, double* %71, i64 16
store double* %72, double** %8
br label %73
73: ; preds = %26
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 4
store i32 %75, i32* %11
br label %21
76: ; preds = %21
br label %77
77: ; preds = %98, %76
%78 = load i32, i32* %11
%79 = load i32, i32* %5
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %101
81: ; preds = %77
%82 = load double*, double** %6
%83 = getelementptr inbounds double, double* %82, i64 3
%84 = load double, double* %83
%85 = load double*, double** %8
%86 = getelementptr inbounds double, double* %85, i64 0
store double %84, double* %86
%87 = load double*, double** %10
%88 = getelementptr inbounds double, double* %87, i64 0
%89 = load double, double* %88
%90 = load double*, double** %8
%91 = getelementptr inbounds double, double* %90, i64 1
store double %89, double* %91
%92 = load double*, double** %6
%93 = getelementptr inbounds double, double* %92, i64 4
store double* %93, double** %6
%94 = load double*, double** %10
%95 = getelementptr inbounds double, double* %94, i64 4
store double* %95, double** %10
%96 = load double*, double** %8
%97 = getelementptr inbounds double, double* %96, i64 4
store double* %97, double** %8
br label %98
98: ; preds = %81
%99 = load i32, i32* %11
%100 = add nsw i32 %99, 1
store i32 %100, i32* %11
br label %77
101: ; preds = %14, %77
ret void
}

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