#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 */
int /*<<< orphan*/ check_alloc(double *);
scalar_t__ malloc(int);
double *multiply_matrix_vector(double **mat, double *vec, unsigned int size) {
  long i, j;
  double *new_vec;
  check_alloc(new_vec = (double *)malloc(sizeof(double) * size));
  for (i = 0; i < size; i++) {
    new_vec[i] = 0.0;
    for (j = 0; j < size; j++)
      new_vec[i] += mat[i][j] * vec[j];
  }
  return new_vec;
}


x86 assembly (clang, -O0):
<multiply_matrix_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x30(%rbp)
call   1040 <check_alloc@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jge    11f0 <multiply_matrix_vector+0xd0>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jge    11da <multiply_matrix_vector+0xba>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117d <multiply_matrix_vector+0x5d>
jmp    11df <multiply_matrix_vector+0xbf>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1155 <multiply_matrix_vector+0x35>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_matrix_vector>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r15
lea    0x0(,%r14,8),%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <check_alloc@plt>
test   %r14d,%r14d
je     11dd <multiply_matrix_vector+0xbd>
mov    %r14d,%eax
mov    %eax,%ecx
and    $0xfffffffe,%ecx
xor    %edx,%edx
jmp    1169 <multiply_matrix_vector+0x49>
xchg   %ax,%ax
add    $0x1,%rdx
cmp    %rax,%rdx
je     11dd <multiply_matrix_vector+0xbd>
movq   $0x0,(%rbx,%rdx,8)
mov    (%r15,%rdx,8),%rsi
xorpd  %xmm0,%xmm0
xor    %edi,%edi
cmp    $0x1,%r14d
je     11c3 <multiply_matrix_vector+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rsi,%rdi,8),%xmm1
mulsd  (%r12,%rdi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rdx,8)
movsd  0x8(%rsi,%rdi,8),%xmm0
mulsd  0x8(%r12,%rdi,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rdx,8)
add    $0x2,%rdi
cmp    %rdi,%rcx
jne    1190 <multiply_matrix_vector+0x70>
test   $0x1,%al
je     1160 <multiply_matrix_vector+0x40>
movsd  (%rsi,%rdi,8),%xmm1
mulsd  (%r12,%rdi,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rdx,8)
jmp    1160 <multiply_matrix_vector+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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