void kernel_dgemv_t_1_lib4(int kmax, double *A, int sda, double *x, double *y,
                           double *z, int alg) {
  if (kmax <= 0)
    return;
  const int lda = 4;
  const int bs = 4;
  int k, ka = kmax;
  double x_0, x_1, x_2, x_3, y_0 = 0;
  k = 0;
  for (; k < ka - bs + 1; k += bs) {
    x_0 = x[0];
    x_1 = x[1];
    x_2 = x[2];
    x_3 = x[3];
    y_0 += A[0 + lda * 0] * x_0;
    y_0 += A[1 + lda * 0] * x_1;
    y_0 += A[2 + lda * 0] * x_2;
    y_0 += A[3 + lda * 0] * x_3;
    A += sda * bs;
    x += 4;
  }
  for (; k < ka; k++) {
    x_0 = x[0];
    y_0 += A[0 + lda * 0] * x_0;
    A += 1;
    x += 1;
  }
  if (alg == 0) {
    y[0] = y_0;
  } else if (alg == 1) {
    z[0] = y[0] + y_0;
  } else {
    z[0] = y[0] - y_0;
  }
}


x86 assembly (clang, -O0):
<kernel_dgemv_t_1_lib4>:
push   %rbp
mov    %rsp,%rbp
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     112c <kernel_dgemv_t_1_lib4+0x2c>
jmp    1308 <kernel_dgemv_t_1_lib4+0x208>
movl   $0x4,-0x34(%rbp)
movl   $0x4,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x40(%rbp),%ecx
sub    $0x4,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    124b <kernel_dgemv_t_1_lib4+0x14b>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x3c(%rbp)
jmp    114f <kernel_dgemv_t_1_lib4+0x4f>
jmp    1250 <kernel_dgemv_t_1_lib4+0x150>
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    12ae <kernel_dgemv_t_1_lib4+0x1ae>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1250 <kernel_dgemv_t_1_lib4+0x150>
cmpl   $0x0,0x10(%rbp)
jne    12ca <kernel_dgemv_t_1_lib4+0x1ca>
movsd  -0x68(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1308 <kernel_dgemv_t_1_lib4+0x208>
cmpl   $0x1,0x10(%rbp)
jne    12ee <kernel_dgemv_t_1_lib4+0x1ee>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x68(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1303 <kernel_dgemv_t_1_lib4+0x203>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
subsd  -0x68(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1308 <kernel_dgemv_t_1_lib4+0x208>
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dgemv_t_1_lib4>:
push   %rbx
test   %edi,%edi
jle    1252 <kernel_dgemv_t_1_lib4+0x152>
cmp    $0x4,%edi
jb     117c <kernel_dgemv_t_1_lib4+0x7c>
lea    -0x3(%rdi),%r10d
shl    $0x2,%edx
movslq %edx,%rdx
shl    $0x3,%rdx
xor    %eax,%eax
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%rsi),%xmm1
movsd  0x8(%rsi),%xmm2
mulsd  (%rcx),%xmm1
addsd  %xmm0,%xmm1
mulsd  0x8(%rcx),%xmm2
addsd  %xmm1,%xmm2
movsd  0x10(%rsi),%xmm1
mulsd  0x10(%rcx),%xmm1
addsd  %xmm2,%xmm1
movsd  0x18(%rsi),%xmm0
mulsd  0x18(%rcx),%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rcx
add    $0x4,%eax
add    %rdx,%rsi
cmp    %r10d,%eax
jl     1130 <kernel_dgemv_t_1_lib4+0x30>
mov    %edi,%edx
and    $0xfffffffc,%edx
jmp    1182 <kernel_dgemv_t_1_lib4+0x82>
xorpd  %xmm0,%xmm0
xor    %edx,%edx
mov    0x10(%rsp),%r10d
cmp    %edi,%edx
jge    1226 <kernel_dgemv_t_1_lib4+0x126>
mov    %edx,%r11d
not    %r11d
add    %edi,%r11d
mov    %edi,%eax
and    $0x3,%eax
je     11cd <kernel_dgemv_t_1_lib4+0xcd>
neg    %eax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rsi),%xmm1
mulsd  (%rcx),%xmm1
addsd  %xmm1,%xmm0
add    $0x8,%rsi
add    $0x8,%rcx
add    $0xffffffff,%ebx
cmp    %ebx,%eax
jne    11b0 <kernel_dgemv_t_1_lib4+0xb0>
sub    %ebx,%edx
cmp    $0x3,%r11d
jb     1226 <kernel_dgemv_t_1_lib4+0x126>
sub    %edx,%edi
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movsd  (%rsi,%rax,8),%xmm1
movsd  0x8(%rsi,%rax,8),%xmm2
mulsd  (%rcx,%rax,8),%xmm1
mulsd  0x8(%rcx,%rax,8),%xmm2
addsd  %xmm0,%xmm1
movsd  0x10(%rsi,%rax,8),%xmm3
mulsd  0x10(%rcx,%rax,8),%xmm3
addsd  %xmm1,%xmm2
movsd  0x18(%rsi,%rax,8),%xmm0
mulsd  0x18(%rcx,%rax,8),%xmm0
addsd  %xmm2,%xmm3
addsd  %xmm3,%xmm0
add    $0x4,%rax
cmp    %eax,%edi
jne    11e0 <kernel_dgemv_t_1_lib4+0xe0>
cmp    $0x1,%r10d
je     1238 <kernel_dgemv_t_1_lib4+0x138>
test   %r10d,%r10d
jne    1244 <kernel_dgemv_t_1_lib4+0x144>
movsd  %xmm0,(%r8)
pop    %rbx
ret
addsd  (%r8),%xmm0
movsd  %xmm0,(%r9)
pop    %rbx
ret
movsd  (%r8),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%r9)
pop    %rbx
ret

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

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