#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 pow(double, int);
double Fluctuation(double Energy) {
  static double EnergyVector[1000] = {0};
  static int front = -1, rear = -1;
  static double Sum = 0.0, Sum2 = 0.0;
  int Denominator;
  Denominator = rear + 2;
  if (front == (rear + 1) % 1000) {
    Denominator = 1000;
    Sum -= EnergyVector[front];
    Sum2 -= pow(EnergyVector[front], 2);
    if (front == rear)
      front = rear = -1;
    else
      front = (front + 1) % 1000;
  }
  if (front == -1)
    front = rear = 0;
  else
    rear = (rear + 1) % 1000;
  EnergyVector[rear] = Energy;
  Sum += EnergyVector[rear];
  Sum2 += pow(EnergyVector[rear], 2);
  return (((double)Sum2 / Denominator) - pow((double)Sum / 1000, 2));
}


x86 assembly (clang, -O0):
<Fluctuation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    0x2f09(%rip),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    0x2ef9(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0x2ef4(%rip),%eax
add    $0x1,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%eax
cmp    %edx,%eax
jne    11f7 <Fluctuation+0xe7>
movl   $0x3e8,-0xc(%rbp)
movslq 0x2ecc(%rip),%rcx
lea    0x2edd(%rip),%rax
movsd  (%rax,%rcx,8),%xmm1
movsd  0x4e10(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x4e04(%rip)
movslq 0x2ea5(%rip),%rcx
lea    0x2eb6(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  0x4de4(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,0x4dd8(%rip)
mov    0x2e72(%rip),%eax
cmp    0x2e70(%rip),%eax
jne    11db <Fluctuation+0xcb>
movl   $0xffffffff,0x2e60(%rip)
ff ff ff
movl   $0xffffffff,0x2e52(%rip)
ff ff ff
jmp    11f2 <Fluctuation+0xe2>
mov    0x2e47(%rip),%eax
add    $0x1,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,0x2e36(%rip)
jmp    11f7 <Fluctuation+0xe7>
cmpl   $0xffffffff,0x2e2a(%rip)
jne    121d <Fluctuation+0x10d>
movl   $0x0,0x2e1e(%rip)
movl   $0x0,0x2e10(%rip)
jmp    1234 <Fluctuation+0x124>
mov    0x2e09(%rip),%eax
add    $0x1,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,0x2df8(%rip)
movsd  -0x8(%rbp),%xmm0
movslq 0x2dec(%rip),%rcx
lea    0x2df9(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
movslq 0x2dd9(%rip),%rcx
lea    0x2de6(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
addsd  0x4d19(%rip),%xmm0
movsd  %xmm0,0x4d11(%rip)
movslq 0x2db6(%rip),%rcx
lea    0x2dc3(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x4cf4(%rip),%xmm0
movsd  %xmm0,0x4cec(%rip)
movsd  0x4ce4(%rip),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0x4cc6(%rip),%xmm0
movsd  0xd3e(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Fluctuation>:
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,%xmm1
mov    0x2f0d(%rip),%eax
mov    0x2f03(%rip),%ecx
lea    0x1(%rax),%edx
movslq %edx,%rdx
imul   $0x10624dd3,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rdx
add    %esi,%edx
imul   $0x3e8,%edx,%edx
neg    %edx
add    %eax,%edx
add    $0x1,%edx
cmp    %edx,%ecx
jne    1200 <Fluctuation+0xf0>
movslq %ecx,%rax
lea    0x2ee2(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm1,0x8(%rsp)
movsd  0x4e0f(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x4e03(%rip)
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x4df9(%rip),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x4ded(%rip)
movsd  0x8(%rsp),%xmm1
mov    0x2e81(%rip),%ecx
mov    0x2e7f(%rip),%eax
mov    $0x3e8,%ebx
cmp    %eax,%ecx
je     11e8 <Fluctuation+0xd8>
add    $0x1,%ecx
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rdx
add    %esi,%edx
imul   $0x3e8,%edx,%edx
sub    %edx,%ecx
mov    %ecx,0x2e4a(%rip)
mov    $0x3e8,%ebx
cmp    $0xffffffff,%ecx
jne    1208 <Fluctuation+0xf8>
movl   $0x0,0x2e3a(%rip)
movl   $0x0,0x2e2c(%rip)
xor    %eax,%eax
jmp    1231 <Fluctuation+0x121>
lea    0x2(%rax),%ebx
cmp    $0xffffffff,%ecx
je     11e8 <Fluctuation+0xd8>
add    $0x1,%eax
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x2dfd(%rip)
cltq
lea    0x2e08(%rip),%rcx
movsd  %xmm1,(%rcx,%rax,8)
movsd  0x4d3b(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x4d2f(%rip)
movapd %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x4d21(%rip),%xmm0
movsd  %xmm0,0x4d19(%rip)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x4cf8(%rip),%xmm0
divsd  0xd70(%rip),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@Fluctuation.EnergyVector = internal global [1000 x double] zeroinitializer
@Fluctuation.front = internal global i32 -1
@Fluctuation.rear = internal global i32 -1
@Fluctuation.Sum = internal global double 0.000000e+00
@Fluctuation.Sum2 = internal global double 0.000000e+00
define double @Fluctuation(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
%4 = load i32, i32* @Fluctuation.rear
%5 = add nsw i32 %4, 2
store i32 %5, i32* %3
%6 = load i32, i32* @Fluctuation.front
%7 = load i32, i32* @Fluctuation.rear
%8 = add nsw i32 %7, 1
%9 = srem i32 %8, 1000
%10 = icmp eq i32 %6, %9
br i1 %10, label %11, label %34
11: ; preds = %1
store i32 1000, i32* %3
%12 = load i32, i32* @Fluctuation.front
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1000 x double], [1000 x double]* @Fluctuation.EnergyVector, i64 0, i64 %13
%15 = load double, double* %14
%16 = load double, double* @Fluctuation.Sum
%17 = fsub double %16, %15
store double %17, double* @Fluctuation.Sum
%18 = load i32, i32* @Fluctuation.front
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1000 x double], [1000 x double]* @Fluctuation.EnergyVector, i64 0, i64 %19
%21 = load double, double* %20
%22 = call double @pow(double %21, i32 2)
%23 = load double, double* @Fluctuation.Sum2
%24 = fsub double %23, %22
store double %24, double* @Fluctuation.Sum2
%25 = load i32, i32* @Fluctuation.front
%26 = load i32, i32* @Fluctuation.rear
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %11
store i32 -1, i32* @Fluctuation.rear
store i32 -1, i32* @Fluctuation.front
br label %33
29: ; preds = %11
%30 = load i32, i32* @Fluctuation.front
%31 = add nsw i32 %30, 1
%32 = srem i32 %31, 1000
store i32 %32, i32* @Fluctuation.front
br label %33
33: ; preds = %29, %28
br label %34
34: ; preds = %33, %1
%35 = load i32, i32* @Fluctuation.front
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 0, i32* @Fluctuation.rear
store i32 0, i32* @Fluctuation.front
br label %42
38: ; preds = %34
%39 = load i32, i32* @Fluctuation.rear
%40 = add nsw i32 %39, 1
%41 = srem i32 %40, 1000
store i32 %41, i32* @Fluctuation.rear
br label %42
42: ; preds = %38, %37
%43 = load double, double* %2
%44 = load i32, i32* @Fluctuation.rear
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1000 x double], [1000 x double]* @Fluctuation.EnergyVector, i64 0, i64 %45
store double %43, double* %46
%47 = load i32, i32* @Fluctuation.rear
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1000 x double], [1000 x double]* @Fluctuation.EnergyVector, i64 0, i64 %48
%50 = load double, double* %49
%51 = load double, double* @Fluctuation.Sum
%52 = fadd double %51, %50
store double %52, double* @Fluctuation.Sum
%53 = load i32, i32* @Fluctuation.rear
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1000 x double], [1000 x double]* @Fluctuation.EnergyVector, i64 0, i64 %54
%56 = load double, double* %55
%57 = call double @pow(double %56, i32 2)
%58 = load double, double* @Fluctuation.Sum2
%59 = fadd double %58, %57
store double %59, double* @Fluctuation.Sum2
%60 = load double, double* @Fluctuation.Sum2
%61 = load i32, i32* %3
%62 = sitofp i32 %61 to double
%63 = fdiv double %60, %62
%64 = load double, double* @Fluctuation.Sum
%65 = fdiv double %64, 1.000000e+03
%66 = call double @pow(double %65, i32 2)
%67 = fsub double %63, %66
ret double %67
}

LLVM IR (-O2):
@Fluctuation.EnergyVector = internal unnamed_addr global [1000 x double] zeroinitializer
@Fluctuation.front = internal unnamed_addr global i32 -1
@Fluctuation.rear = internal unnamed_addr global i32 -1
@Fluctuation.Sum = internal unnamed_addr global double 0.000000e+00
@Fluctuation.Sum2 = internal unnamed_addr global double 0.000000e+00
define double @Fluctuation(double %0) {
%2 = load i32, i32* @Fluctuation.rear
%3 = add nsw i32 %2, 2
%4 = load i32, i32* @Fluctuation.front
%5 = add nsw i32 %2, 1
%6 = srem i32 %5, 1000
%7 = icmp eq i32 %4, %6
br i1 %7, label %8, label %23
8: ; preds = %1
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds [1000 x double], [1000 x double]* @Fluctuation.EnergyVector, i64 0, i64 %9
%11 = load double, double* %10
%12 = load double, double* @Fluctuation.Sum
%13 = fsub double %12, %11
store double %13, double* @Fluctuation.Sum
%14 = tail call double @pow(double %11, i32 2)
%15 = load double, double* @Fluctuation.Sum2
%16 = fsub double %15, %14
store double %16, double* @Fluctuation.Sum2
%17 = load i32, i32* @Fluctuation.front
%18 = load i32, i32* @Fluctuation.rear
%19 = icmp eq i32 %17, %18
br i1 %19, label %28, label %20
20: ; preds = %8
%21 = add nsw i32 %17, 1
%22 = srem i32 %21, 1000
store i32 %22, i32* @Fluctuation.front
br label %23
23: ; preds = %20, %1
%24 = phi i32 [ %18, %20 ], [ %2, %1 ]
%25 = phi i32 [ %22, %20 ], [ %4, %1 ]
%26 = phi i32 [ 1000, %20 ], [ %3, %1 ]
%27 = icmp eq i32 %25, -1
br i1 %27, label %28, label %30
28: ; preds = %8, %23
%29 = phi i32 [ %26, %23 ], [ 1000, %8 ]
store i32 0, i32* @Fluctuation.rear
store i32 0, i32* @Fluctuation.front
br label %34
30: ; preds = %23
%31 = add nsw i32 %24, 1
%32 = srem i32 %31, 1000
store i32 %32, i32* @Fluctuation.rear
%33 = sext i32 %32 to i64
br label %34
34: ; preds = %30, %28
%35 = phi i64 [ %33, %30 ], [ 0, %28 ]
%36 = phi i32 [ %26, %30 ], [ %29, %28 ]
%37 = getelementptr inbounds [1000 x double], [1000 x double]* @Fluctuation.EnergyVector, i64 0, i64 %35
store double %0, double* %37
%38 = load double, double* @Fluctuation.Sum
%39 = fadd double %38, %0
store double %39, double* @Fluctuation.Sum
%40 = tail call double @pow(double %0, i32 2)
%41 = load double, double* @Fluctuation.Sum2
%42 = fadd double %40, %41
store double %42, double* @Fluctuation.Sum2
%43 = sitofp i32 %36 to double
%44 = fdiv double %42, %43
%45 = load double, double* @Fluctuation.Sum
%46 = fdiv double %45, 1.000000e+03
%47 = tail call double @pow(double %46, i32 2)
%48 = fsub double %44, %47
ret double %48
}