#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 */
double exp(double);
int int_distance2(int *, int *);
void intrapot_torsion_well(double(*boltz_ptr), double(*energy_ptr),
                           int(*interaction_hist_ptr),
                           double(*highest_factor_ptr), double(*well_ptr),
                           double(*tor_ptr), double(nT_ptr),
                           const unsigned int ntorangles, int(**poly_ptr),
                           const unsigned int numberofbeads) {
  int interaction_counter = 0;
  int dist2;
  for (int dim1 = 0; dim1 < (numberofbeads - 8); dim1++) {
    for (int dim2 = dim1 + 8; dim2 < (numberofbeads); dim2++) {
      dist2 = int_distance2(poly_ptr[dim1], poly_ptr[dim2]);
      if (dist2 < 23) {
        interaction_counter += 1;
      }
    }
  }
  interaction_hist_ptr[interaction_counter]++;
  double energy;
  energy = (((double)ntorangles - nT_ptr) * tor_ptr[0]) -
           (double)interaction_counter * well_ptr[0];
  energy_ptr[0] = energy;
  boltz_ptr[0] = exp(-energy);
  if (boltz_ptr[0] > highest_factor_ptr[0]) {
    highest_factor_ptr[0] = boltz_ptr[0];
  }
}


x86 assembly (clang, -O0):
<intrapot_torsion_well>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    0x20(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
jae    11dc <intrapot_torsion_well+0xbc>
mov    -0x44(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    0x20(%rbp),%eax
jae    11c9 <intrapot_torsion_well+0xa9>
mov    0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x18(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <int_distance2@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x17,-0x40(%rbp)
jge    11b6 <intrapot_torsion_well+0x96>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11bb <intrapot_torsion_well+0x9b>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1177 <intrapot_torsion_well+0x57>
jmp    11ce <intrapot_torsion_well+0xae>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    115d <intrapot_torsion_well+0x3d>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    0x10(%rbp),%eax
cvtsi2sd %rax,%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm2
cvtsi2sdl -0x3c(%rbp),%xmm1
mov    -0x28(%rbp),%rax
mulsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <exp@plt>
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
ucomisd (%rax),%xmm0
jbe    128f <intrapot_torsion_well+0x16f>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intrapot_torsion_well>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %r9,0x20(%rsp)
mov    %r8,0x10(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdx,(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,0x28(%rsp)
mov    0x90(%rsp),%ecx
mov    %ecx,%eax
add    $0xfffffff8,%eax
je     11d2 <intrapot_torsion_well+0xb2>
mov    0x88(%rsp),%r12
mov    %ecx,%r15d
mov    %eax,%eax
mov    %rax,0x38(%rsp)
xor    %r13d,%r13d
mov    %r15,0x40(%rsp)
mov    %r12,%r14
xor    %ebx,%ebx
jmp    1193 <intrapot_torsion_well+0x73>
add    $0x1,%r13
add    $0x8,%r14
add    $0xffffffffffffffff,%r15
cmp    0x38(%rsp),%r13
je     11d4 <intrapot_torsion_well+0xb4>
lea    0x8(%r13),%rax
cmp    0x40(%rsp),%rax
jae    1180 <intrapot_torsion_well+0x60>
mov    $0x8,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%r13,8),%rdi
mov    (%r14,%rbp,8),%rsi
call   1030 <int_distance2@plt>
xor    %ecx,%ecx
cmp    $0x17,%eax
setl   %cl
add    %ecx,%ebx
add    $0x1,%rbp
cmp    %ebp,%r15d
jne    11b0 <intrapot_torsion_well+0x90>
jmp    1180 <intrapot_torsion_well+0x60>
xor    %ebx,%ebx
movslq %ebx,%rax
mov    (%rsp),%rcx
addl   $0x1,(%rcx,%rax,4)
mov    0x80(%rsp),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
subsd  0x8(%rsp),%xmm0
cvtsi2sd %eax,%xmm1
mov    0x10(%rsp),%rax
mulsd  (%rax),%xmm1
mov    0x20(%rsp),%rax
mulsd  (%rax),%xmm0
subsd  %xmm1,%xmm0
mov    0x18(%rsp),%rax
movsd  %xmm0,(%rax)
xorpd  0xde1(%rip),%xmm0
call   1040 <exp@plt>
mov    0x28(%rsp),%rax
movsd  %xmm0,(%rax)
mov    0x30(%rsp),%rax
ucomisd (%rax),%xmm0
jbe    123c <intrapot_torsion_well+0x11c>
movsd  %xmm0,(%rax)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @intrapot_torsion_well(double* %0, double* %1, i32* %2, double* %3, double* %4, double* %5, double %6, i32 %7, i32** %8, i32 %9) {
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32*
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca double
%18 = alloca i32
%19 = alloca i32**
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca double
store double* %0, double** %11
store double* %1, double** %12
store i32* %2, i32** %13
store double* %3, double** %14
store double* %4, double** %15
store double* %5, double** %16
store double %6, double* %17
store i32 %7, i32* %18
store i32** %8, i32*** %19
store i32 %9, i32* %20
store i32 0, i32* %21
store i32 0, i32* %23
br label %26
26: ; preds = %60, %10
%27 = load i32, i32* %23
%28 = load i32, i32* %20
%29 = sub i32 %28, 8
%30 = icmp ult i32 %27, %29
br i1 %30, label %31, label %63
31: ; preds = %26
%32 = load i32, i32* %23
%33 = add nsw i32 %32, 8
store i32 %33, i32* %24
br label %34
34: ; preds = %56, %31
%35 = load i32, i32* %24
%36 = load i32, i32* %20
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %59
38: ; preds = %34
%39 = load i32**, i32*** %19
%40 = load i32, i32* %23
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32*, i32** %39, i64 %41
%43 = load i32*, i32** %42
%44 = load i32**, i32*** %19
%45 = load i32, i32* %24
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32*, i32** %44, i64 %46
%48 = load i32*, i32** %47
%49 = call i32 @int_distance2(i32* %43, i32* %48)
store i32 %49, i32* %22
%50 = load i32, i32* %22
%51 = icmp slt i32 %50, 23
br i1 %51, label %52, label %55
52: ; preds = %38
%53 = load i32, i32* %21
%54 = add nsw i32 %53, 1
store i32 %54, i32* %21
br label %55
55: ; preds = %52, %38
br label %56
56: ; preds = %55
%57 = load i32, i32* %24
%58 = add nsw i32 %57, 1
store i32 %58, i32* %24
br label %34
59: ; preds = %34
br label %60
60: ; preds = %59
%61 = load i32, i32* %23
%62 = add nsw i32 %61, 1
store i32 %62, i32* %23
br label %26
63: ; preds = %26
%64 = load i32*, i32** %13
%65 = load i32, i32* %21
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = add nsw i32 %68, 1
store i32 %69, i32* %67
%70 = load i32, i32* %18
%71 = uitofp i32 %70 to double
%72 = load double, double* %17
%73 = fsub double %71, %72
%74 = load double*, double** %16
%75 = getelementptr inbounds double, double* %74, i64 0
%76 = load double, double* %75
%77 = load i32, i32* %21
%78 = sitofp i32 %77 to double
%79 = load double*, double** %15
%80 = getelementptr inbounds double, double* %79, i64 0
%81 = load double, double* %80
%82 = fmul double %78, %81
%83 = fneg double %82
%84 = call double @llvm.fmuladd.f64(double %73, double %76, double %83)
store double %84, double* %25
%85 = load double, double* %25
%86 = load double*, double** %12
%87 = getelementptr inbounds double, double* %86, i64 0
store double %85, double* %87
%88 = load double, double* %25
%89 = fneg double %88
%90 = call double @exp(double %89)
%91 = load double*, double** %11
%92 = getelementptr inbounds double, double* %91, i64 0
store double %90, double* %92
%93 = load double*, double** %11
%94 = getelementptr inbounds double, double* %93, i64 0
%95 = load double, double* %94
%96 = load double*, double** %14
%97 = getelementptr inbounds double, double* %96, i64 0
%98 = load double, double* %97
%99 = fcmp ogt double %95, %98
br i1 %99, label %100, label %106
100: ; preds = %63
%101 = load double*, double** %11
%102 = getelementptr inbounds double, double* %101, i64 0
%103 = load double, double* %102
%104 = load double*, double** %14
%105 = getelementptr inbounds double, double* %104, i64 0
store double %103, double* %105
br label %106
106: ; preds = %100, %63
ret void
}

LLVM IR (-O2):
define void @intrapot_torsion_well(double* nocapture writeonly %0, double* nocapture writeonly %1, i32* nocapture %2, double* nocapture %3, double* nocapture %4, double* nocapture %5, double %6, i32 %7, i32** nocapture %8, i32 %9) {
%11 = add i32 %9, -8
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = zext i32 %9 to i64
%15 = zext i32 %11 to i64
br label %34
16: ; preds = %42, %10
%17 = phi i32 [ 0, %10 ], [ %43, %42 ]
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %2, i64 %18
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
%22 = uitofp i32 %7 to double
%23 = fsub double %22, %6
%24 = load double, double* %5
%25 = sitofp i32 %17 to double
%26 = load double, double* %4
%27 = fneg double %26
%28 = fmul double %25, %27
%29 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %28)
store double %29, double* %1
%30 = fneg double %29
%31 = tail call double @exp(double %30)
store double %31, double* %0
%32 = load double, double* %3
%33 = fcmp ogt double %31, %32
br i1 %33, label %60, label %61
34: ; preds = %13, %42
%35 = phi i64 [ 0, %13 ], [ %44, %42 ]
%36 = phi i64 [ 8, %13 ], [ %45, %42 ]
%37 = phi i32 [ 0, %13 ], [ %43, %42 ]
%38 = add nuw nsw i64 %35, 8
%39 = icmp ult i64 %38, %14
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = getelementptr inbounds i32*, i32** %8, i64 %35
br label %47
42: ; preds = %47, %34
%43 = phi i32 [ %37, %34 ], [ %56, %47 ]
%44 = add nuw nsw i64 %35, 1
%45 = add nuw nsw i64 %36, 1
%46 = icmp eq i64 %44, %15
br i1 %46, label %16, label %34
47: ; preds = %40, %47
%48 = phi i64 [ %36, %40 ], [ %57, %47 ]
%49 = phi i32 [ %37, %40 ], [ %56, %47 ]
%50 = load i32*, i32** %41
%51 = getelementptr inbounds i32*, i32** %8, i64 %48
%52 = load i32*, i32** %51
%53 = tail call i32 @int_distance2(i32* %50, i32* %52)
%54 = icmp slt i32 %53, 23
%55 = zext i1 %54 to i32
%56 = add nsw i32 %49, %55
%57 = add nuw nsw i64 %48, 1
%58 = trunc i64 %57 to i32
%59 = icmp eq i32 %58, %9
br i1 %59, label %42, label %47
60: ; preds = %16
store double %31, double* %3
br label %61
61: ; preds = %60, %16
ret void
}