double compute_ewald_deltae(double *deltacosfacs, double *cosfacs,
                            double *deltasinfacs, double *sinfacs,
                            double *prefactors, long nk) {
  long index;
  double e;
  e = 0.0;
  for (index = 0; index < nk; index++) {
    e += (cosfacs[index] * deltacosfacs[index] +
          sinfacs[index] * deltasinfacs[index]) *
         prefactors[index];
  }
  return 2.0 * e;
}


x86 assembly (clang, -O0):
<compute_ewald_deltae>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    11a6 <compute_ewald_deltae+0xa6>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    112c <compute_ewald_deltae+0x2c>
movsd  0xe52(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_ewald_deltae>:
test   %r9,%r9
jle    1113 <compute_ewald_deltae+0x13>
cmp    $0x1,%r9
jne    1117 <compute_ewald_deltae+0x17>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
jmp    1186 <compute_ewald_deltae+0x86>
xorps  %xmm0,%xmm0
ret
mov    %r9,%r10
and    $0xfffffffffffffffe,%r10
xorpd  %xmm1,%xmm1
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rcx,%rax,8),%xmm2
mulsd  (%rdx,%rax,8),%xmm2
movsd  0x8(%rcx,%rax,8),%xmm3
movsd  (%rsi,%rax,8),%xmm4
mulsd  (%rdi,%rax,8),%xmm4
movsd  0x8(%rsi,%rax,8),%xmm0
addsd  %xmm2,%xmm4
mulsd  (%r8,%rax,8),%xmm4
mulsd  0x8(%rdx,%rax,8),%xmm3
mulsd  0x8(%rdi,%rax,8),%xmm0
addsd  %xmm3,%xmm0
mulsd  0x8(%r8,%rax,8),%xmm0
addsd  %xmm1,%xmm4
addsd  %xmm4,%xmm0
add    $0x2,%rax
movapd %xmm0,%xmm1
cmp    %rax,%r10
jne    1130 <compute_ewald_deltae+0x30>
test   $0x1,%r9b
je     11ae <compute_ewald_deltae+0xae>
movsd  (%rsi,%rax,8),%xmm1
movsd  (%rcx,%rax,8),%xmm2
mulsd  (%rdx,%rax,8),%xmm2
mulsd  (%rdi,%rax,8),%xmm1
addsd  %xmm2,%xmm1
mulsd  (%r8,%rax,8),%xmm1
addsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
ret

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

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