#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 *);
int cosh(double);
double sinh(double);
double sqrt(double);
double ff_bond_hyper(int m, int n, double *cor, int *pairs, double *lengths,
                     double scale, double amp, double *unitcell,
                     double *unitcell_reciproke, int *unitcell_active,
                     double *gradient) {
  int b, i, j;
  double result, d, tmp;
  double delta[3];
  result = 0.0;
  for (b = 0; b < m; b++) {
    i = pairs[2 * b];
    j = pairs[2 * b + 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);
    tmp = d - lengths[b];
    result += amp * (cosh(scale * tmp) - 1);
    if (gradient != NULL) {
      tmp = amp * scale * sinh(scale * tmp) / d;
      add_grad(i, j, tmp, delta, gradient);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<ff_bond_hyper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    133a <ff_bond_hyper+0x1ea>
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x3c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
imul   $0x3,-0x40(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
imul   $0x3,-0x44(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x80(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    0x10(%rbp),%r8
mov    0x18(%rbp),%r9
call   1040 <calc_delta@plt>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1060 <cosh@plt>
movsd  -0x88(%rbp),%xmm0
ff
sub    $0x1,%eax
cvtsi2sd %eax,%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cmpq   $0x0,0x20(%rbp)
je     1327 <ff_bond_hyper+0x1d7>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x28(%rbp),%xmm0
mulsd  -0x60(%rbp),%xmm0
call   1030 <sinh@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x44(%rbp),%esi
movsd  -0x60(%rbp),%xmm0
lea    -0x80(%rbp),%rdx
mov    0x20(%rbp),%rcx
call   1050 <add_grad@plt>
jmp    132c <ff_bond_hyper+0x1dc>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1196 <ff_bond_hyper+0x46>
movsd  -0x50(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ff_bond_hyper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,0x28(%rsp)
mov    %rcx,0x20(%rsp)
test   %edi,%edi
jle    12ca <ff_bond_hyper+0x17a>
mov    %rdx,%rbx
mov    0xb0(%rsp),%rax
movsd  %xmm0,0x10(%rsp)
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    %edi,%ecx
mov    %rcx,0x8(%rsp)
xor    %r15d,%r15d
xorpd  %xmm0,%xmm0
movsd  %xmm1,0x18(%rsp)
jmp    11df <ff_bond_hyper+0x8f>
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0x48(%rsp),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x1,%r15
cmp    %r15,0x8(%rsp)
je     12ce <ff_bond_hyper+0x17e>
movsd  %xmm0,0x48(%rsp)
mov    %rax,%r12
mov    0x20(%rsp),%rax
movslq (%rax,%r15,8),%r13
movslq 0x4(%rax,%r15,8),%rbp
lea    0x0(%r13,%r13,2),%rax
lea    (%rbx,%rax,8),%rdi
lea    0x0(%rbp,%rbp,2),%rax
lea    (%rbx,%rax,8),%rsi
lea    0x50(%rsp),%rdx
mov    0x30(%rsp),%rcx
mov    0xa0(%rsp),%r8
mov    0xa8(%rsp),%r9
call   1040 <calc_delta@plt>
movsd  0x50(%rsp),%xmm0
movsd  0x58(%rsp),%xmm1
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0x60(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd 0xdab(%rip),%xmm0
jb     1260 <ff_bond_hyper+0x110>
sqrtsd %xmm0,%xmm0
jmp    1265 <ff_bond_hyper+0x115>
nopl   (%rax)
call   1070 <sqrt@plt>
movsd  %xmm0,0x40(%rsp)
mov    0x28(%rsp),%rax
subsd  (%rax,%r15,8),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
call   1060 <cosh@plt>
mov    %eax,%r14d
add    $0xffffffff,%r14d
mov    %r12,%rax
test   %r12,%r12
je     11b0 <ff_bond_hyper+0x60>
movsd  0x38(%rsp),%xmm0
call   1030 <sinh@plt>
mulsd  (%rsp),%xmm0
divsd  0x40(%rsp),%xmm0
mov    %r13d,%edi
mov    %ebp,%esi
lea    0x50(%rsp),%rdx
mov    %r12,%rcx
call   1050 <add_grad@plt>
mov    %r12,%rax
jmp    11b0 <ff_bond_hyper+0x60>
xorpd  %xmm0,%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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