#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(int, int, double, double *, double *);
int /*<<< orphan*/ calc_delta(double *, double *, double *, double *, double *,
                              int *);
double sqrt(double);
double ff_dm_reci(int n, double *radii, double *cor, int *dm0, double amp,
                  double *unitcell, double *unitcell_reciproke,
                  int *unitcell_active, double *gradient) {
  int i, j, d0, r0;
  double d, tmp, result;
  double delta[3];
  result = 0.0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < i; j++) {
      d0 = dm0[i * n + j];
      if (d0 > 1) {
        calc_delta(cor + 3 * i, cor + 3 * j, delta, unitcell,
                   unitcell_reciproke, unitcell_active);
        tmp = delta[0];
        d = tmp * tmp;
        tmp = delta[1];
        d += tmp * tmp;
        tmp = delta[2];
        d += tmp * tmp;
        d = sqrt(d);
        r0 = radii[i] + radii[j];
        if (d < r0) {
          d /= r0;
          result += amp * (d - 1) * (d - 1) / d / d0;
          if (gradient != NULL) {
            tmp = amp * (1 - 1 / d / d) / r0 / d / d0;
            add_grad(i, j, tmp, delta, gradient);
          }
        }
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<ff_dm_reci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    137e <ff_dm_reci+0x24e>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    136b <ff_dm_reci+0x23b>
mov    -0x20(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x4(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x1,-0x44(%rbp)
jle    1358 <ff_dm_reci+0x228>
mov    -0x18(%rbp),%rdi
imul   $0x3,-0x3c(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
imul   $0x3,-0x40(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x80(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    0x10(%rbp),%r9
call   1030 <calc_delta@plt>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm1
cvtsi2sdl -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1353 <ff_dm_reci+0x223>
cvtsi2sdl -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  0xd4d(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x50(%rbp),%xmm1
movsd  0xd38(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
cmpq   $0x0,0x18(%rbp)
je     134e <ff_dm_reci+0x21e>
movsd  -0x28(%rbp),%xmm0
movsd  0xd00(%rip),%xmm2
divsd  -0x50(%rbp),%xmm2
divsd  -0x50(%rbp),%xmm2
movsd  0xcee(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x48(%rbp),%xmm1
divsd  %xmm1,%xmm0
divsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x40(%rbp),%esi
movsd  -0x58(%rbp),%xmm0
lea    -0x80(%rbp),%rdx
mov    0x18(%rbp),%rcx
call   1040 <add_grad@plt>
jmp    1353 <ff_dm_reci+0x223>
jmp    1358 <ff_dm_reci+0x228>
jmp    135d <ff_dm_reci+0x22d>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1181 <ff_dm_reci+0x51>
jmp    1370 <ff_dm_reci+0x240>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    116e <ff_dm_reci+0x3e>
movsd  -0x60(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ff_dm_reci>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,0x50(%rsp)
mov    %r8,0x48(%rsp)
mov    %rdx,0x28(%rsp)
mov    %rsi,0x20(%rsp)
test   %edi,%edi
jle    1330 <ff_dm_reci+0x200>
movapd %xmm0,%xmm5
mov    %rcx,%r13
mov    %edi,%eax
mov    %rax,0x38(%rsp)
lea    0x0(,%rax,4),%rax
mov    %rax,0x30(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  %xmm5,0x18(%rsp)
jmp    11ad <ff_dm_reci+0x7d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rsi
mov    0x40(%rsp),%r13
add    0x30(%rsp),%r13
add    $0x3,%rdi
cmp    0x38(%rsp),%rsi
je     133a <ff_dm_reci+0x20a>
test   %rsi,%rsi
mov    %r13,0x40(%rsp)
je     1190 <ff_dm_reci+0x60>
lea    (%rsi,%rsi,2),%eax
mov    0x28(%rsp),%rdx
lea    (%rdx,%rax,8),%rax
mov    %rax,0x58(%rsp)
xor    %r14d,%r14d
mov    0x20(%rsp),%rbx
xor    %ebp,%ebp
mov    %rdi,0x10(%rsp)
jmp    11fa <ff_dm_reci+0xca>
nopl   0x0(%rax)
mov    0x10(%rsp),%rdi
add    $0x3,%rbp
add    $0x1,%r14d
add    $0x4,%r13
add    $0x8,%rbx
cmp    %rbp,%rdi
je     1190 <ff_dm_reci+0x60>
mov    0x0(%r13),%r15d
cmp    $0x2,%r15d
jl     11e5 <ff_dm_reci+0xb5>
mov    %rsi,%r12
mov    %ebp,%eax
mov    0x28(%rsp),%rcx
lea    (%rcx,%rax,8),%rsi
mov    0x58(%rsp),%rdi
lea    0x60(%rsp),%rdx
mov    0x48(%rsp),%rcx
mov    0x50(%rsp),%r8
mov    0xb0(%rsp),%r9
call   1030 <calc_delta@plt>
movsd  0x60(%rsp),%xmm0
movsd  0x68(%rsp),%xmm1
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x70(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd 0xdaf(%rip),%xmm0
jb     1270 <ff_dm_reci+0x140>
sqrtsd %xmm0,%xmm0
jmp    1275 <ff_dm_reci+0x145>
nopl   0x0(%rax)
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm5
mov    %r12,%rsi
mov    0x20(%rsp),%rax
movsd  (%rax,%r12,8),%xmm1
addsd  (%rbx),%xmm1
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jbe    11e0 <ff_dm_reci+0xb0>
divsd  %xmm2,%xmm0
movapd %xmm0,%xmm1
addsd  0xd51(%rip),%xmm1
movapd %xmm1,%xmm4
mulsd  %xmm5,%xmm4
mulsd  %xmm1,%xmm4
xorps  %xmm3,%xmm3
cvtsi2sd %r15d,%xmm3
divsd  %xmm0,%xmm4
divsd  %xmm3,%xmm4
movsd  0x8(%rsp),%xmm1
addsd  %xmm4,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    0xb8(%rsp),%rcx
test   %rcx,%rcx
je     11e0 <ff_dm_reci+0xb0>
movsd  0xd14(%rip),%xmm1
movapd %xmm1,%xmm4
divsd  %xmm0,%xmm4
divsd  %xmm0,%xmm4
subsd  %xmm4,%xmm1
mulsd  %xmm5,%xmm1
divsd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
divsd  %xmm3,%xmm1
mov    %r12d,%edi
mov    %r14d,%esi
movapd %xmm1,%xmm0
lea    0x60(%rsp),%rdx
call   1040 <add_grad@plt>
mov    %r12,%rsi
jmp    11e0 <ff_dm_reci+0xb0>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @ff_dm_reci(i32 %0, double* %1, double* %2, i32* %3, double %4, double* %5, double* %6, i32* %7, double* %8) {
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32*
%14 = alloca double
%15 = alloca double*
%16 = alloca double*
%17 = alloca i32*
%18 = alloca double*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca [3 x double]
store i32 %0, i32* %10
store double* %1, double** %11
store double* %2, double** %12
store i32* %3, i32** %13
store double %4, double* %14
store double* %5, double** %15
store double* %6, double** %16
store i32* %7, i32** %17
store double* %8, double** %18
store double 0.000000e+00, double* %25
store i32 0, i32* %19
br label %27
27: ; preds = %149, %9
%28 = load i32, i32* %19
%29 = load i32, i32* %10
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %152
31: ; preds = %27
store i32 0, i32* %20
br label %32
32: ; preds = %145, %31
%33 = load i32, i32* %20
%34 = load i32, i32* %19
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %148
36: ; preds = %32
%37 = load i32*, i32** %13
%38 = load i32, i32* %19
%39 = load i32, i32* %10
%40 = mul nsw i32 %38, %39
%41 = load i32, i32* %20
%42 = add nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %37, i64 %43
%45 = load i32, i32* %44
store i32 %45, i32* %21
%46 = load i32, i32* %21
%47 = icmp sgt i32 %46, 1
br i1 %47, label %48, label %144
48: ; preds = %36
%49 = load double*, double** %12
%50 = load i32, i32* %19
%51 = mul nsw i32 3, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %49, i64 %52
%54 = load double*, double** %12
%55 = load i32, i32* %20
%56 = mul nsw i32 3, %55
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %54, i64 %57
%59 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0, i64 0
%60 = load double*, double** %15
%61 = load double*, double** %16
%62 = load i32*, i32** %17
%63 = call i32 @calc_delta(double* %53, double* %58, double* %59, double* %60, double* %61, i32* %62)
%64 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0, i64 0
%65 = load double, double* %64
store double %65, double* %24
%66 = load double, double* %24
%67 = load double, double* %24
%68 = fmul double %66, %67
store double %68, double* %23
%69 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0, i64 1
%70 = load double, double* %69
store double %70, double* %24
%71 = load double, double* %24
%72 = load double, double* %24
%73 = load double, double* %23
%74 = call double @llvm.fmuladd.f64(double %71, double %72, double %73)
store double %74, double* %23
%75 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0, i64 2
%76 = load double, double* %75
store double %76, double* %24
%77 = load double, double* %24
%78 = load double, double* %24
%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* %23
%82 = call double @sqrt(double %81)
store double %82, double* %23
%83 = load double*, double** %11
%84 = load i32, i32* %19
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
%87 = load double, double* %86
%88 = load double*, double** %11
%89 = load i32, i32* %20
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
%92 = load double, double* %91
%93 = fadd double %87, %92
%94 = fptosi double %93 to i32
store i32 %94, i32* %22
%95 = load double, double* %23
%96 = load i32, i32* %22
%97 = sitofp i32 %96 to double
%98 = fcmp olt double %95, %97
br i1 %98, label %99, label %143
99: ; preds = %48
%100 = load i32, i32* %22
%101 = sitofp i32 %100 to double
%102 = load double, double* %23
%103 = fdiv double %102, %101
store double %103, double* %23
%104 = load double, double* %14
%105 = load double, double* %23
%106 = fsub double %105, 1.000000e+00
%107 = fmul double %104, %106
%108 = load double, double* %23
%109 = fsub double %108, 1.000000e+00
%110 = fmul double %107, %109
%111 = load double, double* %23
%112 = fdiv double %110, %111
%113 = load i32, i32* %21
%114 = sitofp i32 %113 to double
%115 = fdiv double %112, %114
%116 = load double, double* %25
%117 = fadd double %116, %115
store double %117, double* %25
%118 = load double*, double** %18
%119 = icmp ne double* %118, null
br i1 %119, label %120, label %142
120: ; preds = %99
%121 = load double, double* %14
%122 = load double, double* %23
%123 = fdiv double 1.000000e+00, %122
%124 = load double, double* %23
%125 = fdiv double %123, %124
%126 = fsub double 1.000000e+00, %125
%127 = fmul double %121, %126
%128 = load i32, i32* %22
%129 = sitofp i32 %128 to double
%130 = fdiv double %127, %129
%131 = load double, double* %23
%132 = fdiv double %130, %131
%133 = load i32, i32* %21
%134 = sitofp i32 %133 to double
%135 = fdiv double %132, %134
store double %135, double* %24
%136 = load i32, i32* %19
%137 = load i32, i32* %20
%138 = load double, double* %24
%139 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0, i64 0
%140 = load double*, double** %18
%141 = call i32 @add_grad(i32 %136, i32 %137, double %138, double* %139, double* %140)
br label %142
142: ; preds = %120, %99
br label %143
143: ; preds = %142, %48
br label %144
144: ; preds = %143, %36
br label %145
145: ; preds = %144
%146 = load i32, i32* %20
%147 = add nsw i32 %146, 1
store i32 %147, i32* %20
br label %32
148: ; preds = %32
br label %149
149: ; preds = %148
%150 = load i32, i32* %19
%151 = add nsw i32 %150, 1
store i32 %151, i32* %19
br label %27
152: ; preds = %27
%153 = load double, double* %25
ret double %153
}

LLVM IR (-O2):
define double @ff_dm_reci(i32 %0, double* nocapture %1, double* %2, i32* nocapture %3, double %4, double* %5, double* %6, i32* %7, double* %8) {
%10 = alloca [3 x double]
%11 = bitcast [3 x double]* %10 to i8*
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %84
13: ; preds = %9
%14 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 0
%15 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 1
%16 = getelementptr inbounds [3 x double], [3 x double]* %10, i64 0, i64 2
%17 = icmp eq double* %8, null
%18 = zext i32 %0 to i64
%19 = zext i32 %0 to i64
br label %20
20: ; preds = %13, %80
%21 = phi i64 [ 0, %13 ], [ %82, %80 ]
%22 = phi double [ 0.000000e+00, %13 ], [ %81, %80 ]
%23 = icmp eq i64 %21, 0
br i1 %23, label %80, label %24
24: ; preds = %20
%25 = mul nsw i64 %21, %18
%26 = mul i64 %21, 3
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds double, double* %2, i64 %27
%29 = getelementptr inbounds double, double* %1, i64 %21
%30 = trunc i64 %21 to i32
br label %31
31: ; preds = %24, %76
%32 = phi i64 [ 0, %24 ], [ %78, %76 ]
%33 = phi double [ %22, %24 ], [ %77, %76 ]
%34 = add nuw nsw i64 %32, %25
%35 = getelementptr inbounds i32, i32* %3, i64 %34
%36 = load i32, i32* %35
%37 = icmp sgt i32 %36, 1
br i1 %37, label %38, label %76
38: ; preds = %31
%39 = mul i64 %32, 3
%40 = and i64 %39, 4294967295
%41 = getelementptr inbounds double, double* %2, i64 %40
%42 = call i32 @calc_delta(double* %28, double* %41, double* %14, double* %5, double* %6, i32* %7)
%43 = load double, double* %14
%44 = fmul double %43, %43
%45 = load double, double* %15
%46 = call double @llvm.fmuladd.f64(double %45, double %45, double %44)
%47 = load double, double* %16
%48 = call double @llvm.fmuladd.f64(double %47, double %47, double %46)
%49 = call double @sqrt(double %48)
%50 = load double, double* %29
%51 = getelementptr inbounds double, double* %1, i64 %32
%52 = load double, double* %51
%53 = fadd double %50, %52
%54 = fptosi double %53 to i32
%55 = sitofp i32 %54 to double
%56 = fcmp olt double %49, %55
br i1 %56, label %57, label %76
57: ; preds = %38
%58 = fdiv double %49, %55
%59 = fadd double %58, -1.000000e+00
%60 = fmul double %59, %4
%61 = fmul double %59, %60
%62 = fdiv double %61, %58
%63 = sitofp i32 %36 to double
%64 = fdiv double %62, %63
%65 = fadd double %33, %64
br i1 %17, label %76, label %66
66: ; preds = %57
%67 = fdiv double 1.000000e+00, %58
%68 = fdiv double %67, %58
%69 = fsub double 1.000000e+00, %68
%70 = fmul double %69, %4
%71 = fdiv double %70, %55
%72 = fdiv double %71, %58
%73 = fdiv double %72, %63
%74 = trunc i64 %32 to i32
%75 = call i32 @add_grad(i32 %30, i32 %74, double %73, double* %14, double* %8)
br label %76
76: ; preds = %31, %57, %66, %38
%77 = phi double [ %65, %66 ], [ %65, %57 ], [ %33, %38 ], [ %33, %31 ]
%78 = add nuw nsw i64 %32, 1
%79 = icmp eq i64 %78, %21
br i1 %79, label %80, label %31
80: ; preds = %76, %20
%81 = phi double [ %22, %20 ], [ %77, %76 ]
%82 = add nuw nsw i64 %21, 1
%83 = icmp eq i64 %82, %19
br i1 %83, label %84, label %20
84: ; preds = %80, %9
%85 = phi double [ 0.000000e+00, %9 ], [ %81, %80 ]
ret double %85
}