#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 */
scalar_t__ malloc(int);
double vectorDotProduct(double *, double *, int);
double *matrixVectorMultiplication(double **matrix, double *vector, int n0,
                                   int n1) {
  int i;
  double *result;
  result = (double *)malloc(n0 * sizeof(double));
  for (i = 0; i < n0; i++)
    result[i] = vectorDotProduct(matrix[i], vector, n1);
  return (result);
}


x86 assembly (clang, -O0):
<matrixVectorMultiplication>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118f <matrixVectorMultiplication+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <vectorDotProduct@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <matrixVectorMultiplication+0x30>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixVectorMultiplication>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r13
lea    0x0(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    116f <matrixVectorMultiplication+0x4f>
mov    %ebx,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    0x0(%r13,%rbx,8),%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <vectorDotProduct@plt>
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <matrixVectorMultiplication+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @matrixVectorMultiplication(double** %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
store double** %0, double*** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to double*
store double* %16, double** %10
store i32 0, i32* %9
br label %17
17: ; preds = %34, %4
%18 = load i32, i32* %9
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = load double**, double*** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double*, double** %22, i64 %24
%26 = load double*, double** %25
%27 = load double*, double** %6
%28 = load i32, i32* %8
%29 = call double @vectorDotProduct(double* %26, double* %27, i32 %28)
%30 = load double*, double** %10
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %21
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %17
37: ; preds = %17
%38 = load double*, double** %10
ret double* %38
}

LLVM IR (-O2):
define double* @matrixVectorMultiplication(double** nocapture %0, double* %1, i32 %2, i32 %3) {
%5 = shl i32 %2, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %19
9: ; preds = %4
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %17, %11 ]
%13 = getelementptr inbounds double*, double** %0, i64 %12
%14 = load double*, double** %13
%15 = tail call double @vectorDotProduct(double* %14, double* %1, i32 %3)
%16 = getelementptr inbounds double, double* %7, i64 %12
store double %15, double* %16
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %19, label %11
19: ; preds = %11, %4
ret double* %7
}