#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);
int /*<<< orphan*/ matprod_scalar_vec(double, double *, double *, int);
int /*<<< orphan*/ matprod_vec_mat_k2(double *, double *, double *, int);
int /*<<< orphan*/ matprod_vec_mat_sub_yrows(double *, double *, double *, int,
                                             int, int, int);
double matprod_vec_vec(double *, double *, int);
int /*<<< orphan*/ set_to_zeros(double *, int);
void matprod_vec_mat(double *restrict x, double *restrict y, double *restrict z,
                     int k, int m) {
  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);
  if (m <= 1) {
    if (m == 1) {
      z[0] = matprod_vec_vec(x, y, k);
    }
    return;
  }
  if (k <= 2) {
    if (k == 2) {
      matprod_vec_mat_k2(x, y, z, m);
    } else if (k == 1) {
      matprod_scalar_vec(x[0], y, z, m);
    } else {
      set_to_zeros(z, m);
    }
    return;
  }
  int yrows = k;
  int add = 0;
  if (yrows > (512 + 256) && m > 4) {
    while (yrows >= 2 * (512 + 256)) {
      matprod_vec_mat_sub_yrows(x, y, z, k, m, (512 + 256), add);
      x += (512 + 256);
      y += (512 + 256);
      yrows -= (512 + 256);
      add = 1;
    }
    if (yrows > (512 + 256)) {
      int nr = (((yrows + 3) >> 1) & ~3);
      matprod_vec_mat_sub_yrows(x, y, z, k, m, nr, add);
      x += nr;
      y += nr;
      yrows -= nr;
      add = 1;
    }
  }
  matprod_vec_mat_sub_yrows(x, y, z, k, m, yrows, add);
}


x86 assembly (clang, -O0):
<matprod_vec_mat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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   1060 <assert@plt>
mov    -0x10(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rax
and    $0x0,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <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   $0x1,-0x20(%rbp)
jg     120f <matprod_vec_mat+0xaf>
cmpl   $0x1,-0x20(%rbp)
jne    120a <matprod_vec_mat+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <matprod_vec_vec@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    13a7 <matprod_vec_mat+0x247>
cmpl   $0x2,-0x1c(%rbp)
jg     1279 <matprod_vec_mat+0x119>
cmpl   $0x2,-0x1c(%rbp)
jne    123c <matprod_vec_mat+0xdc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
call   1030 <matprod_vec_mat_k2@plt>
jmp    1274 <matprod_vec_mat+0x114>
cmpl   $0x1,-0x1c(%rbp)
jne    1263 <matprod_vec_mat+0x103>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1080 <matprod_scalar_vec@plt>
jmp    126f <matprod_vec_mat+0x10f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1070 <set_to_zeros@plt>
jmp    1274 <matprod_vec_mat+0x114>
jmp    13a7 <matprod_vec_mat+0x247>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x300,-0x24(%rbp)
jle    1385 <matprod_vec_mat+0x225>
cmpl   $0x4,-0x20(%rbp)
jle    1385 <matprod_vec_mat+0x225>
jmp    12a2 <matprod_vec_mat+0x142>
cmpl   $0x600,-0x24(%rbp)
jl     1306 <matprod_vec_mat+0x1a6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x28(%rbp),%eax
mov    $0x300,%r9d
mov    %eax,(%rsp)
call   1040 <matprod_vec_mat_sub_yrows@plt>
mov    -0x8(%rbp),%rax
add    $0x1800,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1800,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x300,%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    12a2 <matprod_vec_mat+0x142>
cmpl   $0x300,-0x24(%rbp)
jle    1380 <matprod_vec_mat+0x220>
mov    -0x24(%rbp),%eax
add    $0x3,%eax
sar    $0x1,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x28(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <matprod_vec_mat_sub_yrows@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1385 <matprod_vec_mat+0x225>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x28(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <matprod_vec_mat_sub_yrows@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matprod_vec_mat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    $0x1,%edi
call   1060 <assert@plt>
mov    $0x1,%edi
call   1060 <assert@plt>
mov    $0x1,%edi
call   1060 <assert@plt>
cmp    $0x1,%r15d
jg     11c0 <matprod_vec_mat+0x60>
jne    135c <matprod_vec_mat+0x1fc>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <matprod_vec_vec@plt>
movsd  %xmm0,(%r12)
jmp    135c <matprod_vec_mat+0x1fc>
cmp    $0x2,%r14d
jg     11f9 <matprod_vec_mat+0x99>
cmp    $0x1,%r14d
je     12ca <matprod_vec_mat+0x16a>
cmp    $0x2,%r14d
jne    12eb <matprod_vec_mat+0x18b>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <matprod_vec_mat_k2@plt>
xor    %eax,%eax
cmp    $0x301,%r14d
mov    %r12,0x10(%rsp)
jb     12c5 <matprod_vec_mat+0x165>
cmp    $0x5,%r15d
jb     12c5 <matprod_vec_mat+0x165>
xor    %eax,%eax
cmp    $0x600,%r14d
jb     1304 <matprod_vec_mat+0x1a4>
movl   $0x0,(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    $0x300,%r9d
call   1040 <matprod_vec_mat_sub_yrows@plt>
add    $0x1800,%rbp
add    $0x1800,%rbx
lea    -0x300(%r14),%r12d
cmp    $0x600,%r12d
jb     12af <matprod_vec_mat+0x14f>
mov    0x10(%rsp),%r13
nopw   0x0(%rax,%rax,1)
movl   $0x1,(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    $0x300,%r9d
call   1040 <matprod_vec_mat_sub_yrows@plt>
add    $0x1800,%rbp
add    $0x1800,%rbx
add    $0xfffffd00,%r12d
cmp    $0x5ff,%r12d
ja     1270 <matprod_vec_mat+0x110>
mov    $0x1,%eax
cmp    $0x301,%r12d
mov    $0x300,%r9d
jae    1307 <matprod_vec_mat+0x1a7>
jmp    1343 <matprod_vec_mat+0x1e3>
mov    %r14d,%r9d
jmp    1343 <matprod_vec_mat+0x1e3>
movsd  0x0(%rbp),%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <matprod_scalar_vec@plt>
mov    %r12,%rdi
mov    %r15d,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <set_to_zeros@plt>
mov    %r14d,%r12d
lea    0x3(%r12),%r13d
shr    %r13d
and    $0xfffffffc,%r13d
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0x10(%rsp),%rdx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    %r13d,%r9d
call   1040 <matprod_vec_mat_sub_yrows@plt>
lea    0x0(%rbp,%r13,8),%rbp
lea    (%rbx,%r13,8),%rbx
sub    %r13d,%r12d
mov    $0x1,%eax
mov    %r12d,%r9d
mov    %eax,(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    0x10(%rsp),%rdx
mov    %r14d,%ecx
mov    %r15d,%r8d
call   1040 <matprod_vec_mat_sub_yrows@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @matprod_vec_mat(double* noalias %0, double* noalias %1, double* noalias %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 slt i32 %4, 2
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = icmp eq i32 %4, 1
br i1 %11, label %12, label %69
12: ; preds = %10
%13 = tail call double @matprod_vec_vec(double* %0, double* %1, i32 %3)
store double %13, double* %2
br label %69
14: ; preds = %5
%15 = icmp slt i32 %3, 3
br i1 %15, label %16, label %24
16: ; preds = %14
switch i32 %3, label %22 [
i32 2, label %17
i32 1, label %19
]
17: ; preds = %16
%18 = tail call i32 @matprod_vec_mat_k2(double* %0, double* %1, double* %2, i32 %4)
br label %69
19: ; preds = %16
%20 = load double, double* %0
%21 = tail call i32 @matprod_scalar_vec(double %20, double* %1, double* %2, i32 %4)
br label %69
22: ; preds = %16
%23 = tail call i32 @set_to_zeros(double* %2, i32 %4)
br label %69
24: ; preds = %14
%25 = icmp ugt i32 %3, 768
%26 = icmp ugt i32 %4, 4
%27 = and i1 %25, %26
br i1 %27, label %28, label %63
28: ; preds = %24
%29 = icmp ugt i32 %3, 1535
br i1 %29, label %30, label %50
30: ; preds = %28
%31 = tail call i32 @matprod_vec_mat_sub_yrows(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 768, i32 0)
%32 = getelementptr inbounds double, double* %0, i64 768
%33 = getelementptr inbounds double, double* %1, i64 768
%34 = add nsw i32 %3, -768
%35 = icmp ugt i32 %34, 1535
br i1 %35, label %36, label %45
36: ; preds = %30, %36
%37 = phi double* [ %41, %36 ], [ %32, %30 ]
%38 = phi i32 [ %43, %36 ], [ %34, %30 ]
%39 = phi double* [ %42, %36 ], [ %33, %30 ]
%40 = tail call i32 @matprod_vec_mat_sub_yrows(double* %37, double* %39, double* %2, i32 %3, i32 %4, i32 768, i32 1)
%41 = getelementptr inbounds double, double* %37, i64 768
%42 = getelementptr inbounds double, double* %39, i64 768
%43 = add nsw i32 %38, -768
%44 = icmp ugt i32 %43, 1535
br i1 %44, label %36, label %45
45: ; preds = %36, %30
%46 = phi double* [ %33, %30 ], [ %42, %36 ]
%47 = phi i32 [ %34, %30 ], [ %43, %36 ]
%48 = phi double* [ %32, %30 ], [ %41, %36 ]
%49 = icmp ugt i32 %47, 768
br i1 %49, label %50, label %63
50: ; preds = %28, %45
%51 = phi double* [ %48, %45 ], [ %0, %28 ]
%52 = phi i32 [ 1, %45 ], [ 0, %28 ]
%53 = phi i32 [ %47, %45 ], [ %3, %28 ]
%54 = phi double* [ %46, %45 ], [ %1, %28 ]
%55 = add nuw nsw i32 %53, 3
%56 = lshr i32 %55, 1
%57 = and i32 %56, 2147483644
%58 = tail call i32 @matprod_vec_mat_sub_yrows(double* %51, double* %54, double* %2, i32 %3, i32 %4, i32 %57, i32 %52)
%59 = zext i32 %57 to i64
%60 = getelementptr inbounds double, double* %51, i64 %59
%61 = getelementptr inbounds double, double* %54, i64 %59
%62 = sub nuw nsw i32 %53, %57
br label %63
63: ; preds = %45, %50, %24
%64 = phi double* [ %61, %50 ], [ %46, %45 ], [ %1, %24 ]
%65 = phi i32 [ %62, %50 ], [ 768, %45 ], [ %3, %24 ]
%66 = phi i32 [ 1, %50 ], [ 1, %45 ], [ 0, %24 ]
%67 = phi double* [ %60, %50 ], [ %48, %45 ], [ %0, %24 ]
%68 = tail call i32 @matprod_vec_mat_sub_yrows(double* %67, double* %64, double* %2, i32 %3, i32 %4, i32 %65, i32 %66)
br label %69
69: ; preds = %17, %22, %19, %10, %12, %63
ret void
}