#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 */
void mat_vec_prod(size_t n, double *res, double **a, double *x) {
  for (size_t i = 0; i < n; i++) {
    res[i] = 0.0;
    for (size_t j = 0; j < n; j++) {
      res[i] += a[i][j] * x[j];
    }
  }
}


x86 assembly (clang, -O0):
<mat_vec_prod>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11b3 <mat_vec_prod+0xb3>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    119d <mat_vec_prod+0x9d>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1142 <mat_vec_prod+0x42>
jmp    11a2 <mat_vec_prod+0xa2>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    111c <mat_vec_prod+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat_vec_prod>:
test   %rdi,%rdi
je     11a5 <mat_vec_prod+0xa5>
mov    %rdi,%r8
and    $0xfffffffffffffffe,%r8
xor    %r9d,%r9d
jmp    1129 <mat_vec_prod+0x29>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r9
cmp    %rdi,%r9
je     11a5 <mat_vec_prod+0xa5>
movq   $0x0,(%rsi,%r9,8)
mov    (%rdx,%r9,8),%r10
xorpd  %xmm0,%xmm0
xor    %eax,%eax
cmp    $0x1,%rdi
je     1185 <mat_vec_prod+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%r10,%rax,8),%xmm1
mulsd  (%rcx,%rax,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi,%r9,8)
movsd  0x8(%r10,%rax,8),%xmm0
mulsd  0x8(%rcx,%rax,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsi,%r9,8)
add    $0x2,%rax
cmp    %rax,%r8
jne    1150 <mat_vec_prod+0x50>
test   $0x1,%dil
je     1120 <mat_vec_prod+0x20>
movsd  (%r10,%rax,8),%xmm1
mulsd  (%rcx,%rax,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi,%r9,8)
jmp    1120 <mat_vec_prod+0x20>
ret

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

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