#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 */

/* Variables and functions */
double dot(double *, double *, int);
int /*<<< orphan*/ memcpy(double *, double *, int);
void matrix_vec_mult(double *y, double **A, double *x, int n, int m) {
  int i;
  if (y == x) {
    double z[m];
    memcpy(z, x, m * sizeof(double));
    for (i = 0; i < n; i++)
      y[i] = dot(A[i], z, m);
  } else
    for (i = 0; i < n; i++)
      y[i] = dot(A[i], x, m);
}


x86 assembly (clang, -O0):
<matrix_vec_mult>:
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
cmp    -0x18(%rbp),%rax
jne    11d5 <matrix_vec_mult+0xb5>
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c9 <matrix_vec_mult+0xa9>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%edx
call   1030 <dot@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <matrix_vec_mult+0x6a>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    1220 <matrix_vec_mult+0x100>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    121b <matrix_vec_mult+0xfb>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <dot@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11dc <matrix_vec_mult+0xbc>
jmp    1220 <matrix_vec_mult+0x100>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_vec_mult>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %rsi,%r15
mov    %rdi,%rcx
cmp    %rdx,%rdi
je     1187 <matrix_vec_mult+0x67>
test   %ebx,%ebx
jle    11f6 <matrix_vec_mult+0xd6>
mov    %rdx,%r13
mov    %rcx,%r12
mov    %ebx,%eax
mov    %rax,-0x30(%rbp)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%r14,8),%rdi
mov    %r13,%rsi
mov    %r8d,%edx
mov    %r8,%rbx
call   1030 <dot@plt>
mov    %rbx,%r8
movsd  %xmm0,(%r12,%r14,8)
add    $0x1,%r14
cmp    %r14,-0x30(%rbp)
jne    1160 <matrix_vec_mult+0x40>
jmp    11f6 <matrix_vec_mult+0xd6>
mov    %rsp,-0x38(%rbp)
mov    %r8d,%eax
mov    %rsp,%r13
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0x0(,%r8,8),%edx
mov    %r13,%rdi
mov    %r15,-0x30(%rbp)
mov    %rcx,%rsi
mov    %r8,%r12
mov    %rcx,%r15
call   1040 <memcpy@plt>
test   %ebx,%ebx
jle    11f2 <matrix_vec_mult+0xd2>
mov    %ebx,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax,%rbx,8),%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <dot@plt>
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11d0 <matrix_vec_mult+0xb0>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @matrix_vec_mult(double* %0, double** %1, double* %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 i8*
%13 = alloca i64
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 = load double*, double** %8
%16 = icmp eq double* %14, %15
br i1 %16, label %17, label %49
17: ; preds = %5
%18 = load i32, i32* %10
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %12
%21 = alloca double, i64 %19
store i64 %19, i64* %13
%22 = load double*, double** %8
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i32 @memcpy(double* %21, double* %22, i32 %26)
store i32 0, i32* %11
br label %28
28: ; preds = %44, %17
%29 = load i32, i32* %11
%30 = load i32, i32* %9
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load double**, double*** %7
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double*, double** %33, i64 %35
%37 = load double*, double** %36
%38 = load i32, i32* %10
%39 = call double @dot(double* %37, double* %21, i32 %38)
%40 = load double*, double** %6
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double %39, double* %43
br label %44
44: ; preds = %32
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %28
47: ; preds = %28
%48 = load i8*, i8** %12
br label %71
49: ; preds = %5
store i32 0, i32* %11
br label %50
50: ; preds = %67, %49
%51 = load i32, i32* %11
%52 = load i32, i32* %9
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %70
54: ; preds = %50
%55 = load double**, double*** %7
%56 = load i32, i32* %11
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double*, double** %55, i64 %57
%59 = load double*, double** %58
%60 = load double*, double** %8
%61 = load i32, i32* %10
%62 = call double @dot(double* %59, double* %60, i32 %61)
%63 = load double*, double** %6
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %62, double* %66
br label %67
67: ; preds = %54
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %50
70: ; preds = %50
br label %71
71: ; preds = %70, %47
ret void
}

LLVM IR (-O2):
define void @matrix_vec_mult(double* writeonly %0, double** nocapture %1, double* %2, i32 %3, i32 %4) {
%6 = icmp eq double* %0, %2
br i1 %6, label %11, label %7
7: ; preds = %5
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %37
9: ; preds = %7
%10 = zext i32 %3 to i64
br label %29
11: ; preds = %5
%12 = zext i32 %4 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca double, i64 %12
%15 = shl i32 %4, 3
%16 = call i32 @memcpy(double* %14, double* %0, i32 %15)
%17 = icmp sgt i32 %3, 0
br i1 %17, label %18, label %28
18: ; preds = %11
%19 = zext i32 %3 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %26, %20 ]
%22 = getelementptr inbounds double*, double** %1, i64 %21
%23 = load double*, double** %22
%24 = call double @dot(double* %23, double* %14, i32 %4)
%25 = getelementptr inbounds double, double* %0, i64 %21
store double %24, double* %25
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, %19
br i1 %27, label %28, label %20
28: ; preds = %20, %11
br label %37
29: ; preds = %9, %29
%30 = phi i64 [ 0, %9 ], [ %35, %29 ]
%31 = getelementptr inbounds double*, double** %1, i64 %30
%32 = load double*, double** %31
%33 = tail call double @dot(double* %32, double* %2, i32 %4)
%34 = getelementptr inbounds double, double* %0, i64 %30
store double %33, double* %34
%35 = add nuw nsw i64 %30, 1
%36 = icmp eq i64 %35, %10
br i1 %36, label %37, label %29
37: ; preds = %29, %7, %28
ret void
}