void kernel_dtrmv_u_t_1_lib4(int kmax, double *A, int sda, double *x, double *y,
                             int alg) {
  __builtin_prefetch(A);
  const int lda = 4;
  const int bs = 4;
  int k;
  double x_0, x_1, x_2, x_3, y_0 = 0;
  k = 0;
  for (; k < kmax - 3; k += 4) {
    __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;
  }
  if (k < kmax - 1) {
    x_0 = x[0];
    x_1 = x[1];
    y_0 += A[0 + lda * 0] * x_0;
    y_0 += A[1 + lda * 0] * x_1;
    A += 2;
    x += 2;
  }
  x_0 = x[0];
  y_0 += A[0 + lda * 0] * x_0;
  if (alg == 0) {
    y[0] = y_0;
  } else if (alg == 1) {
    y[0] += y_0;
  } else {
    y[0] -= y_0;
  }
}


x86 assembly (clang, -O0):
<kernel_dtrmv_u_t_1_lib4>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
prefetcht0 (%rax)
movl   $0x4,-0x30(%rbp)
movl   $0x4,-0x34(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    124e <kernel_dtrmv_u_t_1_lib4+0x14e>
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,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%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    -0x38(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x38(%rbp)
jmp    113e <kernel_dtrmv_u_t_1_lib4+0x3e>
mov    -0x38(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12d1 <kernel_dtrmv_u_t_1_lib4+0x1d1>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1319 <kernel_dtrmv_u_t_1_lib4+0x219>
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1353 <kernel_dtrmv_u_t_1_lib4+0x253>
cmpl   $0x1,-0x2c(%rbp)
jne    1339 <kernel_dtrmv_u_t_1_lib4+0x239>
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    134e <kernel_dtrmv_u_t_1_lib4+0x24e>
movsd  -0x60(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
jmp    1353 <kernel_dtrmv_u_t_1_lib4+0x253>
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dtrmv_u_t_1_lib4>:
prefetcht0 (%rsi)
cmp    $0x4,%edi
jl     1170 <kernel_dtrmv_u_t_1_lib4+0x70>
lea    -0x3(%rdi),%r10d
shl    $0x2,%edx
movslq %edx,%rdx
shl    $0x3,%rdx
xor    %eax,%eax
xorpd  %xmm0,%xmm0
nopl   0x0(%rax)
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     1120 <kernel_dtrmv_u_t_1_lib4+0x20>
mov    %edi,%eax
and    $0xfffffffc,%eax
jmp    1176 <kernel_dtrmv_u_t_1_lib4+0x76>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
add    $0xffffffff,%edi
cmp    %edi,%eax
jge    11a3 <kernel_dtrmv_u_t_1_lib4+0xa3>
movsd  (%rsi),%xmm1
movsd  0x8(%rsi),%xmm2
mulsd  (%rcx),%xmm1
mulsd  0x8(%rcx),%xmm2
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
add    $0x10,%rsi
add    $0x10,%rcx
movapd %xmm2,%xmm0
movsd  (%rsi),%xmm1
mulsd  (%rcx),%xmm1
addsd  %xmm0,%xmm1
test   %r9d,%r9d
je     11d2 <kernel_dtrmv_u_t_1_lib4+0xd2>
cmp    $0x1,%r9d
jne    11c5 <kernel_dtrmv_u_t_1_lib4+0xc5>
addsd  (%r8),%xmm1
movsd  %xmm1,(%r8)
ret
movsd  (%r8),%xmm0
subsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
movsd  %xmm1,(%r8)
ret

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

LLVM IR (-O2):
define void @kernel_dtrmv_u_t_1_lib4(i32 %0, double* nocapture %1, i32 %2, double* nocapture %3, double* nocapture %4, i32 %5) {
%7 = bitcast double* %1 to i8*
tail call void @llvm.prefetch.p0i8(i8* %7, i32 0, i32 3, i32 1)
%8 = add nsw i32 %0, -3
%9 = icmp sgt i32 %0, 3
br i1 %9, label %10, label %43
10: ; preds = %6
%11 = shl nsw i32 %2, 2
%12 = sext i32 %11 to i64
br label %13
13: ; preds = %10, %13
%14 = phi double [ 0.000000e+00, %10 ], [ %37, %13 ]
%15 = phi double* [ %1, %10 ], [ %18, %13 ]
%16 = phi double* [ %3, %10 ], [ %38, %13 ]
%17 = phi i32 [ 0, %10 ], [ %39, %13 ]
%18 = getelementptr inbounds double, double* %15, i64 %12
%19 = bitcast double* %18 to i8*
tail call void @llvm.prefetch.p0i8(i8* %19, i32 0, i32 3, i32 1)
%20 = load double, double* %16
%21 = getelementptr inbounds double, double* %16, i64 1
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %16, i64 2
%24 = load double, double* %23
%25 = getelementptr inbounds double, double* %16, i64 3
%26 = load double, double* %25
%27 = load double, double* %15
%28 = tail call double @llvm.fmuladd.f64(double %27, double %20, double %14)
%29 = getelementptr inbounds double, double* %15, i64 1
%30 = load double, double* %29
%31 = tail call double @llvm.fmuladd.f64(double %30, double %22, double %28)
%32 = getelementptr inbounds double, double* %15, i64 2
%33 = load double, double* %32
%34 = tail call double @llvm.fmuladd.f64(double %33, double %24, double %31)
%35 = getelementptr inbounds double, double* %15, i64 3
%36 = load double, double* %35
%37 = tail call double @llvm.fmuladd.f64(double %36, double %26, double %34)
%38 = getelementptr inbounds double, double* %16, i64 4
%39 = add nuw nsw i32 %17, 4
%40 = icmp slt i32 %39, %8
br i1 %40, label %13, label %41
41: ; preds = %13
%42 = and i32 %0, -4
br label %43
43: ; preds = %41, %6
%44 = phi i32 [ 0, %6 ], [ %42, %41 ]
%45 = phi double* [ %3, %6 ], [ %38, %41 ]
%46 = phi double* [ %1, %6 ], [ %18, %41 ]
%47 = phi double [ 0.000000e+00, %6 ], [ %37, %41 ]
%48 = add nsw i32 %0, -1
%49 = icmp slt i32 %44, %48
br i1 %49, label %50, label %61
50: ; preds = %43
%51 = load double, double* %45
%52 = getelementptr inbounds double, double* %45, i64 1
%53 = load double, double* %52
%54 = load double, double* %46
%55 = tail call double @llvm.fmuladd.f64(double %54, double %51, double %47)
%56 = getelementptr inbounds double, double* %46, i64 1
%57 = load double, double* %56
%58 = tail call double @llvm.fmuladd.f64(double %57, double %53, double %55)
%59 = getelementptr inbounds double, double* %46, i64 2
%60 = getelementptr inbounds double, double* %45, i64 2
br label %61
61: ; preds = %50, %43
%62 = phi double* [ %60, %50 ], [ %45, %43 ]
%63 = phi double* [ %59, %50 ], [ %46, %43 ]
%64 = phi double [ %58, %50 ], [ %47, %43 ]
%65 = load double, double* %62
%66 = load double, double* %63
%67 = tail call double @llvm.fmuladd.f64(double %66, double %65, double %64)
switch i32 %5, label %71 [
i32 0, label %74
i32 1, label %68
]
68: ; preds = %61
%69 = load double, double* %4
%70 = fadd double %67, %69
br label %74
71: ; preds = %61
%72 = load double, double* %4
%73 = fsub double %72, %67
br label %74
74: ; preds = %61, %68, %71
%75 = phi double [ %70, %68 ], [ %73, %71 ], [ %67, %61 ]
store double %75, double* %4
ret void
}