#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double);
double sqrt(double);
int /*<<< orphan*/ stderr;
double eCenter(const short *ibuff, int len) {
  double v0, v1, v2;
  int n;
  v0 = v1 = v2 = 0;
  for (n = 0; n < len; n++) {
    double w = ibuff[n];
    w = w * w;
    v0 += w;
    v1 += n * w;
    v2 += (n * n) * w;
  }
  v1 /= v0;
  v2 /= v0;
  v2 -= v1 * v1;
  fprintf(stderr, "eCenter %.2f,  STD %.2f\n", v1, sqrt(v2));
  return v1;
}


x86 assembly (clang, -O0):
<eCenter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <eCenter+0xb9>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movswl (%rax,%rcx,2),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0x2c(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    114e <eCenter+0x2e>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
mov    -0x44(%rbp),%edi
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
lea    0xd9c(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eCenter>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm1,%xmm1
test   %esi,%esi
jle    118b <eCenter+0x6b>
mov    %esi,%eax
xorpd  %xmm4,%xmm4
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
nopl   0x0(%rax)
movapd %xmm4,%xmm3
movswl (%rdi,%rcx,2),%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm0,%xmm2
movd   %ecx,%xmm4
mov    %ecx,%edx
imul   %ecx,%edx
movd   %edx,%xmm5
punpckldq %xmm5,%xmm4
cvtdq2pd %xmm4,%xmm4
unpcklpd %xmm0,%xmm0
mulpd  %xmm4,%xmm0
movapd %xmm0,%xmm4
addpd  %xmm3,%xmm4
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1140 <eCenter+0x20>
addpd  %xmm3,%xmm0
jmp    1193 <eCenter+0x73>
xorpd  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
divsd  %xmm2,%xmm3
unpckhpd %xmm0,%xmm0
divsd  %xmm2,%xmm0
movapd %xmm3,%xmm2
mulsd  %xmm3,%xmm2
subsd  %xmm2,%xmm0
mov    0x2e2a(%rip),%rax
mov    (%rax),%ebx
ucomisd %xmm1,%xmm0
movapd %xmm3,(%rsp)
jb     11cc <eCenter+0xac>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    11da <eCenter+0xba>
call   1040 <sqrt@plt>
movapd (%rsp),%xmm3
movapd %xmm0,%xmm1
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
movapd %xmm3,%xmm0
call   1030 <fprintf@plt>
movaps (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"eCenter %.2f, STD %.2f\0A\00"
define double @eCenter(i16* %0, i32 %1) {
%3 = alloca i16*
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
store i16* %0, i16** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %5
store i32 0, i32* %8
br label %10
10: ; preds = %39, %2
%11 = load i32, i32* %8
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %42
14: ; preds = %10
%15 = load i16*, i16** %3
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i16, i16* %15, i64 %17
%19 = load i16, i16* %18
%20 = sitofp i16 %19 to double
store double %20, double* %9
%21 = load double, double* %9
%22 = load double, double* %9
%23 = fmul double %21, %22
store double %23, double* %9
%24 = load double, double* %9
%25 = load double, double* %5
%26 = fadd double %25, %24
store double %26, double* %5
%27 = load i32, i32* %8
%28 = sitofp i32 %27 to double
%29 = load double, double* %9
%30 = load double, double* %6
%31 = call double @llvm.fmuladd.f64(double %28, double %29, double %30)
store double %31, double* %6
%32 = load i32, i32* %8
%33 = load i32, i32* %8
%34 = mul nsw i32 %32, %33
%35 = sitofp i32 %34 to double
%36 = load double, double* %9
%37 = load double, double* %7
%38 = call double @llvm.fmuladd.f64(double %35, double %36, double %37)
store double %38, double* %7
br label %39
39: ; preds = %14
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %10
42: ; preds = %10
%43 = load double, double* %5
%44 = load double, double* %6
%45 = fdiv double %44, %43
store double %45, double* %6
%46 = load double, double* %5
%47 = load double, double* %7
%48 = fdiv double %47, %46
store double %48, double* %7
%49 = load double, double* %6
%50 = load double, double* %6
%51 = load double, double* %7
%52 = fneg double %49
%53 = call double @llvm.fmuladd.f64(double %52, double %50, double %51)
store double %53, double* %7
%54 = load i32, i32* @stderr
%55 = load double, double* %6
%56 = load double, double* %7
%57 = call double @sqrt(double %56)
%58 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %55, double %57)
%59 = load double, double* %6
ret double %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"eCenter %.2f, STD %.2f\0A\00"
define double @eCenter(i16* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %23, %6 ]
%8 = phi double [ 0.000000e+00, %4 ], [ %14, %6 ]
%9 = phi <2 x double> [ zeroinitializer, %4 ], [ %22, %6 ]
%10 = getelementptr inbounds i16, i16* %0, i64 %7
%11 = load i16, i16* %10
%12 = sitofp i16 %11 to double
%13 = fmul double %12, %12
%14 = fadd double %8, %13
%15 = trunc i64 %7 to i32
%16 = mul nsw i32 %15, %15
%17 = insertelement <2 x i32> poison, i32 %15, i64 0
%18 = insertelement <2 x i32> %17, i32 %16, i64 1
%19 = sitofp <2 x i32> %18 to <2 x double>
%20 = insertelement <2 x double> poison, double %13, i64 0
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%22 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %19, <2 x double> %21, <2 x double> %9)
%23 = add nuw nsw i64 %7, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %6
25: ; preds = %6
%26 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %19, <2 x double> %21, <2 x double> %9)
br label %27
27: ; preds = %25, %2
%28 = phi double [ 0.000000e+00, %2 ], [ %14, %25 ]
%29 = phi <2 x double> [ zeroinitializer, %2 ], [ %26, %25 ]
%30 = extractelement <2 x double> %29, i64 0
%31 = fdiv double %30, %28
%32 = extractelement <2 x double> %29, i64 1
%33 = fdiv double %32, %28
%34 = fneg double %31
%35 = tail call double @llvm.fmuladd.f64(double %34, double %31, double %33)
%36 = load i32, i32* @stderr
%37 = tail call double @sqrt(double %35)
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), double %31, double %37)
ret double %31
}