void kernel_dgead_2_3_lib4(int kmax, double alpha, 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] += alpha * A0[3 + bs * 0];
    B[1 + bs * 0] += alpha * A1[0 + bs * 0];
    B[0 + bs * 1] += alpha * A0[3 + bs * 1];
    B[1 + bs * 1] += alpha * A1[0 + bs * 1];
    B[0 + bs * 2] += alpha * A0[3 + bs * 2];
    B[1 + bs * 2] += alpha * A1[0 + bs * 2];
    B[0 + bs * 3] += alpha * A0[3 + bs * 3];
    B[1 + bs * 3] += alpha * A1[0 + bs * 3];
    A0 += 16;
    A1 += 16;
    B += 16;
  }
  for (; k < kmax; k++) {
    B[0 + bs * 0] += alpha * A0[3 + bs * 0];
    B[1 + bs * 0] += alpha * A1[0 + bs * 0];
    A0 += 4;
    A1 += 4;
    B += 4;
  }
}


x86 assembly (clang, -O0):
<kernel_dgead_2_3_lib4>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1126 <kernel_dgead_2_3_lib4+0x26>
jmp    133a <kernel_dgead_2_3_lib4+0x23a>
movl   $0x4,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    12b2 <kernel_dgead_2_3_lib4+0x1b2>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x38(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x20(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  0x20(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x28(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x28(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x58(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x40(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x40(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  0x40(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x48(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x48(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x78(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x60(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x60(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  0x60(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x68(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x68(%rax)
mov    -0x18(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x3c(%rbp)
jmp    114c <kernel_dgead_2_3_lib4+0x4c>
jmp    12b7 <kernel_dgead_2_3_lib4+0x1b7>
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    133a <kernel_dgead_2_3_lib4+0x23a>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x28(%rbp),%rax
movsd  0x8(%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x28(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12b7 <kernel_dgead_2_3_lib4+0x1b7>
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dgead_2_3_lib4>:
test   %edi,%edi
jle    129e <kernel_dgead_2_3_lib4+0x19e>
shl    $0x2,%edx
movslq %edx,%rax
cmp    $0x4,%edi
jb     11df <kernel_dgead_2_3_lib4+0xdf>
lea    -0x3(%rdi),%r8d
xor    %edx,%edx
nopl   (%rax)
movsd  0x18(%rsi),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rcx),%xmm1
movsd  %xmm1,(%rcx)
movsd  (%rsi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rcx),%xmm1
movsd  %xmm1,0x8(%rcx)
movsd  0x38(%rsi),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x20(%rcx),%xmm1
movsd  %xmm1,0x20(%rcx)
movsd  0x20(%rsi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x28(%rcx),%xmm1
movsd  %xmm1,0x28(%rcx)
movsd  0x58(%rsi),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x40(%rcx),%xmm1
movsd  %xmm1,0x40(%rcx)
movsd  0x40(%rsi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x48(%rcx),%xmm1
movsd  %xmm1,0x48(%rcx)
movsd  0x78(%rsi),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x60(%rcx),%xmm1
movsd  %xmm1,0x60(%rcx)
movsd  0x60(%rsi,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x68(%rcx),%xmm1
movsd  %xmm1,0x68(%rcx)
sub    $0xffffffffffffff80,%rsi
sub    $0xffffffffffffff80,%rcx
add    $0x4,%edx
cmp    %r8d,%edx
jl     1120 <kernel_dgead_2_3_lib4+0x20>
mov    %edi,%edx
and    $0xfffffffc,%edx
lea    (%rsi,%rax,8),%rax
cmp    %edi,%edx
jl     11ed <kernel_dgead_2_3_lib4+0xed>
jmp    129e <kernel_dgead_2_3_lib4+0x19e>
lea    (%rsi,%rax,8),%rax
xor    %edx,%edx
cmp    %edi,%edx
jge    129e <kernel_dgead_2_3_lib4+0x19e>
mov    %edx,%r8d
not    %r8d
test   $0x1,%dil
je     122b <kernel_dgead_2_3_lib4+0x12b>
movsd  0x18(%rsi),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rcx),%xmm1
movsd  %xmm1,(%rcx)
movsd  (%rax),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rcx),%xmm1
movsd  %xmm1,0x8(%rcx)
add    $0x20,%rsi
add    $0x20,%rax
add    $0x20,%rcx
or     $0x1,%edx
add    %edi,%r8d
je     129e <kernel_dgead_2_3_lib4+0x19e>
sub    %edx,%edi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x18(%rsi,%rdx,1),%xmm1
mulsd  %xmm0,%xmm1
addsd  (%rcx,%rdx,1),%xmm1
movsd  %xmm1,(%rcx,%rdx,1)
movsd  (%rax,%rdx,1),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x8(%rcx,%rdx,1),%xmm1
movsd  %xmm1,0x8(%rcx,%rdx,1)
movsd  0x38(%rsi,%rdx,1),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x20(%rcx,%rdx,1),%xmm1
movsd  %xmm1,0x20(%rcx,%rdx,1)
movsd  0x20(%rax,%rdx,1),%xmm1
mulsd  %xmm0,%xmm1
addsd  0x28(%rcx,%rdx,1),%xmm1
movsd  %xmm1,0x28(%rcx,%rdx,1)
add    $0x40,%rdx
add    $0xfffffffe,%edi
jne    1240 <kernel_dgead_2_3_lib4+0x140>
ret

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

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