void kernel_dtrmv_u_t_1_lib4(int kmax, double *A, int sda, double *x, double *y,
                             int alg) {
  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) {
    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)
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    1230 <kernel_dtrmv_u_t_1_lib4+0x130>
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    1137 <kernel_dtrmv_u_t_1_lib4+0x37>
mov    -0x38(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12b3 <kernel_dtrmv_u_t_1_lib4+0x1b3>
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    12fb <kernel_dtrmv_u_t_1_lib4+0x1fb>
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    1335 <kernel_dtrmv_u_t_1_lib4+0x235>
cmpl   $0x1,-0x2c(%rbp)
jne    131b <kernel_dtrmv_u_t_1_lib4+0x21b>
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
jmp    1330 <kernel_dtrmv_u_t_1_lib4+0x230>
movsd  -0x60(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
jmp    1335 <kernel_dtrmv_u_t_1_lib4+0x235>
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dtrmv_u_t_1_lib4>:
cmp    $0x4,%edi
jl     116c <kernel_dtrmv_u_t_1_lib4+0x6c>
lea    -0x3(%rdi),%r10d
shl    $0x2,%edx
movslq %edx,%rdx
shl    $0x3,%rdx
xor    %eax,%eax
xorpd  %xmm0,%xmm0
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     1120 <kernel_dtrmv_u_t_1_lib4+0x20>
mov    %edi,%eax
and    $0xfffffffc,%eax
jmp    1172 <kernel_dtrmv_u_t_1_lib4+0x72>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
add    $0xffffffff,%edi
cmp    %edi,%eax
jge    119f <kernel_dtrmv_u_t_1_lib4+0x9f>
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     11ce <kernel_dtrmv_u_t_1_lib4+0xce>
cmp    $0x1,%r9d
jne    11c1 <kernel_dtrmv_u_t_1_lib4+0xc1>
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
store i32 4, i32* %13
store i32 4, i32* %14
store double 0.000000e+00, double* %20
store i32 0, i32* %15
br label %21
21: ; preds = %70, %6
%22 = load i32, i32* %15
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 3
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %73
26: ; preds = %21
%27 = load double*, double** %10
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double, double* %28
store double %29, double* %16
%30 = load double*, double** %10
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
store double %32, double* %17
%33 = load double*, double** %10
%34 = getelementptr inbounds double, double* %33, i64 2
%35 = load double, double* %34
store double %35, double* %18
%36 = load double*, double** %10
%37 = getelementptr inbounds double, double* %36, i64 3
%38 = load double, double* %37
store double %38, double* %19
%39 = load double*, double** %8
%40 = getelementptr inbounds double, double* %39, i64 0
%41 = load double, double* %40
%42 = load double, double* %16
%43 = load double, double* %20
%44 = call double @llvm.fmuladd.f64(double %41, double %42, double %43)
store double %44, double* %20
%45 = load double*, double** %8
%46 = getelementptr inbounds double, double* %45, i64 1
%47 = load double, double* %46
%48 = load double, double* %17
%49 = load double, double* %20
%50 = call double @llvm.fmuladd.f64(double %47, double %48, double %49)
store double %50, double* %20
%51 = load double*, double** %8
%52 = getelementptr inbounds double, double* %51, i64 2
%53 = load double, double* %52
%54 = load double, double* %18
%55 = load double, double* %20
%56 = call double @llvm.fmuladd.f64(double %53, double %54, double %55)
store double %56, double* %20
%57 = load double*, double** %8
%58 = getelementptr inbounds double, double* %57, i64 3
%59 = load double, double* %58
%60 = load double, double* %19
%61 = load double, double* %20
%62 = call double @llvm.fmuladd.f64(double %59, double %60, double %61)
store double %62, double* %20
%63 = load i32, i32* %9
%64 = mul nsw i32 %63, 4
%65 = load double*, double** %8
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds double, double* %65, i64 %66
store double* %67, double** %8
%68 = load double*, double** %10
%69 = getelementptr inbounds double, double* %68, i64 4
store double* %69, double** %10
br label %70
70: ; preds = %26
%71 = load i32, i32* %15
%72 = add nsw i32 %71, 4
store i32 %72, i32* %15
br label %21
73: ; preds = %21
%74 = load i32, i32* %15
%75 = load i32, i32* %7
%76 = sub nsw i32 %75, 1
%77 = icmp slt i32 %74, %76
br i1 %77, label %78, label %101
78: ; preds = %73
%79 = load double*, double** %10
%80 = getelementptr inbounds double, double* %79, i64 0
%81 = load double, double* %80
store double %81, double* %16
%82 = load double*, double** %10
%83 = getelementptr inbounds double, double* %82, i64 1
%84 = load double, double* %83
store double %84, double* %17
%85 = load double*, double** %8
%86 = getelementptr inbounds double, double* %85, i64 0
%87 = load double, double* %86
%88 = load double, double* %16
%89 = load double, double* %20
%90 = call double @llvm.fmuladd.f64(double %87, double %88, double %89)
store double %90, double* %20
%91 = load double*, double** %8
%92 = getelementptr inbounds double, double* %91, i64 1
%93 = load double, double* %92
%94 = load double, double* %17
%95 = load double, double* %20
%96 = call double @llvm.fmuladd.f64(double %93, double %94, double %95)
store double %96, double* %20
%97 = load double*, double** %8
%98 = getelementptr inbounds double, double* %97, i64 2
store double* %98, double** %8
%99 = load double*, double** %10
%100 = getelementptr inbounds double, double* %99, i64 2
store double* %100, double** %10
br label %101
101: ; preds = %78, %73
%102 = load double*, double** %10
%103 = getelementptr inbounds double, double* %102, i64 0
%104 = load double, double* %103
store double %104, double* %16
%105 = load double*, double** %8
%106 = getelementptr inbounds double, double* %105, i64 0
%107 = load double, double* %106
%108 = load double, double* %16
%109 = load double, double* %20
%110 = call double @llvm.fmuladd.f64(double %107, double %108, double %109)
store double %110, double* %20
%111 = load i32, i32* %12
%112 = icmp eq i32 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %101
%114 = load double, double* %20
%115 = load double*, double** %11
%116 = getelementptr inbounds double, double* %115, i64 0
store double %114, double* %116
br label %133
117: ; preds = %101
%118 = load i32, i32* %12
%119 = icmp eq i32 %118, 1
br i1 %119, label %120, label %126
120: ; preds = %117
%121 = load double, double* %20
%122 = load double*, double** %11
%123 = getelementptr inbounds double, double* %122, i64 0
%124 = load double, double* %123
%125 = fadd double %124, %121
store double %125, double* %123
br label %132
126: ; preds = %117
%127 = load double, double* %20
%128 = load double*, double** %11
%129 = getelementptr inbounds double, double* %128, i64 0
%130 = load double, double* %129
%131 = fsub double %130, %127
store double %131, double* %129
br label %132
132: ; preds = %126, %120
br label %133
133: ; preds = %132, %113
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 = add nsw i32 %0, -3
%8 = icmp sgt i32 %0, 3
br i1 %8, label %9, label %41
9: ; preds = %6
%10 = shl nsw i32 %2, 2
%11 = sext i32 %10 to i64
br label %12
12: ; preds = %9, %12
%13 = phi double [ 0.000000e+00, %9 ], [ %34, %12 ]
%14 = phi double* [ %1, %9 ], [ %35, %12 ]
%15 = phi double* [ %3, %9 ], [ %36, %12 ]
%16 = phi i32 [ 0, %9 ], [ %37, %12 ]
%17 = load double, double* %15
%18 = getelementptr inbounds double, double* %15, i64 1
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %15, i64 2
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %15, i64 3
%23 = load double, double* %22
%24 = load double, double* %14
%25 = tail call double @llvm.fmuladd.f64(double %24, double %17, double %13)
%26 = getelementptr inbounds double, double* %14, i64 1
%27 = load double, double* %26
%28 = tail call double @llvm.fmuladd.f64(double %27, double %19, double %25)
%29 = getelementptr inbounds double, double* %14, i64 2
%30 = load double, double* %29
%31 = tail call double @llvm.fmuladd.f64(double %30, double %21, double %28)
%32 = getelementptr inbounds double, double* %14, i64 3
%33 = load double, double* %32
%34 = tail call double @llvm.fmuladd.f64(double %33, double %23, double %31)
%35 = getelementptr inbounds double, double* %14, i64 %11
%36 = getelementptr inbounds double, double* %15, i64 4
%37 = add nuw nsw i32 %16, 4
%38 = icmp slt i32 %37, %7
br i1 %38, label %12, label %39
39: ; preds = %12
%40 = and i32 %0, -4
br label %41
41: ; preds = %39, %6
%42 = phi i32 [ 0, %6 ], [ %40, %39 ]
%43 = phi double* [ %3, %6 ], [ %36, %39 ]
%44 = phi double* [ %1, %6 ], [ %35, %39 ]
%45 = phi double [ 0.000000e+00, %6 ], [ %34, %39 ]
%46 = add nsw i32 %0, -1
%47 = icmp slt i32 %42, %46
br i1 %47, label %48, label %59
48: ; preds = %41
%49 = load double, double* %43
%50 = getelementptr inbounds double, double* %43, i64 1
%51 = load double, double* %50
%52 = load double, double* %44
%53 = tail call double @llvm.fmuladd.f64(double %52, double %49, double %45)
%54 = getelementptr inbounds double, double* %44, i64 1
%55 = load double, double* %54
%56 = tail call double @llvm.fmuladd.f64(double %55, double %51, double %53)
%57 = getelementptr inbounds double, double* %44, i64 2
%58 = getelementptr inbounds double, double* %43, i64 2
br label %59
59: ; preds = %48, %41
%60 = phi double* [ %58, %48 ], [ %43, %41 ]
%61 = phi double* [ %57, %48 ], [ %44, %41 ]
%62 = phi double [ %56, %48 ], [ %45, %41 ]
%63 = load double, double* %60
%64 = load double, double* %61
%65 = tail call double @llvm.fmuladd.f64(double %64, double %63, double %62)
switch i32 %5, label %69 [
i32 0, label %72
i32 1, label %66
]
66: ; preds = %59
%67 = load double, double* %4
%68 = fadd double %65, %67
br label %72
69: ; preds = %59
%70 = load double, double* %4
%71 = fsub double %70, %65
br label %72
72: ; preds = %59, %66, %69
%73 = phi double [ %68, %66 ], [ %71, %69 ], [ %65, %59 ]
store double %73, double* %4
ret void
}