#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_bond_quad(size_t npair, int periodic, double *cor, long *pairs,
                    double *lengths, double amp, double *gradient,
                    double *matrix, double *reciprocal) {
  size_t b, i, j;
  double delta[3], result, d, tmp;
  result = 0.0;
  for (b = 0; b < npair; b++) {
    i = pairs[2 * b];
    j = pairs[2 * b + 1];
    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 - lengths[b];
    result += amp * tmp * tmp;
    if (gradient != NULL) {
      tmp = 2 * amp * tmp / d;
      add_grad(i, j, tmp, cor, delta, gradient);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<ff_bond_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,-0x78(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    12be <ff_bond_quad+0x18e>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
shl    $0x1,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
shl    $0x1,%rcx
mov    0x8(%rax,%rcx,8),%rax
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11eb <ff_bond_quad+0xbb>
mov    -0x18(%rbp),%rdi
imul   $0x3,-0x48(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
imul   $0x3,-0x50(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x70(%rbp),%rdx
mov    0x10(%rbp),%rcx
mov    0x18(%rbp),%r8
call   1040 <distance_delta_periodic@plt>
movsd  %xmm0,-0x80(%rbp)
jmp    1219 <ff_bond_quad+0xe9>
mov    -0x18(%rbp),%rdi
imul   $0x3,-0x48(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
imul   $0x3,-0x50(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x70(%rbp),%rdx
call   1050 <distance_delta@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
movsd  -0x88(%rbp),%xmm2
ff
movsd  -0x78(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12a8 <ff_bond_quad+0x178>
movsd  0xd93(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
divsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
movsd  -0x88(%rbp),%xmm0
ff
mov    -0x18(%rbp),%rdx
lea    -0x70(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1030 <add_grad@plt>
jmp    12ad <ff_bond_quad+0x17d>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    116f <ff_bond_quad+0x3f>
movsd  -0x78(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ff_bond_quad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,0x28(%rsp)
mov    %esi,0xc(%rsp)
mov    %rdi,0x20(%rsp)
test   %rdi,%rdi
je     1255 <ff_bond_quad+0x125>
mov    %r9,%r15
mov    %rcx,%rbx
mov    %rdx,%r12
movsd  %xmm0,0x18(%rsp)
addsd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
add    $0x8,%rbx
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
jmp    11af <ff_bond_quad+0x7f>
nopw   0x0(%rax,%rax,1)
movapd %xmm2,%xmm0
mulsd  0x18(%rsp),%xmm0
mulsd  %xmm2,%xmm0
movsd  0x38(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x1,%rbp
add    $0x10,%rbx
cmp    %rbp,0x20(%rsp)
je     1259 <ff_bond_quad+0x129>
mov    -0x8(%rbx),%r14
mov    (%rbx),%r13
lea    (%r14,%r14,2),%rax
lea    (%r12,%rax,8),%rdi
lea    0x0(,%r13,2),%rax
add    %r13,%rax
lea    (%r12,%rax,8),%rsi
cmpl   $0x0,0xc(%rsp)
movsd  %xmm0,0x38(%rsp)
lea    0x40(%rsp),%rdx
je     1200 <ff_bond_quad+0xd0>
mov    0x90(%rsp),%rcx
mov    0x98(%rsp),%r8
call   1040 <distance_delta_periodic@plt>
jmp    1205 <ff_bond_quad+0xd5>
cs nopw 0x0(%rax,%rax,1)
call   1050 <distance_delta@plt>
movapd %xmm0,%xmm2
mov    0x28(%rsp),%rax
subsd  (%rax,%rbp,8),%xmm2
test   %r15,%r15
je     1180 <ff_bond_quad+0x50>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
mov    %r14,%rdi
mov    %r13,%rsi
movapd %xmm1,%xmm0
mov    %r12,%rdx
lea    0x40(%rsp),%rcx
mov    %r15,%r8
movsd  %xmm2,0x30(%rsp)
call   1030 <add_grad@plt>
movsd  0x30(%rsp),%xmm2
jmp    1180 <ff_bond_quad+0x50>
xorpd  %xmm0,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @ff_bond_quad(i64 %0, i32 %1, double* %2, i64* 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 %49, 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, %46
%19 = phi double [ 0.000000e+00, %13 ], [ %41, %46 ]
%20 = phi i64 [ 0, %13 ], [ %47, %46 ]
%21 = shl i64 %20, 1
%22 = getelementptr inbounds i64, i64* %3, i64 %21
%23 = load i64, i64* %22
%24 = or i64 %21, 1
%25 = getelementptr inbounds i64, i64* %3, i64 %24
%26 = load i64, i64* %25
%27 = mul i64 %23, 3
%28 = getelementptr inbounds double, double* %2, i64 %27
%29 = mul i64 %26, 3
%30 = getelementptr inbounds double, double* %2, i64 %29
br i1 %14, label %33, label %31
31: ; preds = %18
%32 = call double @distance_delta_periodic(double* %28, double* %30, double* %15, double* %7, double* %8)
br label %35
33: ; preds = %18
%34 = call double @distance_delta(double* %28, double* %30, double* %15)
br label %35
35: ; preds = %33, %31
%36 = phi double [ %32, %31 ], [ %34, %33 ]
%37 = getelementptr inbounds double, double* %4, i64 %20
%38 = load double, double* %37
%39 = fsub double %36, %38
%40 = fmul double %39, %5
%41 = call double @llvm.fmuladd.f64(double %40, double %39, double %19)
br i1 %16, label %46, label %42
42: ; preds = %35
%43 = fmul double %17, %39
%44 = fdiv double %43, %36
%45 = call i32 @add_grad(i64 %23, i64 %26, double %44, double* %2, double* %15, double* %6)
br label %46
46: ; preds = %35, %42
%47 = add nuw i64 %20, 1
%48 = icmp eq i64 %47, %0
br i1 %48, label %49, label %18
49: ; preds = %46, %9
%50 = phi double [ 0.000000e+00, %9 ], [ %41, %46 ]
ret double %50
}