#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 *generate_zero_vector(int);
double *multiply_double_matrix_vector(double **a, int m, int n, double *b) {
  double *c = generate_zero_vector(m + 1);
  int i, j;
  for (i = 1; i <= m; i++) {
    c[i] = 0.0;
    for (j = 1; j <= n; j++) {
      c[i] += a[i][j] * b[j];
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<multiply_double_matrix_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <generate_zero_vector@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11c8 <multiply_double_matrix_vector+0xb8>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11b5 <multiply_double_matrix_vector+0xa5>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115f <multiply_double_matrix_vector+0x4f>
jmp    11ba <multiply_double_matrix_vector+0xaa>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113c <multiply_double_matrix_vector+0x2c>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_double_matrix_vector>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x1(%rbp),%r12d
mov    %r12d,%edi
call   1030 <generate_zero_vector@plt>
test   %ebp,%ebp
jle    11e8 <multiply_double_matrix_vector+0xd8>
lea    0x1(%r14),%r8d
mov    %r12d,%r10d
lea    -0x1(%r8),%r9
mov    %r9,%rdi
and    $0xfffffffffffffffe,%rdi
neg    %rdi
mov    $0x1,%ebp
jmp    1169 <multiply_double_matrix_vector+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
cmp    %r10,%rbp
je     11e8 <multiply_double_matrix_vector+0xd8>
movq   $0x0,(%rax,%rbp,8)
test   %r14d,%r14d
jle    1160 <multiply_double_matrix_vector+0x50>
mov    (%r15,%rbp,8),%rcx
mov    $0x1,%esi
xorpd  %xmm0,%xmm0
cmp    $0x2,%r8d
je     11ca <multiply_double_matrix_vector+0xba>
nopl   0x0(%rax)
movsd  (%rcx,%rsi,8),%xmm1
mulsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rbp,8)
movsd  0x8(%rcx,%rsi,8),%xmm0
mulsd  0x8(%rbx,%rsi,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rbp,8)
lea    (%rdi,%rsi,1),%rdx
add    $0x2,%rdx
add    $0x2,%rsi
cmp    $0x1,%rdx
jne    1190 <multiply_double_matrix_vector+0x80>
test   $0x1,%r9b
je     1160 <multiply_double_matrix_vector+0x50>
movsd  (%rcx,%rsi,8),%xmm1
mulsd  (%rbx,%rsi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rbp,8)
jmp    1160 <multiply_double_matrix_vector+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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