#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*/ add_grad(size_t, size_t, double, double *, double *,
                            double *);
double distance_delta(double *, double *, double *);
double distance_delta_periodic(double *, double *, double *, double *,
                               double *);
double ff_dm_quad(size_t natom, int periodic, double *cor, double *dm0,
                  double *dmk, double amp, double *gradient, double *matrix,
                  double *reciprocal) {
  size_t i, j;
  double delta[3], d, d0, k, tmp, result;
  result = 0.0;
  for (i = 0; i < natom; i++) {
    for (j = 0; j < i; j++) {
      d0 = dm0[i * natom + j];
      k = dmk[i * natom + j];
      if (d0 > 0) {
        if (periodic) {
          d = distance_delta_periodic(cor + 3 * i, cor + 3 * j, delta, matrix,
                                      reciprocal);
        } else {
          d = distance_delta(cor + 3 * i, cor + 3 * j, delta);
        }
        tmp = (d - d0);
        result += amp * k * tmp * tmp;
        if (gradient != NULL) {
          tmp = 2 * amp * k * tmp / d;
          add_grad(i, j, tmp, cor, delta, gradient);
        }
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<ff_dm_quad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1307 <ff_dm_quad+0x1d7>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12f1 <ff_dm_quad+0x1c1>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
imul   -0x8(%rbp),%rcx
add    -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
imul   -0x8(%rbp),%rcx
add    -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12db <ff_dm_quad+0x1ab>
cmpl   $0x0,-0xc(%rbp)
je     1223 <ff_dm_quad+0xf3>
mov    -0x18(%rbp),%rdi
imul   $0x3,-0x40(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
imul   $0x3,-0x48(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x60(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1040 <distance_delta_periodic@plt>
movsd  %xmm0,-0x68(%rbp)
jmp    1251 <ff_dm_quad+0x121>
mov    -0x18(%rbp),%rdi
imul   $0x3,-0x40(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
imul   $0x3,-0x48(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x60(%rbp),%rdx
call   1050 <distance_delta@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
subsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
mulsd  -0x80(%rbp),%xmm0
movsd  -0x80(%rbp),%xmm2
movsd  -0x88(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
cmpq   $0x0,-0x38(%rbp)
je     12d6 <ff_dm_quad+0x1a6>
movsd  0xd61(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
mulsd  -0x80(%rbp),%xmm0
divsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
movsd  -0x80(%rbp),%xmm0
mov    -0x18(%rbp),%rdx
lea    -0x60(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1030 <add_grad@plt>
jmp    12db <ff_dm_quad+0x1ab>
jmp    12e0 <ff_dm_quad+0x1b0>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1188 <ff_dm_quad+0x58>
jmp    12f6 <ff_dm_quad+0x1c6>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1172 <ff_dm_quad+0x42>
movsd  -0x88(%rbp),%xmm0
ff
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ff_dm_quad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,0x10(%rsp)
mov    %esi,0xc(%rsp)
test   %rdi,%rdi
je     12ca <ff_dm_quad+0x19a>
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%rbx
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x48(%rsp)
lea    0x0(,%rdi,8),%rax
mov    %rax,0x38(%rsp)
xorpd  %xmm1,%xmm1
xor    %r13d,%r13d
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x18(%rsp)
mov    %rdi,0x40(%rsp)
jmp    11b2 <ff_dm_quad+0x82>
nopl   0x0(%rax)
movapd %xmm2,%xmm4
add    $0x1,%r13
mov    0x38(%rsp),%rax
add    %rax,%r14
add    %rax,%rbx
movapd %xmm4,%xmm2
cmp    0x40(%rsp),%r13
je     12ce <ff_dm_quad+0x19e>
test   %r13,%r13
je     1190 <ff_dm_quad+0x60>
lea    0x0(,%r13,2),%rax
add    %r13,%rax
mov    0x10(%rsp),%rbp
lea    0x0(,%rax,8),%rax
add    %rbp,%rax
mov    %rax,0x20(%rsp)
xor    %r12d,%r12d
jmp    11f5 <ff_dm_quad+0xc5>
nopl   0x0(%rax)
movapd %xmm2,%xmm4
add    $0x1,%r12
add    $0x18,%rbp
movapd %xmm4,%xmm2
cmp    %r12,%r13
je     1194 <ff_dm_quad+0x64>
movsd  (%rbx,%r12,8),%xmm3
ucomisd %xmm1,%xmm3
jbe    11e0 <ff_dm_quad+0xb0>
movsd  (%r14,%r12,8),%xmm0
cmpl   $0x0,0xc(%rsp)
movsd  %xmm2,(%rsp)
movsd  %xmm0,0x30(%rsp)
movsd  %xmm3,0x28(%rsp)
je     1243 <ff_dm_quad+0x113>
mov    0x20(%rsp),%rdi
mov    %rbp,%rsi
lea    0x50(%rsp),%rdx
mov    0xa0(%rsp),%rcx
mov    0xa8(%rsp),%r8
call   1040 <distance_delta_periodic@plt>
jmp    1255 <ff_dm_quad+0x125>
mov    0x20(%rsp),%rdi
mov    %rbp,%rsi
lea    0x50(%rsp),%rdx
call   1050 <distance_delta@plt>
movsd  0x28(%rsp),%xmm4
movsd  0x30(%rsp),%xmm5
movsd  (%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movapd %xmm0,%xmm1
subsd  %xmm4,%xmm1
movapd %xmm5,%xmm4
mulsd  %xmm2,%xmm4
mulsd  %xmm1,%xmm4
mulsd  %xmm1,%xmm4
addsd  %xmm3,%xmm4
test   %r15,%r15
je     12c1 <ff_dm_quad+0x191>
mulsd  0x48(%rsp),%xmm5
mulsd  %xmm1,%xmm5
divsd  %xmm0,%xmm5
mov    %r13,%rdi
mov    %r12,%rsi
movapd %xmm5,%xmm0
mov    0x10(%rsp),%rdx
lea    0x50(%rsp),%rcx
mov    %r15,%r8
movsd  %xmm4,(%rsp)
call   1030 <add_grad@plt>
movsd  (%rsp),%xmm4
xorpd  %xmm1,%xmm1
jmp    11e4 <ff_dm_quad+0xb4>
xorpd  %xmm4,%xmm4
movapd %xmm4,%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @ff_dm_quad(i64 %0, i32 %1, double* %2, double* %3, double* %4, double %5, double* %6, double* %7, double* %8) {
%10 = alloca i64
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca double
%16 = alloca double*
%17 = alloca double*
%18 = alloca double*
%19 = alloca i64
%20 = alloca i64
%21 = alloca [3 x double]
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
store i64 %0, i64* %10
store i32 %1, i32* %11
store double* %2, double** %12
store double* %3, double** %13
store double* %4, double** %14
store double %5, double* %15
store double* %6, double** %16
store double* %7, double** %17
store double* %8, double** %18
store double 0.000000e+00, double* %26
store i64 0, i64* %19
br label %27
27: ; preds = %118, %9
%28 = load i64, i64* %19
%29 = load i64, i64* %10
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %121
31: ; preds = %27
store i64 0, i64* %20
br label %32
32: ; preds = %114, %31
%33 = load i64, i64* %20
%34 = load i64, i64* %19
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %117
36: ; preds = %32
%37 = load double*, double** %13
%38 = load i64, i64* %19
%39 = load i64, i64* %10
%40 = mul i64 %38, %39
%41 = load i64, i64* %20
%42 = add i64 %40, %41
%43 = getelementptr inbounds double, double* %37, i64 %42
%44 = load double, double* %43
store double %44, double* %23
%45 = load double*, double** %14
%46 = load i64, i64* %19
%47 = load i64, i64* %10
%48 = mul i64 %46, %47
%49 = load i64, i64* %20
%50 = add i64 %48, %49
%51 = getelementptr inbounds double, double* %45, i64 %50
%52 = load double, double* %51
store double %52, double* %24
%53 = load double, double* %23
%54 = fcmp ogt double %53, 0.000000e+00
br i1 %54, label %55, label %113
55: ; preds = %36
%56 = load i32, i32* %11
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %71
58: ; preds = %55
%59 = load double*, double** %12
%60 = load i64, i64* %19
%61 = mul i64 3, %60
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double*, double** %12
%64 = load i64, i64* %20
%65 = mul i64 3, %64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = getelementptr inbounds [3 x double], [3 x double]* %21, i64 0, i64 0
%68 = load double*, double** %17
%69 = load double*, double** %18
%70 = call double @distance_delta_periodic(double* %62, double* %66, double* %67, double* %68, double* %69)
store double %70, double* %22
br label %82
71: ; preds = %55
%72 = load double*, double** %12
%73 = load i64, i64* %19
%74 = mul i64 3, %73
%75 = getelementptr inbounds double, double* %72, i64 %74
%76 = load double*, double** %12
%77 = load i64, i64* %20
%78 = mul i64 3, %77
%79 = getelementptr inbounds double, double* %76, i64 %78
%80 = getelementptr inbounds [3 x double], [3 x double]* %21, i64 0, i64 0
%81 = call double @distance_delta(double* %75, double* %79, double* %80)
store double %81, double* %22
br label %82
82: ; preds = %71, %58
%83 = load double, double* %22
%84 = load double, double* %23
%85 = fsub double %83, %84
store double %85, double* %25
%86 = load double, double* %15
%87 = load double, double* %24
%88 = fmul double %86, %87
%89 = load double, double* %25
%90 = fmul double %88, %89
%91 = load double, double* %25
%92 = load double, double* %26
%93 = call double @llvm.fmuladd.f64(double %90, double %91, double %92)
store double %93, double* %26
%94 = load double*, double** %16
%95 = icmp ne double* %94, null
br i1 %95, label %96, label %112
96: ; preds = %82
%97 = load double, double* %15
%98 = fmul double 2.000000e+00, %97
%99 = load double, double* %24
%100 = fmul double %98, %99
%101 = load double, double* %25
%102 = fmul double %100, %101
%103 = load double, double* %22
%104 = fdiv double %102, %103
store double %104, double* %25
%105 = load i64, i64* %19
%106 = load i64, i64* %20
%107 = load double, double* %25
%108 = load double*, double** %12
%109 = getelementptr inbounds [3 x double], [3 x double]* %21, i64 0, i64 0
%110 = load double*, double** %16
%111 = call i32 @add_grad(i64 %105, i64 %106, double %107, double* %108, double* %109, double* %110)
br label %112
112: ; preds = %96, %82
br label %113
113: ; preds = %112, %36
br label %114
114: ; preds = %113
%115 = load i64, i64* %20
%116 = add i64 %115, 1
store i64 %116, i64* %20
br label %32
117: ; preds = %32
br label %118
118: ; preds = %117
%119 = load i64, i64* %19
%120 = add i64 %119, 1
store i64 %120, i64* %19
br label %27
121: ; preds = %27
%122 = load double, double* %26
ret double %122
}

LLVM IR (-O2):
define double @ff_dm_quad(i64 %0, i32 %1, double* %2, double* nocapture %3, double* nocapture %4, double %5, double* %6, double* %7, double* %8) {
%10 = alloca [3 x double]
%11 = bitcast [3 x double]* %10 to i8*
%12 = icmp eq i64 %0, 0
br i1 %12, label %61, label %13
13: ; preds = %9
%14 = icmp eq i32 %1, 0
%15 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%16 = icmp eq double* %6, null
%17 = fmul double %5, 2.000000e+00
br label %18
18: ; preds = %13, %57
%19 = phi double [ 0.000000e+00, %13 ], [ %58, %57 ]
%20 = phi i64 [ 0, %13 ], [ %59, %57 ]
%21 = icmp eq i64 %20, 0
br i1 %21, label %57, label %22
22: ; preds = %18
%23 = mul i64 %20, %0
%24 = mul i64 %20, 3
%25 = getelementptr inbounds double, double* %2, i64 %24
br label %26
26: ; preds = %22, %53
%27 = phi double [ %19, %22 ], [ %54, %53 ]
%28 = phi i64 [ 0, %22 ], [ %55, %53 ]
%29 = add i64 %28, %23
%30 = getelementptr inbounds double, double* %3, i64 %29
%31 = load double, double* %30
%32 = getelementptr inbounds double, double* %4, i64 %29
%33 = load double, double* %32
%34 = fcmp ogt double %31, 0.000000e+00
br i1 %34, label %35, label %53
35: ; preds = %26
%36 = mul i64 %28, 3
%37 = getelementptr inbounds double, double* %2, i64 %36
br i1 %14, label %40, label %38
38: ; preds = %35
%39 = call double @distance_delta_periodic(double* %25, double* %37, double* %15, double* %7, double* %8)
br label %42
40: ; preds = %35
%41 = call double @distance_delta(double* %25, double* %37, double* %15)
br label %42
42: ; preds = %40, %38
%43 = phi double [ %39, %38 ], [ %41, %40 ]
%44 = fsub double %43, %31
%45 = fmul double %33, %5
%46 = fmul double %45, %44
%47 = call double @llvm.fmuladd.f64(double %46, double %44, double %27)
br i1 %16, label %53, label %48
48: ; preds = %42
%49 = fmul double %17, %33
%50 = fmul double %49, %44
%51 = fdiv double %50, %43
%52 = call i32 @add_grad(i64 %20, i64 %28, double %51, double* %2, double* %15, double* %6)
br label %53
53: ; preds = %26, %48, %42
%54 = phi double [ %47, %48 ], [ %47, %42 ], [ %27, %26 ]
%55 = add nuw i64 %28, 1
%56 = icmp eq i64 %55, %20
br i1 %56, label %57, label %26
57: ; preds = %53, %18
%58 = phi double [ %19, %18 ], [ %54, %53 ]
%59 = add nuw i64 %20, 1
%60 = icmp eq i64 %59, %0
br i1 %60, label %61, label %18
61: ; preds = %57, %9
%62 = phi double [ 0.000000e+00, %9 ], [ %58, %57 ]
ret double %62
}