#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_scan(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;
  int bin;
  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;
  for (int dim1 = 0; dim1 < 10; dim1++) {
    for (int dim2 = 0; dim2 < 10; dim2++) {
      energy = (((double)ntorangles - nT_ptr) * tor_ptr[dim2]) -
               (double)interaction_counter * well_ptr[dim1];
      bin = dim1 * 10 + dim2;
      energy_ptr[bin] = energy;
      boltz_ptr[bin] = exp(-energy);
      if (boltz_ptr[bin] > highest_factor_ptr[bin]) {
        highest_factor_ptr[bin] = boltz_ptr[bin];
      }
    }
  }
}


x86 assembly (clang, -O0):
<intrapot_torsion_well_scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x20(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
jae    11dc <intrapot_torsion_well_scan+0xbc>
mov    -0x48(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    0x20(%rbp),%eax
jae    11c9 <intrapot_torsion_well_scan+0xa9>
mov    0x18(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x18(%rbp),%rax
movslq -0x4c(%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_scan+0x96>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11bb <intrapot_torsion_well_scan+0x9b>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1177 <intrapot_torsion_well_scan+0x57>
jmp    11ce <intrapot_torsion_well_scan+0xae>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    115d <intrapot_torsion_well_scan+0x3d>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
movl   $0x0,-0x5c(%rbp)
cmpl   $0xa,-0x5c(%rbp)
jge    1309 <intrapot_torsion_well_scan+0x1e9>
movl   $0x0,-0x60(%rbp)
cmpl   $0xa,-0x60(%rbp)
jge    12f6 <intrapot_torsion_well_scan+0x1d6>
mov    0x10(%rbp),%eax
cvtsi2sd %rax,%xmm0
subsd  -0x38(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
cvtsi2sdl -0x3c(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x5c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
imul   $0xa,-0x5c(%rbp),%eax
add    -0x60(%rbp),%eax
mov    %eax,-0x44(%rbp)
movsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x58(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <exp@plt>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jbe    12e3 <intrapot_torsion_well_scan+0x1c3>
mov    -0x8(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    12e8 <intrapot_torsion_well_scan+0x1c8>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1205 <intrapot_torsion_well_scan+0xe5>
jmp    12fb <intrapot_torsion_well_scan+0x1db>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11f4 <intrapot_torsion_well_scan+0xd4>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intrapot_torsion_well_scan>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movsd  %xmm0,0x38(%rsp)
mov    %r9,0x28(%rsp)
mov    %r8,0x40(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rdx,0x30(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,0x18(%rsp)
mov    0x90(%rsp),%ecx
mov    %ecx,%eax
add    $0xfffffff8,%eax
je     11d2 <intrapot_torsion_well_scan+0xb2>
mov    0x88(%rsp),%r14
mov    %ecx,%r13d
mov    %eax,%eax
mov    %rax,(%rsp)
xor    %r12d,%r12d
mov    %r13,0x8(%rsp)
mov    %r14,%r15
xor    %ebp,%ebp
jmp    1192 <intrapot_torsion_well_scan+0x72>
add    $0x1,%r12
add    $0x8,%r15
add    $0xffffffffffffffff,%r13
cmp    (%rsp),%r12
je     11d4 <intrapot_torsion_well_scan+0xb4>
lea    0x8(%r12),%rax
cmp    0x8(%rsp),%rax
jae    1180 <intrapot_torsion_well_scan+0x60>
mov    $0x8,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%r12,8),%rdi
mov    (%r15,%rbx,8),%rsi
call   1030 <int_distance2@plt>
xor    %ecx,%ecx
cmp    $0x17,%eax
setl   %cl
add    %ecx,%ebp
add    $0x1,%rbx
cmp    %ebx,%r13d
jne    11b0 <intrapot_torsion_well_scan+0x90>
jmp    1180 <intrapot_torsion_well_scan+0x60>
xor    %ebp,%ebp
movslq %ebp,%rax
mov    0x30(%rsp),%rcx
addl   $0x1,(%rcx,%rax,4)
mov    0x80(%rsp),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
subsd  0x38(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%rsp)
xor    %r13d,%r13d
mov    0x28(%rsp),%r12
mov    0x20(%rsp),%r15
mov    0x18(%rsp),%rbp
mov    0x10(%rsp),%rbx
jmp    1236 <intrapot_torsion_well_scan+0x116>
add    $0x1,%r13
add    $0x50,%rbx
add    $0x50,%rbp
add    $0x50,%r15
cmp    $0xa,%r13
je     1294 <intrapot_torsion_well_scan+0x174>
xor    %r14d,%r14d
jmp    124a <intrapot_torsion_well_scan+0x12a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    $0xa,%r14
je     1220 <intrapot_torsion_well_scan+0x100>
mov    0x40(%rsp),%rax
movsd  (%rax,%r13,8),%xmm1
mulsd  (%rsp),%xmm1
movsd  (%r12,%r14,8),%xmm0
mulsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%r15,%r14,8)
xorpd  0xd88(%rip),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,0x0(%rbp,%r14,8)
ucomisd (%rbx,%r14,8),%xmm0
jbe    1240 <intrapot_torsion_well_scan+0x120>
movsd  %xmm0,(%rbx,%r14,8)
jmp    1240 <intrapot_torsion_well_scan+0x120>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @intrapot_torsion_well_scan(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 %25
16: ; preds = %33, %10
%17 = phi i32 [ 0, %10 ], [ %34, %33 ]
%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 = sitofp i32 %17 to double
br label %51
25: ; preds = %13, %33
%26 = phi i64 [ 0, %13 ], [ %35, %33 ]
%27 = phi i64 [ 8, %13 ], [ %36, %33 ]
%28 = phi i32 [ 0, %13 ], [ %34, %33 ]
%29 = add nuw nsw i64 %26, 8
%30 = icmp ult i64 %29, %14
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = getelementptr inbounds i32*, i32** %8, i64 %26
br label %38
33: ; preds = %38, %25
%34 = phi i32 [ %28, %25 ], [ %47, %38 ]
%35 = add nuw nsw i64 %26, 1
%36 = add nuw nsw i64 %27, 1
%37 = icmp eq i64 %35, %15
br i1 %37, label %16, label %25
38: ; preds = %31, %38
%39 = phi i64 [ %27, %31 ], [ %48, %38 ]
%40 = phi i32 [ %28, %31 ], [ %47, %38 ]
%41 = load i32*, i32** %32
%42 = getelementptr inbounds i32*, i32** %8, i64 %39
%43 = load i32*, i32** %42
%44 = tail call i32 @int_distance2(i32* %41, i32* %43)
%45 = icmp slt i32 %44, 23
%46 = zext i1 %45 to i32
%47 = add nsw i32 %40, %46
%48 = add nuw nsw i64 %39, 1
%49 = trunc i64 %48 to i32
%50 = icmp eq i32 %49, %9
br i1 %50, label %33, label %38
51: ; preds = %16, %56
%52 = phi i64 [ 0, %16 ], [ %57, %56 ]
%53 = getelementptr inbounds double, double* %4, i64 %52
%54 = mul nuw nsw i64 %52, 10
br label %59
55: ; preds = %56
ret void
56: ; preds = %76
%57 = add nuw nsw i64 %52, 1
%58 = icmp eq i64 %57, 10
br i1 %58, label %55, label %51
59: ; preds = %51, %76
%60 = phi i64 [ 0, %51 ], [ %77, %76 ]
%61 = getelementptr inbounds double, double* %5, i64 %60
%62 = load double, double* %61
%63 = load double, double* %53
%64 = fneg double %63
%65 = fmul double %24, %64
%66 = tail call double @llvm.fmuladd.f64(double %23, double %62, double %65)
%67 = add nuw nsw i64 %60, %54
%68 = getelementptr inbounds double, double* %1, i64 %67
store double %66, double* %68
%69 = fneg double %66
%70 = tail call double @exp(double %69)
%71 = getelementptr inbounds double, double* %0, i64 %67
store double %70, double* %71
%72 = getelementptr inbounds double, double* %3, i64 %67
%73 = load double, double* %72
%74 = fcmp ogt double %70, %73
br i1 %74, label %75, label %76
75: ; preds = %59
store double %70, double* %72
br label %76
76: ; preds = %59, %75
%77 = add nuw nsw i64 %60, 1
%78 = icmp eq i64 %77, 10
br i1 %78, label %56, label %59
}