#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ z;
typedef scalar_t__ y;
typedef scalar_t__ x;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
void matprod_mat_vec_n2(double *restrict x, double *restrict y,
                        double *restrict z, int k, int add) {
  assert(((uintptr_t)(x) & (1 - 1)) == 0);
  assert(((uintptr_t)(y) & (1 - 1)) == 0);
  assert(((uintptr_t)(z) & (1 - 1)) == 0);
  x = (x);
  y = (y);
  z = (z);
  double s[2];
  if (add) {
    s[0] = z[0];
    s[1] = z[1];
  } else
    s[0] = s[1] = 0;
  while (k > 1) {
    s[0] = (s[0] + (x[0] * y[0])) + (x[2] * y[1]);
    s[1] = (s[1] + (x[1] * y[0])) + (x[3] * y[1]);
    x += 4;
    y += 2;
    k -= 2;
  }
  if (k >= 1) {
    s[0] += x[0] * y[0];
    s[1] += x[1] * y[0];
  }
  z[0] = s[0];
  z[1] = s[1];
}


x86 assembly (clang, -O0):
<matprod_mat_vec_n2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11b8 <matprod_mat_vec_n2+0xa8>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11c8 <matprod_mat_vec_n2+0xb8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11cd <matprod_mat_vec_n2+0xbd>
cmpl   $0x1,-0x1c(%rbp)
jle    1276 <matprod_mat_vec_n2+0x166>
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <matprod_mat_vec_n2+0xbd>
cmpl   $0x1,-0x1c(%rbp)
jl     12c5 <matprod_mat_vec_n2+0x1b5>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matprod_mat_vec_n2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r12d
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x1,%edi
call   1030 <assert@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
mov    $0x1,%edi
call   1030 <assert@plt>
test   %r12d,%r12d
je     117b <matprod_mat_vec_n2+0x6b>
movupd (%r14),%xmm0
cmp    $0x2,%ebp
jge    1190 <matprod_mat_vec_n2+0x80>
cmp    $0x1,%ebp
jne    116d <matprod_mat_vec_n2+0x5d>
movupd (%rbx),%xmm1
movsd  (%r15),%xmm2
unpcklpd %xmm2,%xmm2
mulpd  %xmm1,%xmm2
addpd  %xmm2,%xmm0
movupd %xmm0,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xorpd  %xmm0,%xmm0
cmp    $0x2,%ebp
jl     1153 <matprod_mat_vec_n2+0x43>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%eax
movupd (%rbx),%xmm3
movupd 0x10(%rbx),%xmm4
movsd  (%r15),%xmm2
movsd  0x8(%r15),%xmm1
unpcklpd %xmm2,%xmm2
mulpd  %xmm3,%xmm2
addpd  %xmm0,%xmm2
unpcklpd %xmm1,%xmm1
mulpd  %xmm4,%xmm1
movapd %xmm1,%xmm0
addpd  %xmm2,%xmm0
add    $0x20,%rbx
add    $0x10,%r15
lea    -0x2(%rax),%ebp
cmp    $0x3,%eax
ja     1190 <matprod_mat_vec_n2+0x80>
addpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
cmp    $0x1,%ebp
je     1158 <matprod_mat_vec_n2+0x48>
jmp    116d <matprod_mat_vec_n2+0x5d>

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

LLVM IR (-O2):
define void @matprod_mat_vec_n2(double* noalias nocapture %0, double* noalias nocapture %1, double* noalias nocapture %2, i32 %3, i32 %4) {
%6 = tail call i32 @assert(i32 1)
%7 = tail call i32 @assert(i32 1)
%8 = tail call i32 @assert(i32 1)
%9 = icmp eq i32 %4, 0
br i1 %9, label %13, label %10
10: ; preds = %5
%11 = bitcast double* %2 to <2 x double>*
%12 = load <2 x double>, <2 x double>* %11
br label %13
13: ; preds = %5, %10
%14 = phi <2 x double> [ %12, %10 ], [ zeroinitializer, %5 ]
%15 = icmp sgt i32 %3, 1
br i1 %15, label %16, label %42
16: ; preds = %13, %16
%17 = phi double* [ %35, %16 ], [ %0, %13 ]
%18 = phi i32 [ %37, %16 ], [ %3, %13 ]
%19 = phi double* [ %36, %16 ], [ %1, %13 ]
%20 = phi <2 x double> [ %34, %16 ], [ %14, %13 ]
%21 = load double, double* %19
%22 = getelementptr inbounds double, double* %17, i64 2
%23 = getelementptr inbounds double, double* %19, i64 1
%24 = load double, double* %23
%25 = bitcast double* %17 to <2 x double>*
%26 = load <2 x double>, <2 x double>* %25
%27 = insertelement <2 x double> poison, double %21, i64 0
%28 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> zeroinitializer
%29 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %28, <2 x double> %20)
%30 = bitcast double* %22 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = insertelement <2 x double> poison, double %24, i64 0
%33 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> zeroinitializer
%34 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %33, <2 x double> %29)
%35 = getelementptr inbounds double, double* %17, i64 4
%36 = getelementptr inbounds double, double* %19, i64 2
%37 = add nsw i32 %18, -2
%38 = icmp ugt i32 %18, 3
br i1 %38, label %16, label %39
39: ; preds = %16
%40 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %26, <2 x double> %28, <2 x double> %20)
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %33, <2 x double> %40)
br label %42
42: ; preds = %39, %13
%43 = phi double* [ %1, %13 ], [ %36, %39 ]
%44 = phi i32 [ %3, %13 ], [ %37, %39 ]
%45 = phi double* [ %0, %13 ], [ %35, %39 ]
%46 = phi <2 x double> [ %14, %13 ], [ %41, %39 ]
%47 = icmp eq i32 %44, 1
br i1 %47, label %48, label %55
48: ; preds = %42
%49 = load double, double* %43
%50 = bitcast double* %45 to <2 x double>*
%51 = load <2 x double>, <2 x double>* %50
%52 = insertelement <2 x double> poison, double %49, i64 0
%53 = shufflevector <2 x double> %52, <2 x double> poison, <2 x i32> zeroinitializer
%54 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %51, <2 x double> %53, <2 x double> %46)
br label %55
55: ; preds = %48, %42
%56 = phi <2 x double> [ %54, %48 ], [ %46, %42 ]
%57 = bitcast double* %2 to <2 x double>*
store <2 x double> %56, <2 x double>* %57
ret void
}