#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*/ memcpy(double *, double *, int);
void mat_times_vec(double *mat, double *vec, double *out_vec, double *offset) {
  double temp[3];
  int i, j;
  for (i = 0; i < 3; i++) {
    temp[i] = 0;
    for (j = 0; j < 3; j++)
      temp[i] += mat[i * 3 + j] * (vec[j] - offset[j]);
    temp[i] += offset[i];
  }
  memcpy(out_vec, temp, 3 * sizeof(double));
}


x86 assembly (clang, -O0):
<mat_times_vec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jge    11d5 <mat_times_vec+0xc5>
movslq -0x44(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
movl   $0x0,-0x48(%rbp)
cmpl   $0x3,-0x48(%rbp)
jge    11aa <mat_times_vec+0x9a>
mov    -0x8(%rbp),%rax
imul   $0x3,-0x44(%rbp),%ecx
add    -0x48(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm2
movslq -0x44(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    114d <mat_times_vec+0x3d>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x44(%rbp),%rax
addsd  -0x40(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    112f <mat_times_vec+0x1f>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1030 <memcpy@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat_times_vec>:
sub    $0x18,%rsp
movupd (%rcx),%xmm4
movsd  (%rsi),%xmm2
movsd  0x8(%rsi),%xmm0
subsd  %xmm4,%xmm2
movapd %xmm4,%xmm1
unpckhpd %xmm4,%xmm1
subsd  %xmm1,%xmm0
movsd  0x10(%rsi),%xmm1
movsd  0x10(%rcx),%xmm8
subsd  %xmm8,%xmm1
movsd  (%rdi),%xmm5
movsd  0x8(%rdi),%xmm6
movsd  0x10(%rdi),%xmm7
movhpd 0x18(%rdi),%xmm5
movapd %xmm2,%xmm3
unpcklpd %xmm2,%xmm3
mulpd  %xmm5,%xmm3
xorpd  %xmm5,%xmm5
addpd  %xmm3,%xmm5
movhpd 0x20(%rdi),%xmm6
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
mulpd  %xmm6,%xmm3
addpd  %xmm5,%xmm3
movhpd 0x28(%rdi),%xmm7
movapd %xmm1,%xmm5
unpcklpd %xmm1,%xmm5
mulpd  %xmm7,%xmm5
addpd  %xmm3,%xmm5
addpd  %xmm4,%xmm5
movapd %xmm5,(%rsp)
mulsd  0x30(%rdi),%xmm2
xorpd  %xmm3,%xmm3
addsd  %xmm2,%xmm3
mulsd  0x38(%rdi),%xmm0
mulsd  0x40(%rdi),%xmm1
addsd  %xmm3,%xmm0
addsd  %xmm0,%xmm1
addsd  %xmm8,%xmm1
movsd  %xmm1,0x10(%rsp)
mov    %rsp,%rsi
mov    %rdx,%rdi
mov    $0x18,%edx
call   1030 <memcpy@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define void @mat_times_vec(double* nocapture %0, double* nocapture %1, double* %2, double* nocapture %3) {
%5 = alloca [3 x double]
%6 = bitcast [3 x double]* %5 to i8*
%7 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 0
%8 = load double, double* %0
%9 = load double, double* %1
%10 = bitcast double* %3 to <2 x double>*
%11 = load <2 x double>, <2 x double>* %10
%12 = extractelement <2 x double> %11, i64 0
%13 = fsub double %9, %12
%14 = getelementptr inbounds double, double* %0, i64 1
%15 = load double, double* %14
%16 = getelementptr inbounds double, double* %1, i64 1
%17 = load double, double* %16
%18 = extractelement <2 x double> %11, i64 1
%19 = fsub double %17, %18
%20 = getelementptr inbounds double, double* %0, i64 2
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %1, i64 2
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %3, i64 2
%25 = load double, double* %24
%26 = fsub double %23, %25
%27 = getelementptr inbounds double, double* %0, i64 3
%28 = load double, double* %27
%29 = insertelement <2 x double> poison, double %8, i64 0
%30 = insertelement <2 x double> %29, double %28, i64 1
%31 = insertelement <2 x double> poison, double %13, i64 0
%32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> zeroinitializer
%33 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %32, <2 x double> zeroinitializer)
%34 = getelementptr inbounds double, double* %0, i64 4
%35 = load double, double* %34
%36 = insertelement <2 x double> poison, double %15, i64 0
%37 = insertelement <2 x double> %36, double %35, i64 1
%38 = insertelement <2 x double> poison, double %19, i64 0
%39 = shufflevector <2 x double> %38, <2 x double> poison, <2 x i32> zeroinitializer
%40 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %37, <2 x double> %39, <2 x double> %33)
%41 = getelementptr inbounds double, double* %0, i64 5
%42 = load double, double* %41
%43 = insertelement <2 x double> poison, double %21, i64 0
%44 = insertelement <2 x double> %43, double %42, i64 1
%45 = insertelement <2 x double> poison, double %26, i64 0
%46 = shufflevector <2 x double> %45, <2 x double> poison, <2 x i32> zeroinitializer
%47 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %44, <2 x double> %46, <2 x double> %40)
%48 = fadd <2 x double> %11, %47
%49 = bitcast [3 x double]* %5 to <2 x double>*
store <2 x double> %48, <2 x double>* %49
%50 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 2
%51 = getelementptr inbounds double, double* %0, i64 6
%52 = load double, double* %51
%53 = tail call double @llvm.fmuladd.f64(double %52, double %13, double 0.000000e+00)
%54 = getelementptr inbounds double, double* %0, i64 7
%55 = load double, double* %54
%56 = tail call double @llvm.fmuladd.f64(double %55, double %19, double %53)
%57 = getelementptr inbounds double, double* %0, i64 8
%58 = load double, double* %57
%59 = tail call double @llvm.fmuladd.f64(double %58, double %26, double %56)
%60 = fadd double %25, %59
store double %60, double* %50
%61 = call i32 @memcpy(double* %2, double* %7, i32 24)
ret void
}