#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 */
typedef int uint8_t;

/* Variables and functions */
void matrix_vector_multiply(double out[3], double a[3][3], double b[3]) {
  for (uint8_t row = 0; row < 3; row++) {
    out[row] = a[row][0] * b[0] + a[row][1] * b[1] + a[row][2] * b[2];
  }
}


x86 assembly (clang, -O0):
<matrix_vector_multiply>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11a1 <matrix_vector_multiply+0xa1>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <matrix_vector_multiply+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_vector_multiply>:
movsd  (%rsi),%xmm0
movsd  0x8(%rsi),%xmm1
mulsd  0x8(%rdx),%xmm1
mulsd  (%rdx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x10(%rsi),%xmm1
mulsd  0x10(%rdx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi)
movsd  0x18(%rsi),%xmm0
movsd  0x20(%rsi),%xmm1
mulsd  0x8(%rdx),%xmm1
mulsd  (%rdx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x28(%rsi),%xmm1
mulsd  0x10(%rdx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rdi)
movsd  0x30(%rsi),%xmm0
movsd  0x38(%rsi),%xmm1
mulsd  0x8(%rdx),%xmm1
mulsd  (%rdx),%xmm0
addsd  %xmm1,%xmm0
movsd  0x40(%rsi),%xmm1
mulsd  0x10(%rdx),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rdi)
ret

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

LLVM IR (-O2):
define void @matrix_vector_multiply(double* nocapture writeonly %0, [3 x double]* nocapture %1, double* nocapture %2) {
%4 = getelementptr inbounds double, double* %2, i64 1
%5 = getelementptr inbounds double, double* %2, i64 2
%6 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
%7 = load double, double* %6
%8 = load double, double* %2
%9 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 1
%10 = load double, double* %9
%11 = load double, double* %4
%12 = fmul double %10, %11
%13 = tail call double @llvm.fmuladd.f64(double %7, double %8, double %12)
%14 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 2
%15 = load double, double* %14
%16 = load double, double* %5
%17 = tail call double @llvm.fmuladd.f64(double %15, double %16, double %13)
store double %17, double* %0
%18 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 0
%19 = load double, double* %18
%20 = load double, double* %2
%21 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 1
%22 = load double, double* %21
%23 = load double, double* %4
%24 = fmul double %22, %23
%25 = tail call double @llvm.fmuladd.f64(double %19, double %20, double %24)
%26 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 2
%27 = load double, double* %26
%28 = load double, double* %5
%29 = tail call double @llvm.fmuladd.f64(double %27, double %28, double %25)
%30 = getelementptr inbounds double, double* %0, i64 1
store double %29, double* %30
%31 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 0
%32 = load double, double* %31
%33 = load double, double* %2
%34 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 1
%35 = load double, double* %34
%36 = load double, double* %4
%37 = fmul double %35, %36
%38 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %37)
%39 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 2
%40 = load double, double* %39
%41 = load double, double* %5
%42 = tail call double @llvm.fmuladd.f64(double %40, double %41, double %38)
%43 = getelementptr inbounds double, double* %0, i64 2
store double %42, double* %43
ret void
}