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;
  __builtin_prefetch(A);
  k = 0;
  for (; k < ka - bs + 1; k += bs) {
    __builtin_prefetch(A + sda * 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    1326 <kernel_dgemv_t_1_lib4+0x226>
movl   $0x4,-0x34(%rbp)
movl   $0x4,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
prefetcht0 (%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x40(%rbp),%ecx
sub    $0x4,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1269 <kernel_dgemv_t_1_lib4+0x169>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
prefetcht0 (%rax)
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    1156 <kernel_dgemv_t_1_lib4+0x56>
jmp    126e <kernel_dgemv_t_1_lib4+0x16e>
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    12cc <kernel_dgemv_t_1_lib4+0x1cc>
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    126e <kernel_dgemv_t_1_lib4+0x16e>
cmpl   $0x0,0x10(%rbp)
jne    12e8 <kernel_dgemv_t_1_lib4+0x1e8>
movsd  -0x68(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1326 <kernel_dgemv_t_1_lib4+0x226>
cmpl   $0x1,0x10(%rbp)
jne    130c <kernel_dgemv_t_1_lib4+0x20c>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
addsd  -0x68(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1321 <kernel_dgemv_t_1_lib4+0x221>
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
subsd  -0x68(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1326 <kernel_dgemv_t_1_lib4+0x226>
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>
prefetcht0 (%rsi)
cmp    $0x4,%edi
jb     1180 <kernel_dgemv_t_1_lib4+0x80>
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)
nop
prefetcht0 (%rsi,%rdx,1)
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
movsd  0x18(%rsi),%xmm0
add    %rdx,%rsi
addsd  %xmm2,%xmm1
mulsd  0x18(%rcx),%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rcx
add    $0x4,%eax
cmp    %r10d,%eax
jl     1130 <kernel_dgemv_t_1_lib4+0x30>
mov    %edi,%edx
and    $0xfffffffc,%edx
jmp    1186 <kernel_dgemv_t_1_lib4+0x86>
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
nopw   0x0(%rax,%rax,1)
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 %139
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
%29 = load double*, double** %9
%30 = bitcast double* %29 to i8*
store i32 0, i32* %17
br label %31
31: ; preds = %87, %27
%32 = load i32, i32* %17
%33 = load i32, i32* %18
%34 = sub nsw i32 %33, 4
%35 = add nsw i32 %34, 1
%36 = icmp slt i32 %32, %35
br i1 %36, label %37, label %90
37: ; preds = %31
%38 = load double*, double** %9
%39 = load i32, i32* %10
%40 = mul nsw i32 %39, 4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %38, i64 %41
%43 = bitcast double* %42 to i8*
%44 = load double*, double** %11
%45 = getelementptr inbounds double, double* %44, i64 0
%46 = load double, double* %45
store double %46, double* %19
%47 = load double*, double** %11
%48 = getelementptr inbounds double, double* %47, i64 1
%49 = load double, double* %48
store double %49, double* %20
%50 = load double*, double** %11
%51 = getelementptr inbounds double, double* %50, i64 2
%52 = load double, double* %51
store double %52, double* %21
%53 = load double*, double** %11
%54 = getelementptr inbounds double, double* %53, i64 3
%55 = load double, double* %54
store double %55, double* %22
%56 = load double*, double** %9
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
%59 = load double, double* %19
%60 = load double, double* %23
%61 = call double @llvm.fmuladd.f64(double %58, double %59, double %60)
store double %61, double* %23
%62 = load double*, double** %9
%63 = getelementptr inbounds double, double* %62, i64 1
%64 = load double, double* %63
%65 = load double, double* %20
%66 = load double, double* %23
%67 = call double @llvm.fmuladd.f64(double %64, double %65, double %66)
store double %67, double* %23
%68 = load double*, double** %9
%69 = getelementptr inbounds double, double* %68, i64 2
%70 = load double, double* %69
%71 = load double, double* %21
%72 = load double, double* %23
%73 = call double @llvm.fmuladd.f64(double %70, double %71, double %72)
store double %73, double* %23
%74 = load double*, double** %9
%75 = getelementptr inbounds double, double* %74, i64 3
%76 = load double, double* %75
%77 = load double, double* %22
%78 = load double, double* %23
%79 = call double @llvm.fmuladd.f64(double %76, double %77, double %78)
store double %79, double* %23
%80 = load i32, i32* %10
%81 = mul nsw i32 %80, 4
%82 = load double*, double** %9
%83 = sext i32 %81 to i64
%84 = getelementptr inbounds double, double* %82, i64 %83
store double* %84, double** %9
%85 = load double*, double** %11
%86 = getelementptr inbounds double, double* %85, i64 4
store double* %86, double** %11
br label %87
87: ; preds = %37
%88 = load i32, i32* %17
%89 = add nsw i32 %88, 4
store i32 %89, i32* %17
br label %31
90: ; preds = %31
br label %91
91: ; preds = %109, %90
%92 = load i32, i32* %17
%93 = load i32, i32* %18
%94 = icmp slt i32 %92, %93
br i1 %94, label %95, label %112
95: ; preds = %91
%96 = load double*, double** %11
%97 = getelementptr inbounds double, double* %96, i64 0
%98 = load double, double* %97
store double %98, double* %19
%99 = load double*, double** %9
%100 = getelementptr inbounds double, double* %99, i64 0
%101 = load double, double* %100
%102 = load double, double* %19
%103 = load double, double* %23
%104 = call double @llvm.fmuladd.f64(double %101, double %102, double %103)
store double %104, double* %23
%105 = load double*, double** %9
%106 = getelementptr inbounds double, double* %105, i64 1
store double* %106, double** %9
%107 = load double*, double** %11
%108 = getelementptr inbounds double, double* %107, i64 1
store double* %108, double** %11
br label %109
109: ; preds = %95
%110 = load i32, i32* %17
%111 = add nsw i32 %110, 1
store i32 %111, i32* %17
br label %91
112: ; preds = %91
%113 = load i32, i32* %14
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %119
115: ; preds = %112
%116 = load double, double* %23
%117 = load double*, double** %12
%118 = getelementptr inbounds double, double* %117, i64 0
store double %116, double* %118
br label %139
119: ; preds = %112
%120 = load i32, i32* %14
%121 = icmp eq i32 %120, 1
br i1 %121, label %122, label %130
122: ; preds = %119
%123 = load double*, double** %12
%124 = getelementptr inbounds double, double* %123, i64 0
%125 = load double, double* %124
%126 = load double, double* %23
%127 = fadd double %125, %126
%128 = load double*, double** %13
%129 = getelementptr inbounds double, double* %128, i64 0
store double %127, double* %129
br label %138
130: ; preds = %119
%131 = load double*, double** %12
%132 = getelementptr inbounds double, double* %131, i64 0
%133 = load double, double* %132
%134 = load double, double* %23
%135 = fsub double %133, %134
%136 = load double*, double** %13
%137 = getelementptr inbounds double, double* %136, i64 0
store double %135, double* %137
br label %138
138: ; preds = %130, %122
br label %139
139: ; preds = %26, %138, %115
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 %114, label %9
9: ; preds = %7
%10 = bitcast double* %1 to i8*
tail call void @llvm.prefetch.p0i8(i8* %10, i32 0, i32 3, i32 1)
%11 = add nsw i32 %0, -3
%12 = icmp ugt i32 %0, 3
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = shl nsw i32 %2, 2
%15 = sext i32 %14 to i64
br label %50
16: ; preds = %50
%17 = and i32 %0, -4
br label %18
18: ; preds = %16, %9
%19 = phi i32 [ 0, %9 ], [ %17, %16 ]
%20 = phi double* [ %3, %9 ], [ %75, %16 ]
%21 = phi double* [ %1, %9 ], [ %55, %16 ]
%22 = phi double [ 0.000000e+00, %9 ], [ %74, %16 ]
%23 = icmp slt i32 %19, %0
br i1 %23, label %24, label %105
24: ; preds = %18
%25 = xor i32 %19, -1
%26 = add i32 %25, %0
%27 = and i32 %0, 3
%28 = icmp eq i32 %27, 0
br i1 %28, label %43, label %29
29: ; preds = %24, %29
%30 = phi double [ %37, %29 ], [ %22, %24 ]
%31 = phi double* [ %38, %29 ], [ %21, %24 ]
%32 = phi double* [ %39, %29 ], [ %20, %24 ]
%33 = phi i32 [ %40, %29 ], [ %19, %24 ]
%34 = phi i32 [ %41, %29 ], [ 0, %24 ]
%35 = load double, double* %32
%36 = load double, double* %31
%37 = tail call double @llvm.fmuladd.f64(double %36, double %35, double %30)
%38 = getelementptr inbounds double, double* %31, i64 1
%39 = getelementptr inbounds double, double* %32, i64 1
%40 = add nuw nsw i32 %33, 1
%41 = add i32 %34, 1
%42 = icmp eq i32 %41, %27
br i1 %42, label %43, label %29
43: ; preds = %29, %24
%44 = phi double [ undef, %24 ], [ %37, %29 ]
%45 = phi double [ %22, %24 ], [ %37, %29 ]
%46 = phi double* [ %21, %24 ], [ %38, %29 ]
%47 = phi double* [ %20, %24 ], [ %39, %29 ]
%48 = phi i32 [ %19, %24 ], [ %40, %29 ]
%49 = icmp ult i32 %26, 3
br i1 %49, label %105, label %78
50: ; preds = %13, %50
%51 = phi double [ 0.000000e+00, %13 ], [ %74, %50 ]
%52 = phi double* [ %1, %13 ], [ %55, %50 ]
%53 = phi double* [ %3, %13 ], [ %75, %50 ]
%54 = phi i32 [ 0, %13 ], [ %76, %50 ]
%55 = getelementptr inbounds double, double* %52, i64 %15
%56 = bitcast double* %55 to i8*
tail call void @llvm.prefetch.p0i8(i8* %56, i32 0, i32 3, i32 1)
%57 = load double, double* %53
%58 = getelementptr inbounds double, double* %53, i64 1
%59 = load double, double* %58
%60 = getelementptr inbounds double, double* %53, i64 2
%61 = load double, double* %60
%62 = getelementptr inbounds double, double* %53, i64 3
%63 = load double, double* %62
%64 = load double, double* %52
%65 = tail call double @llvm.fmuladd.f64(double %64, double %57, double %51)
%66 = getelementptr inbounds double, double* %52, i64 1
%67 = load double, double* %66
%68 = tail call double @llvm.fmuladd.f64(double %67, double %59, double %65)
%69 = getelementptr inbounds double, double* %52, i64 2
%70 = load double, double* %69
%71 = tail call double @llvm.fmuladd.f64(double %70, double %61, double %68)
%72 = getelementptr inbounds double, double* %52, i64 3
%73 = load double, double* %72
%74 = tail call double @llvm.fmuladd.f64(double %73, double %63, double %71)
%75 = getelementptr inbounds double, double* %53, i64 4
%76 = add nuw nsw i32 %54, 4
%77 = icmp slt i32 %76, %11
br i1 %77, label %50, label %16
78: ; preds = %43, %78
%79 = phi double [ %100, %78 ], [ %45, %43 ]
%80 = phi double* [ %101, %78 ], [ %46, %43 ]
%81 = phi double* [ %102, %78 ], [ %47, %43 ]
%82 = phi i32 [ %103, %78 ], [ %48, %43 ]
%83 = load double, double* %81
%84 = load double, double* %80
%85 = tail call double @llvm.fmuladd.f64(double %84, double %83, double %79)
%86 = getelementptr inbounds double, double* %80, i64 1
%87 = getelementptr inbounds double, double* %81, i64 1
%88 = load double, double* %87
%89 = load double, double* %86
%90 = tail call double @llvm.fmuladd.f64(double %89, double %88, double %85)
%91 = getelementptr inbounds double, double* %80, i64 2
%92 = getelementptr inbounds double, double* %81, i64 2
%93 = load double, double* %92
%94 = load double, double* %91
%95 = tail call double @llvm.fmuladd.f64(double %94, double %93, double %90)
%96 = getelementptr inbounds double, double* %80, i64 3
%97 = getelementptr inbounds double, double* %81, i64 3
%98 = load double, double* %97
%99 = load double, double* %96
%100 = tail call double @llvm.fmuladd.f64(double %99, double %98, double %95)
%101 = getelementptr inbounds double, double* %80, i64 4
%102 = getelementptr inbounds double, double* %81, i64 4
%103 = add nuw nsw i32 %82, 4
%104 = icmp eq i32 %103, %0
br i1 %104, label %105, label %78
105: ; preds = %43, %78, %18
%106 = phi double [ %22, %18 ], [ %44, %43 ], [ %100, %78 ]
switch i32 %6, label %111 [
i32 0, label %107
i32 1, label %108
]
107: ; preds = %105
store double %106, double* %4
br label %114
108: ; preds = %105
%109 = load double, double* %4
%110 = fadd double %106, %109
store double %110, double* %5
br label %114
111: ; preds = %105
%112 = load double, double* %4
%113 = fsub double %112, %106
store double %113, double* %5
br label %114
114: ; preds = %107, %111, %108, %7
ret void
}