double get_A(const int atom_i, const int cart_i, const double q[3],
             const double *born) {
  int i;
  double sum;
  sum = 0;
  for (i = 0; i < 3; i++) {
    sum += q[i] * born[atom_i * 9 + i * 3 + cart_i];
  }
  return sum;
}


x86 assembly (clang, -O0):
<get_A>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1171 <get_A+0x71>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
imul   $0x9,-0x4(%rbp),%ecx
imul   $0x3,-0x1c(%rbp),%edx
add    %edx,%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1121 <get_A+0x21>
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_A>:
lea    (%rdi,%rdi,8),%eax
lea    (%rax,%rsi,1),%edi
movslq %edi,%rdi
movsd  (%rdx),%xmm0
movsd  0x8(%rdx),%xmm1
mulsd  (%rcx,%rdi,8),%xmm0
xorpd  %xmm2,%xmm2
lea    0x3(%rsi,%rax,1),%edi
movslq %edi,%rdi
mulsd  (%rcx,%rdi,8),%xmm1
addsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
movsd  0x10(%rdx),%xmm0
lea    0x6(%rsi,%rax,1),%eax
cltq
mulsd  (%rcx,%rax,8),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @get_A(i32 %0, i32 %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
store double 0.000000e+00, double* %10
store i32 0, i32* %9
br label %11
11: ; preds = %33, %4
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = load double*, double** %7
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = load double*, double** %8
%21 = load i32, i32* %5
%22 = mul nsw i32 %21, 9
%23 = load i32, i32* %9
%24 = mul nsw i32 %23, 3
%25 = add nsw i32 %22, %24
%26 = load i32, i32* %6
%27 = add nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %20, i64 %28
%30 = load double, double* %29
%31 = load double, double* %10
%32 = call double @llvm.fmuladd.f64(double %19, double %30, double %31)
store double %32, double* %10
br label %33
33: ; preds = %14
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
store i32 %35, i32* %9
br label %11
36: ; preds = %11
%37 = load double, double* %10
ret double %37
}

LLVM IR (-O2):
define double @get_A(i32 %0, i32 %1, double* nocapture %2, double* nocapture %3) {
%5 = mul nsw i32 %0, 9
%6 = add i32 %5, %1
%7 = load double, double* %2
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds double, double* %3, i64 %8
%10 = load double, double* %9
%11 = tail call double @llvm.fmuladd.f64(double %7, double %10, double 0.000000e+00)
%12 = getelementptr inbounds double, double* %2, i64 1
%13 = load double, double* %12
%14 = add i32 %6, 3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %3, i64 %15
%17 = load double, double* %16
%18 = tail call double @llvm.fmuladd.f64(double %13, double %17, double %11)
%19 = getelementptr inbounds double, double* %2, i64 2
%20 = load double, double* %19
%21 = add i32 %6, 6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %3, i64 %22
%24 = load double, double* %23
%25 = tail call double @llvm.fmuladd.f64(double %20, double %24, double %18)
ret double %25
}