void expVecTimesPlusAccum(int dim, double p1, const double *restrict v1,
                          double p2, const double *restrict v2,
                          double *restrict pacc, double *restrict vacc) {
  *pacc += p1 * p2;
  for (int i = 0; i < dim; ++i) {
    vacc[i] += (p2 * v1[i]) + (p1 * v2[i]);
  }
}


x86 assembly (clang, -O0):
<expVecTimesPlusAccum>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119e <expVecTimesPlusAccum+0x9e>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x10(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1146 <expVecTimesPlusAccum+0x46>
pop    %rbp
ret

x86 assembly (clang, -O2):
<expVecTimesPlusAccum>:
movapd %xmm0,%xmm2
mulsd  %xmm1,%xmm2
addsd  (%rcx),%xmm2
movsd  %xmm2,(%rcx)
test   %edi,%edi
jle    11db <expVecTimesPlusAccum+0xdb>
mov    %edi,%r9d
cmp    $0x4,%edi
jae    1127 <expVecTimesPlusAccum+0x27>
xor    %ecx,%ecx
jmp    11b0 <expVecTimesPlusAccum+0xb0>
mov    %r9d,%ecx
and    $0xfffffffc,%ecx
movapd %xmm0,%xmm2
unpcklpd %xmm0,%xmm2
movapd %xmm1,%xmm3
unpcklpd %xmm1,%xmm3
lea    0x0(,%r9,8),%rdi
and    $0xffffffffffffffe0,%rdi
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movupd (%rsi,%rax,1),%xmm4
movupd 0x10(%rsi,%rax,1),%xmm5
movupd (%rdx,%rax,1),%xmm6
movupd 0x10(%rdx,%rax,1),%xmm7
mulpd  %xmm2,%xmm6
mulpd  %xmm2,%xmm7
mulpd  %xmm3,%xmm4
addpd  %xmm6,%xmm4
mulpd  %xmm3,%xmm5
addpd  %xmm7,%xmm5
movupd (%r8,%rax,1),%xmm6
addpd  %xmm4,%xmm6
movupd 0x10(%r8,%rax,1),%xmm4
addpd  %xmm5,%xmm4
movupd %xmm6,(%r8,%rax,1)
movupd %xmm4,0x10(%r8,%rax,1)
add    $0x20,%rax
cmp    %rax,%rdi
jne    1150 <expVecTimesPlusAccum+0x50>
cmp    %r9,%rcx
je     11db <expVecTimesPlusAccum+0xdb>
xchg   %ax,%ax
movsd  (%rdx,%rcx,8),%xmm2
mulsd  %xmm0,%xmm2
movsd  (%rsi,%rcx,8),%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm2,%xmm3
addsd  (%r8,%rcx,8),%xmm3
movsd  %xmm3,(%r8,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%r9
jne    11b0 <expVecTimesPlusAccum+0xb0>
ret

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

LLVM IR (-O2):
define void @expVecTimesPlusAccum(i32 %0, double %1, double* noalias nocapture %2, double %3, double* noalias nocapture %4, double* noalias nocapture %5, double* noalias nocapture %6) {
%8 = load double, double* %5
%9 = tail call double @llvm.fmuladd.f64(double %1, double %3, double %8)
store double %9, double* %5
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %58
11: ; preds = %7
%12 = zext i32 %0 to i64
%13 = icmp ult i32 %0, 4
br i1 %13, label %56, label %14
14: ; preds = %11
%15 = and i64 %12, 4294967292
%16 = insertelement <2 x double> poison, double %1, i64 0
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
%18 = insertelement <2 x double> poison, double %1, i64 0
%19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
%20 = insertelement <2 x double> poison, double %3, i64 0
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%22 = insertelement <2 x double> poison, double %3, i64 0
%23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
br label %24
24: ; preds = %24, %14
%25 = phi i64 [ 0, %14 ], [ %52, %24 ]
%26 = getelementptr inbounds double, double* %2, i64 %25
%27 = bitcast double* %26 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = getelementptr inbounds double, double* %26, i64 2
%30 = bitcast double* %29 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = getelementptr inbounds double, double* %4, i64 %25
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %32, i64 2
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = fmul <2 x double> %34, %17
%39 = fmul <2 x double> %37, %19
%40 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %28, <2 x double> %38)
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %23, <2 x double> %31, <2 x double> %39)
%42 = getelementptr inbounds double, double* %6, i64 %25
%43 = bitcast double* %42 to <2 x double>*
%44 = load <2 x double>, <2 x double>* %43
%45 = getelementptr inbounds double, double* %42, i64 2
%46 = bitcast double* %45 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = fadd <2 x double> %44, %40
%49 = fadd <2 x double> %47, %41
%50 = bitcast double* %42 to <2 x double>*
store <2 x double> %48, <2 x double>* %50
%51 = bitcast double* %45 to <2 x double>*
store <2 x double> %49, <2 x double>* %51
%52 = add nuw i64 %25, 4
%53 = icmp eq i64 %52, %15
br i1 %53, label %54, label %24
54: ; preds = %24
%55 = icmp eq i64 %15, %12
br i1 %55, label %58, label %56
56: ; preds = %11, %54
%57 = phi i64 [ 0, %11 ], [ %15, %54 ]
br label %59
58: ; preds = %59, %54, %7
ret void
59: ; preds = %56, %59
%60 = phi i64 [ %70, %59 ], [ %57, %56 ]
%61 = getelementptr inbounds double, double* %2, i64 %60
%62 = load double, double* %61
%63 = getelementptr inbounds double, double* %4, i64 %60
%64 = load double, double* %63
%65 = fmul double %64, %1
%66 = tail call double @llvm.fmuladd.f64(double %3, double %62, double %65)
%67 = getelementptr inbounds double, double* %6, i64 %60
%68 = load double, double* %67
%69 = fadd double %68, %66
store double %69, double* %67
%70 = add nuw nsw i64 %60, 1
%71 = icmp eq i64 %70, %12
br i1 %71, label %58, label %59
}