double wave_function(double **r, double correlation5, double l, int dimension,
                     int number_particles) {
  int i, j;
  double wf, dist, lh, argument, *r_distance;
  r_distance = (double *)malloc((dimension) * sizeof(double));
  lh = l / 2;
  argument = 0;
  for (i = 0; i < number_particles; i++) {
    for (j = 0; j < number_particles; j++) {
      if (i != j) {
        dist = distance(r, r_distance, l, i, j, dimension);
        if (dist > lh) {
          dist = lh;
        }
        argument += 1. / pow(dist, 5.);
      }
    }
  }
  argument *= -correlation5;
  wf = exp(argument);
  return wf;
}


x86 assembly (clang, -O0):
<wave_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
movslq -0x1c(%rbp),%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe86(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    124f <wave_function+0x10f>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    123c <wave_function+0xfc>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     1229 <wave_function+0xe9>
mov    -0x8(%rbp),%rdi
mov    -0x50(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    $0x1,%al
call   1060 <distance@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    11fe <wave_function+0xbe>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe05(%rip),%xmm1
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xded(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    122e <wave_function+0xee>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a5 <wave_function+0x65>
jmp    1241 <wave_function+0x101>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1192 <wave_function+0x52>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wave_function>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r13d
mov    %esi,%r14d
movsd  %xmm1,0x10(%rsp)
movapd %xmm0,0x20(%rsp)
mov    %rdi,%r15
movslq %esi,%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
test   %r13d,%r13d
jle    121e <wave_function+0xde>
mov    %rax,%r12
movsd  0xe7d(%rip),%xmm0
movsd  0x10(%rsp),%xmm2
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
jmp    11a8 <wave_function+0x68>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r13d,%ebp
je     1222 <wave_function+0xe2>
xor    %ebx,%ebx
jmp    11b8 <wave_function+0x78>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %ebx,%r13d
je     11a0 <wave_function+0x60>
cmp    %ebx,%ebp
je     11b0 <wave_function+0x70>
mov    %r15,%rdi
mov    %r12,%rsi
movsd  0x10(%rsp),%xmm0
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
mov    $0x1,%al
movsd  %xmm1,0x8(%rsp)
call   1060 <distance@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x18(%rsp),%xmm0
minsd  %xmm1,%xmm0
movsd  0xe13(%rip),%xmm1
call   1050 <pow@plt>
movsd  0xe0e(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
jmp    11b0 <wave_function+0x70>
xorpd  %xmm1,%xmm1
movapd 0x20(%rsp),%xmm0
xorpd  0xdf0(%rip),%xmm0
mulsd  %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <exp@plt>

LLVM IR (-O0):
define double @wave_function(double** %0, double %1, double %2, i32 %3, i32 %4) {
%6 = alloca double**
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double*
store double** %0, double*** %6
store double %1, double* %7
store double %2, double* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = call i8* @malloc(i64 %20)
%22 = bitcast i8* %21 to double*
store double* %22, double** %17
%23 = load double, double* %8
%24 = fdiv double %23, 2.000000e+00
store double %24, double* %15
store double 0.000000e+00, double* %16
store i32 0, i32* %11
br label %25
25: ; preds = %63, %5
%26 = load i32, i32* %11
%27 = load i32, i32* %10
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %66
29: ; preds = %25
store i32 0, i32* %12
br label %30
30: ; preds = %59, %29
%31 = load i32, i32* %12
%32 = load i32, i32* %10
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %62
34: ; preds = %30
%35 = load i32, i32* %11
%36 = load i32, i32* %12
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %58
38: ; preds = %34
%39 = load double**, double*** %6
%40 = load double*, double** %17
%41 = load double, double* %8
%42 = load i32, i32* %11
%43 = load i32, i32* %12
%44 = load i32, i32* %9
%45 = call i32 (double**, double*, double, i32, i32, i32, ...) bitcast (i32 (...)* @distance to i32 (double**, double*, double, i32, i32, i32, ...)*)(double** %39, double* %40, double %41, i32 %42, i32 %43, i32 %44)
%46 = sitofp i32 %45 to double
store double %46, double* %14
%47 = load double, double* %14
%48 = load double, double* %15
%49 = fcmp ogt double %47, %48
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = load double, double* %15
store double %51, double* %14
br label %52
52: ; preds = %50, %38
%53 = load double, double* %14
%54 = call double @pow(double %53, double 5.000000e+00)
%55 = fdiv double 1.000000e+00, %54
%56 = load double, double* %16
%57 = fadd double %56, %55
store double %57, double* %16
br label %58
58: ; preds = %52, %34
br label %59
59: ; preds = %58
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
store i32 %61, i32* %12
br label %30
62: ; preds = %30
br label %63
63: ; preds = %62
%64 = load i32, i32* %11
%65 = add nsw i32 %64, 1
store i32 %65, i32* %11
br label %25
66: ; preds = %25
%67 = load double, double* %7
%68 = fneg double %67
%69 = load double, double* %16
%70 = fmul double %69, %68
store double %70, double* %16
%71 = load double, double* %16
%72 = call double @exp(double %71)
store double %72, double* %13
%73 = load double, double* %13
ret double %73
}

LLVM IR (-O2):
define double @wave_function(double** %0, double %1, double %2, i32 %3, i32 %4) {
%6 = sext i32 %3 to i64
%7 = shl nsw i64 %6, 3
%8 = tail call i8* @malloc(i64 %7)
%9 = bitcast i8* %8 to double*
%10 = fmul double %2, 5.000000e-01
%11 = icmp sgt i32 %4, 0
br i1 %11, label %12, label %34
12: ; preds = %5, %31
%13 = phi i32 [ %32, %31 ], [ 0, %5 ]
%14 = phi double [ %28, %31 ], [ 0.000000e+00, %5 ]
br label %15
15: ; preds = %12, %27
%16 = phi double [ %28, %27 ], [ %14, %12 ]
%17 = phi i32 [ %29, %27 ], [ 0, %12 ]
%18 = icmp eq i32 %13, %17
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = tail call i32 (double**, double*, double, i32, i32, i32, ...) bitcast (i32 (...)* @distance to i32 (double**, double*, double, i32, i32, i32, ...)*)(double** %0, double* %9, double %2, i32 %13, i32 %17, i32 %3)
%21 = sitofp i32 %20 to double
%22 = fcmp olt double %10, %21
%23 = select i1 %22, double %10, double %21
%24 = tail call double @pow(double %23, double 5.000000e+00)
%25 = fdiv double 1.000000e+00, %24
%26 = fadd double %16, %25
br label %27
27: ; preds = %15, %19
%28 = phi double [ %26, %19 ], [ %16, %15 ]
%29 = add nuw nsw i32 %17, 1
%30 = icmp eq i32 %29, %4
br i1 %30, label %31, label %15
31: ; preds = %27
%32 = add nuw nsw i32 %13, 1
%33 = icmp eq i32 %32, %4
br i1 %33, label %34, label %12
34: ; preds = %31, %5
%35 = phi double [ 0.000000e+00, %5 ], [ %28, %31 ]
%36 = fneg double %1
%37 = fmul double %35, %36
%38 = tail call double @exp(double %37)
ret double %38
}