#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 */
long double _mean(long double *, unsigned int);
long double sqrt(long double);
void standard_deviation(long double *result, const long double x,
                        long double *acc) {
  static unsigned int i = 0;
  size_t j = 0;
  long double mean, sum = 0;
  acc[i++] = x;
  mean = _mean(acc, i);
  while (j < i) {
    long double val = acc[j++] - mean;
    sum += val * val;
  }
  *result = sqrt(sum / i);
}


x86 assembly (clang, -O0):
<standard_deviation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
fldt   0x10(%rbp)
mov    %rdi,-0x8(%rbp)
fstpt  -0x20(%rbp)
mov    %rsi,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
fldz
fstpt  -0x50(%rbp)
fldt   -0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2ee1(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2ed6(%rip)
shl    $0x4,%rcx
fstpt  (%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    0x2ec5(%rip),%esi
call   1030 <_mean@plt>
fstpt  -0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2eb3(%rip),%ecx
cmp    %rcx,%rax
jae    11c0 <standard_deviation+0xa0>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
shl    $0x4,%rcx
fldt   (%rax,%rcx,1)
fldt   -0x40(%rbp)
fsubrp %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
fldt   -0x50(%rbp)
fxch   %st(1)
fmul   %st,%st(0)
faddp  %st,%st(1)
fstpt  -0x50(%rbp)
jmp    1177 <standard_deviation+0x57>
fldt   -0x50(%rbp)
mov    0x2e6b(%rip),%eax
mov    %rax,-0x68(%rbp)
fildll -0x68(%rbp)
fdivrp %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <sqrt@plt>
mov    -0x8(%rbp),%rax
fstpt  (%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<standard_deviation>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
fldt   0x30(%rsp)
mov    0x2efd(%rip),%eax
lea    0x1(%rax),%esi
mov    %esi,0x2ef4(%rip)
shl    $0x4,%rax
fstpt  (%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <_mean@plt>
mov    0x2edf(%rip),%eax
fldz
fld    %st(0)
test   %rax,%rax
je     11f2 <standard_deviation+0xd2>
fstp   %st(0)
lea    -0x1(%rax),%rdx
mov    %eax,%ecx
and    $0x3,%ecx
fldz
cmp    $0x3,%rdx
jae    1179 <standard_deviation+0x59>
xor    %edx,%edx
jmp    11c0 <standard_deviation+0xa0>
fstp   %st(0)
mov    %eax,%esi
and    $0xfffffffc,%esi
lea    0x30(%rbx),%rdi
fldz
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
fldt   -0x30(%rdi)
fsub   %st(3),%st
fmul   %st,%st(0)
faddp  %st,%st(1)
fldt   -0x20(%rdi)
fsub   %st(3),%st
fmul   %st,%st(0)
faddp  %st,%st(1)
fldt   -0x10(%rdi)
fsub   %st(3),%st
fmul   %st,%st(0)
faddp  %st,%st(1)
add    $0x4,%rdx
fldt   (%rdi)
fsub   %st(3),%st
fmul   %st,%st(0)
faddp  %st,%st(1)
add    $0x40,%rdi
cmp    %rdx,%rsi
jne    1190 <standard_deviation+0x70>
test   %rcx,%rcx
je     11f2 <standard_deviation+0xd2>
shl    $0x4,%rdx
add    %rdx,%rbx
shl    $0x4,%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
fldt   (%rbx,%rdx,1)
fsub   %st(3),%st
fmul   %st,%st(0)
faddp  %st,%st(1)
add    $0x10,%rdx
cmp    %rdx,%rcx
jne    11e0 <standard_deviation+0xc0>
fstp   %st(2)
mov    %rax,0x10(%rsp)
fildll 0x10(%rsp)
fdivrp %st,%st(2)
fld    %st(1)
fsqrt
fxch   %st(2)
fucomi %st(1),%st
fstp   %st(1)
jae    1217 <standard_deviation+0xf7>
fstp   %st(1)
fstpt  (%rsp)
call   1040 <sqrt@plt>
fldz
fstp   %st(0)
fstpt  (%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@standard_deviation.i = internal global i32 0
define void @standard_deviation(x86_fp80* %0, x86_fp80 %1, x86_fp80* %2) {
%4 = alloca x86_fp80*
%5 = alloca x86_fp80
%6 = alloca x86_fp80*
%7 = alloca i64
%8 = alloca x86_fp80
%9 = alloca x86_fp80
%10 = alloca x86_fp80
store x86_fp80* %0, x86_fp80** %4
store x86_fp80 %1, x86_fp80* %5
store x86_fp80* %2, x86_fp80** %6
store i64 0, i64* %7
store x86_fp80 0xK00000000000000000000, x86_fp80* %9
%11 = load x86_fp80, x86_fp80* %5
%12 = load x86_fp80*, x86_fp80** %6
%13 = load i32, i32* @standard_deviation.i
%14 = add i32 %13, 1
store i32 %14, i32* @standard_deviation.i
%15 = zext i32 %13 to i64
%16 = getelementptr inbounds x86_fp80, x86_fp80* %12, i64 %15
store x86_fp80 %11, x86_fp80* %16
%17 = load x86_fp80*, x86_fp80** %6
%18 = load i32, i32* @standard_deviation.i
%19 = call x86_fp80 @_mean(x86_fp80* %17, i32 %18)
store x86_fp80 %19, x86_fp80* %8
br label %20
20: ; preds = %25, %3
%21 = load i64, i64* %7
%22 = load i32, i32* @standard_deviation.i
%23 = zext i32 %22 to i64
%24 = icmp ult i64 %21, %23
br i1 %24, label %25, label %37
25: ; preds = %20
%26 = load x86_fp80*, x86_fp80** %6
%27 = load i64, i64* %7
%28 = add i64 %27, 1
store i64 %28, i64* %7
%29 = getelementptr inbounds x86_fp80, x86_fp80* %26, i64 %27
%30 = load x86_fp80, x86_fp80* %29
%31 = load x86_fp80, x86_fp80* %8
%32 = fsub x86_fp80 %30, %31
store x86_fp80 %32, x86_fp80* %10
%33 = load x86_fp80, x86_fp80* %10
%34 = load x86_fp80, x86_fp80* %10
%35 = load x86_fp80, x86_fp80* %9
%36 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %33, x86_fp80 %34, x86_fp80 %35)
store x86_fp80 %36, x86_fp80* %9
br label %20
37: ; preds = %20
%38 = load x86_fp80, x86_fp80* %9
%39 = load i32, i32* @standard_deviation.i
%40 = uitofp i32 %39 to x86_fp80
%41 = fdiv x86_fp80 %38, %40
%42 = call x86_fp80 @sqrt(x86_fp80 %41)
%43 = load x86_fp80*, x86_fp80** %4
store x86_fp80 %42, x86_fp80* %43
ret void
}

LLVM IR (-O2):
@standard_deviation.i = internal unnamed_addr global i32 0
define void @standard_deviation(x86_fp80* nocapture writeonly %0, x86_fp80 %1, x86_fp80* %2) {
%4 = load i32, i32* @standard_deviation.i
%5 = add i32 %4, 1
store i32 %5, i32* @standard_deviation.i
%6 = zext i32 %4 to i64
%7 = getelementptr inbounds x86_fp80, x86_fp80* %2, i64 %6
store x86_fp80 %1, x86_fp80* %7
%8 = tail call x86_fp80 @_mean(x86_fp80* %2, i32 %5)
%9 = load i32, i32* @standard_deviation.i
%10 = zext i32 %9 to i64
%11 = icmp eq i32 %9, 0
br i1 %11, label %60, label %12
12: ; preds = %3
%13 = add nsw i64 %10, -1
%14 = and i64 %10, 3
%15 = icmp ult i64 %13, 3
br i1 %15, label %44, label %16
16: ; preds = %12
%17 = and i64 %10, 4294967292
br label %18
18: ; preds = %18, %16
%19 = phi i64 [ 0, %16 ], [ %37, %18 ]
%20 = phi x86_fp80 [ 0xK00000000000000000000, %16 ], [ %41, %18 ]
%21 = phi i64 [ 0, %16 ], [ %42, %18 ]
%22 = or i64 %19, 1
%23 = getelementptr inbounds x86_fp80, x86_fp80* %2, i64 %19
%24 = load x86_fp80, x86_fp80* %23
%25 = fsub x86_fp80 %24, %8
%26 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %25, x86_fp80 %25, x86_fp80 %20)
%27 = or i64 %19, 2
%28 = getelementptr inbounds x86_fp80, x86_fp80* %2, i64 %22
%29 = load x86_fp80, x86_fp80* %28
%30 = fsub x86_fp80 %29, %8
%31 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %30, x86_fp80 %30, x86_fp80 %26)
%32 = or i64 %19, 3
%33 = getelementptr inbounds x86_fp80, x86_fp80* %2, i64 %27
%34 = load x86_fp80, x86_fp80* %33
%35 = fsub x86_fp80 %34, %8
%36 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %35, x86_fp80 %35, x86_fp80 %31)
%37 = add nuw nsw i64 %19, 4
%38 = getelementptr inbounds x86_fp80, x86_fp80* %2, i64 %32
%39 = load x86_fp80, x86_fp80* %38
%40 = fsub x86_fp80 %39, %8
%41 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %40, x86_fp80 %40, x86_fp80 %36)
%42 = add i64 %21, 4
%43 = icmp eq i64 %42, %17
br i1 %43, label %44, label %18
44: ; preds = %18, %12
%45 = phi x86_fp80 [ undef, %12 ], [ %41, %18 ]
%46 = phi i64 [ 0, %12 ], [ %37, %18 ]
%47 = phi x86_fp80 [ 0xK00000000000000000000, %12 ], [ %41, %18 ]
%48 = icmp eq i64 %14, 0
br i1 %48, label %60, label %49
49: ; preds = %44, %49
%50 = phi i64 [ %53, %49 ], [ %46, %44 ]
%51 = phi x86_fp80 [ %57, %49 ], [ %47, %44 ]
%52 = phi i64 [ %58, %49 ], [ 0, %44 ]
%53 = add nuw nsw i64 %50, 1
%54 = getelementptr inbounds x86_fp80, x86_fp80* %2, i64 %50
%55 = load x86_fp80, x86_fp80* %54
%56 = fsub x86_fp80 %55, %8
%57 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %56, x86_fp80 %56, x86_fp80 %51)
%58 = add i64 %52, 1
%59 = icmp eq i64 %58, %14
br i1 %59, label %60, label %49
60: ; preds = %44, %49, %3
%61 = phi x86_fp80 [ 0xK00000000000000000000, %3 ], [ %45, %44 ], [ %57, %49 ]
%62 = uitofp i32 %9 to x86_fp80
%63 = fdiv x86_fp80 %61, %62
%64 = tail call x86_fp80 @sqrt(x86_fp80 %63)
store x86_fp80 %64, x86_fp80* %0
ret void
}