double s_ff(const double *h, const double *d, double zeta, double *kv, int a,
            int b) {
  return (h[a] * d[b] + h[b] * d[a]) * zeta + h[a] * kv[b];
}


x86 assembly (clang, -O0):
<s_ff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm2
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_ff>:
movslq %ecx,%rax
movslq %r8d,%rcx
movsd  (%rdi,%rcx,8),%xmm1
mulsd  (%rsi,%rax,8),%xmm1
movsd  (%rdi,%rax,8),%xmm2
movsd  (%rsi,%rcx,8),%xmm3
mulsd  %xmm2,%xmm3
addsd  %xmm1,%xmm3
mulsd  (%rdx,%rcx,8),%xmm2
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @s_ff(double* %0, double* %1, double %2, double* %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store double %2, double* %9
store double* %3, double** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%13 = load double*, double** %7
%14 = load i32, i32* %11
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = load double*, double** %8
%19 = load i32, i32* %12
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %7
%24 = load i32, i32* %12
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %8
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = fmul double %27, %32
%34 = call double @llvm.fmuladd.f64(double %17, double %22, double %33)
%35 = load double, double* %9
%36 = load double*, double** %7
%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 = load double*, double** %10
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = fmul double %40, %45
%47 = call double @llvm.fmuladd.f64(double %34, double %35, double %46)
ret double %47
}

LLVM IR (-O2):
define double @s_ff(double* nocapture %0, double* nocapture %1, double %2, double* nocapture %3, i32 %4, i32 %5) {
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds double, double* %0, i64 %7
%9 = load double, double* %8
%10 = sext i32 %5 to i64
%11 = getelementptr inbounds double, double* %1, i64 %10
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %0, i64 %10
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %1, i64 %7
%16 = load double, double* %15
%17 = fmul double %14, %16
%18 = tail call double @llvm.fmuladd.f64(double %9, double %12, double %17)
%19 = getelementptr inbounds double, double* %3, i64 %10
%20 = load double, double* %19
%21 = fmul double %9, %20
%22 = tail call double @llvm.fmuladd.f64(double %18, double %2, double %21)
ret double %22
}