#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 *allocateDoubleVector(int);
double *multiplyMatrixVector(double **A, double *b, int m, int n) {
  int i, j;
  double *x;
  x = allocateDoubleVector(n);
  for (i = 0; i < n; i++)
    x[i] = 0.0;
  for (j = 0; j < n; j++)
    for (i = 0; i < m; i++)
      x[j] += A[i][j] * b[i];
  return x;
}


x86 assembly (clang, -O0):
<multiplyMatrixVector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <allocateDoubleVector@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1163 <multiplyMatrixVector+0x53>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1139 <multiplyMatrixVector+0x29>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e6 <multiplyMatrixVector+0xd6>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d3 <multiplyMatrixVector+0xc3>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <multiplyMatrixVector+0x6d>
jmp    11d8 <multiplyMatrixVector+0xc8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116a <multiplyMatrixVector+0x5a>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiplyMatrixVector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r13
mov    %ecx,%edi
call   1030 <allocateDoubleVector@plt>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11eb <multiplyMatrixVector+0xcb>
mov    %r12d,%r12d
lea    0x0(,%r12,8),%rdx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14d,%eax
mov    %eax,%ecx
and    $0xfffffffe,%ecx
jmp    1179 <multiplyMatrixVector+0x59>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %r12,%rbp
je     11eb <multiplyMatrixVector+0xcb>
test   %r14d,%r14d
jle    1170 <multiplyMatrixVector+0x50>
movsd  (%rbx,%rbp,8),%xmm0
xor    %edx,%edx
cmp    $0x1,%r14d
je     11cc <multiplyMatrixVector+0xac>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rdx,8),%rsi
movsd  (%rsi,%rbp,8),%xmm1
mulsd  (%r15,%rdx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rbp,8)
mov    0x8(%r13,%rdx,8),%rsi
movsd  (%rsi,%rbp,8),%xmm0
mulsd  0x8(%r15,%rdx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x2,%rdx
cmp    %rdx,%rcx
jne    1190 <multiplyMatrixVector+0x70>
test   $0x1,%al
je     1170 <multiplyMatrixVector+0x50>
mov    0x0(%r13,%rdx,8),%rsi
movsd  (%rsi,%rbp,8),%xmm1
mulsd  (%r15,%rdx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rbp,8)
jmp    1170 <multiplyMatrixVector+0x50>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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