#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 *pdvector(int);
double *dotMultMatrixByVector(double **mat, double *vec, int dim) {
  double *result;
  int row, col;
  result = pdvector(dim);
  for (row = 0; row < dim; row++) {
    result[row] = 0.0;
    for (col = 0; col < dim; col++) {
      result[row] = result[row] + (mat[row][col] * vec[col]);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<dotMultMatrixByVector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <pdvector@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ca <dotMultMatrixByVector+0xba>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b7 <dotMultMatrixByVector+0xa7>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1159 <dotMultMatrixByVector+0x49>
jmp    11bc <dotMultMatrixByVector+0xac>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1136 <dotMultMatrixByVector+0x26>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dotMultMatrixByVector>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%edi
call   1030 <pdvector@plt>
test   %r15d,%r15d
jle    11bb <dotMultMatrixByVector+0xab>
mov    %r15d,%ecx
mov    %ecx,%edx
and    $0xfffffffe,%edx
xor    %esi,%esi
jmp    1149 <dotMultMatrixByVector+0x39>
nopl   0x0(%rax)
add    $0x1,%rsi
cmp    %rcx,%rsi
je     11bb <dotMultMatrixByVector+0xab>
movq   $0x0,(%rax,%rsi,8)
mov    (%r14,%rsi,8),%rdi
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
cmp    $0x1,%r15d
je     11a1 <dotMultMatrixByVector+0x91>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rbp,8),%xmm1
mulsd  (%rbx,%rbp,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rsi,8)
movsd  0x8(%rdi,%rbp,8),%xmm0
mulsd  0x8(%rbx,%rbp,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rsi,8)
add    $0x2,%rbp
cmp    %rbp,%rdx
jne    1170 <dotMultMatrixByVector+0x60>
test   $0x1,%cl
je     1140 <dotMultMatrixByVector+0x30>
movsd  (%rdi,%rbp,8),%xmm1
mulsd  (%rbx,%rbp,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rsi,8)
jmp    1140 <dotMultMatrixByVector+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @dotMultMatrixByVector(double** %0, double* %1, i32 %2) {
%4 = alloca double**
%5 = alloca double*
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
store double** %0, double*** %4
store double* %1, double** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = call double* @pdvector(i32 %10)
store double* %11, double** %7
store i32 0, i32* %8
br label %12
12: ; preds = %54, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %57
16: ; preds = %12
%17 = load double*, double** %7
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
store double 0.000000e+00, double* %20
store i32 0, i32* %9
br label %21
21: ; preds = %50, %16
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %53
25: ; preds = %21
%26 = load double*, double** %7
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double**, double*** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
%35 = load double*, double** %34
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = load double*, double** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = call double @llvm.fmuladd.f64(double %39, double %44, double %30)
%46 = load double*, double** %7
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
store double %45, double* %49
br label %50
50: ; preds = %25
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %21
53: ; preds = %21
br label %54
54: ; preds = %53
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %12
57: ; preds = %12
%58 = load double*, double** %7
ret double* %58
}

LLVM IR (-O2):
define double* @dotMultMatrixByVector(double** nocapture %0, double* nocapture %1, i32 %2) {
%4 = tail call double* @pdvector(i32 %2)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %47
6: ; preds = %3
%7 = zext i32 %2 to i64
%8 = and i64 %7, 1
%9 = icmp eq i32 %2, 1
%10 = and i64 %7, 4294967294
%11 = icmp eq i64 %8, 0
br label %12
12: ; preds = %44, %6
%13 = phi i64 [ 0, %6 ], [ %45, %44 ]
%14 = getelementptr inbounds double, double* %4, i64 %13
store double 0.000000e+00, double* %14
%15 = getelementptr inbounds double*, double** %0, i64 %13
%16 = load double*, double** %15
br i1 %9, label %35, label %17
17: ; preds = %12, %17
%18 = phi double [ %31, %17 ], [ 0.000000e+00, %12 ]
%19 = phi i64 [ %32, %17 ], [ 0, %12 ]
%20 = phi i64 [ %33, %17 ], [ 0, %12 ]
%21 = getelementptr inbounds double, double* %16, i64 %19
%22 = load double, double* %21
%23 = getelementptr inbounds double, double* %1, i64 %19
%24 = load double, double* %23
%25 = tail call double @llvm.fmuladd.f64(double %22, double %24, double %18)
store double %25, double* %14
%26 = or i64 %19, 1
%27 = getelementptr inbounds double, double* %16, i64 %26
%28 = load double, double* %27
%29 = getelementptr inbounds double, double* %1, i64 %26
%30 = load double, double* %29
%31 = tail call double @llvm.fmuladd.f64(double %28, double %30, double %25)
store double %31, double* %14
%32 = add nuw nsw i64 %19, 2
%33 = add i64 %20, 2
%34 = icmp eq i64 %33, %10
br i1 %34, label %35, label %17
35: ; preds = %17, %12
%36 = phi double [ 0.000000e+00, %12 ], [ %31, %17 ]
%37 = phi i64 [ 0, %12 ], [ %32, %17 ]
br i1 %11, label %44, label %38
38: ; preds = %35
%39 = getelementptr inbounds double, double* %16, i64 %37
%40 = load double, double* %39
%41 = getelementptr inbounds double, double* %1, i64 %37
%42 = load double, double* %41
%43 = tail call double @llvm.fmuladd.f64(double %40, double %42, double %36)
store double %43, double* %14
br label %44
44: ; preds = %35, %38
%45 = add nuw nsw i64 %13, 1
%46 = icmp eq i64 %45, %7
br i1 %46, label %47, label %12
47: ; preds = %44, %3
ret double* %4
}