#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 potential(double);
void eval_potential(int n, double dx, double x0, double *x_buff,
                    double *V_buff) {
  double x = x0;
  for (int i = 0; i < n; i++) {
    x_buff[i] = x;
    V_buff[i] = potential(x);
    x += dx;
  }
}


x86 assembly (clang, -O0):
<eval_potential>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1190 <eval_potential+0x80>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x30(%rbp),%xmm0
call   1030 <potential@plt>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x10(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113e <eval_potential+0x2e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_potential>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    1163 <eval_potential+0x53>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
xor    %ebx,%ebx
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm1,(%r15,%rbx,8)
movaps %xmm1,%xmm0
call   1030 <potential@plt>
movsd  0x10(%rsp),%xmm1
movsd  %xmm0,(%r14,%rbx,8)
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <eval_potential+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @eval_potential(i32 %0, double %1, double %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca double*
%11 = alloca double
%12 = alloca i32
store i32 %0, i32* %6
store double %1, double* %7
store double %2, double* %8
store double* %3, double** %9
store double* %4, double** %10
%13 = load double, double* %8
store double %13, double* %11
store i32 0, i32* %12
br label %14
14: ; preds = %33, %5
%15 = load i32, i32* %12
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load double, double* %11
%20 = load double*, double** %9
%21 = load i32, i32* %12
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
store double %19, double* %23
%24 = load double, double* %11
%25 = call double @potential(double %24)
%26 = load double*, double** %10
%27 = load i32, i32* %12
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
%30 = load double, double* %7
%31 = load double, double* %11
%32 = fadd double %31, %30
store double %32, double* %11
br label %33
33: ; preds = %18
%34 = load i32, i32* %12
%35 = add nsw i32 %34, 1
store i32 %35, i32* %12
br label %14
36: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @eval_potential(i32 %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %10
9: ; preds = %10, %5
ret void
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %17, %10 ]
%12 = phi double [ %2, %7 ], [ %16, %10 ]
%13 = getelementptr inbounds double, double* %3, i64 %11
store double %12, double* %13
%14 = tail call double @potential(double %12)
%15 = getelementptr inbounds double, double* %4, i64 %11
store double %14, double* %15
%16 = fadd double %12, %1
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %8
br i1 %18, label %9, label %10
}