#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 */
float pow(float, int);
float sqrt(float);
float compute_standard_deviation(unsigned long *values) {
  float avg = 0.0f, var = 0.0f;
  for (int i = 0; i < 1000; i++) {
    avg += ((float)values[i]) / ((float)1000);
  }
  for (int i = 0; i < 1000; i++) {
    var += pow(((float)values[i]) - avg, 2) / ((float)1000);
  }
  return sqrt(var);
}


x86 assembly (clang, -O0):
<compute_standard_deviation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    11be <compute_standard_deviation+0x9e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x20(%rbp)
test   %rax,%rax
movss  %xmm0,-0x1c(%rbp)
js     1195 <compute_standard_deviation+0x75>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  0xe5e(%rip),%xmm1
divss  %xmm1,%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <compute_standard_deviation+0x23>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    124f <compute_standard_deviation+0x12f>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x28(%rbp)
test   %rax,%rax
movss  %xmm0,-0x24(%rbp)
js     1217 <compute_standard_deviation+0xf7>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movss  0xdcd(%rip),%xmm1
divss  %xmm1,%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c5 <compute_standard_deviation+0xa5>
movss  -0x10(%rbp),%xmm0
call   1040 <sqrt@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_standard_deviation>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xorps  %xmm4,%xmm4
mov    $0x1,%eax
movss  0xec9(%rip),%xmm3
jmp    116a <compute_standard_deviation+0x4a>
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2ss %rcx,%xmm1
divss  %xmm3,%xmm0
movaps %xmm4,%xmm2
addss  %xmm0,%xmm2
divss  %xmm3,%xmm1
movaps %xmm1,%xmm4
addss  %xmm2,%xmm4
add    $0x2,%rax
cmp    $0x3e9,%rax
je     11bb <compute_standard_deviation+0x9b>
mov    -0x8(%r14,%rax,8),%rcx
test   %rcx,%rcx
js     1180 <compute_standard_deviation+0x60>
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
jmp    1198 <compute_standard_deviation+0x78>
xchg   %ax,%ax
mov    %rcx,%rdx
shr    %rdx
and    $0x1,%ecx
or     %rdx,%rcx
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
mov    (%r14,%rax,8),%rcx
test   %rcx,%rcx
jns    1140 <compute_standard_deviation+0x20>
mov    %rcx,%rdx
shr    %rdx
and    $0x1,%ecx
or     %rdx,%rcx
xorps  %xmm1,%xmm1
cvtsi2ss %rcx,%xmm1
addss  %xmm1,%xmm1
jmp    1148 <compute_standard_deviation+0x28>
movss  %xmm4,0x4(%rsp)
xorps  %xmm0,%xmm0
mov    $0x1,%ebx
jmp    1223 <compute_standard_deviation+0x103>
nopl   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
movss  0x4(%rsp),%xmm3
movss  (%rsp),%xmm4
movss  0xe15(%rip),%xmm2
divss  %xmm2,%xmm0
addss  %xmm0,%xmm4
movss  %xmm4,(%rsp)
subss  %xmm3,%xmm1
movaps %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
divss  0xdef(%rip),%xmm0
addss  (%rsp),%xmm0
add    $0x2,%rbx
cmp    $0x3e9,%rbx
je     1296 <compute_standard_deviation+0x176>
mov    -0x8(%r14,%rbx,8),%rax
test   %rax,%rax
movss  %xmm0,(%rsp)
js     1240 <compute_standard_deviation+0x120>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
jmp    1258 <compute_standard_deviation+0x138>
nopl   0x0(%rax)
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
subss  %xmm1,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
mov    (%r14,%rbx,8),%rax
test   %rax,%rax
jns    11d0 <compute_standard_deviation+0xb0>
mov    %rax,%rcx
shr    %rcx
and    $0x1,%eax
or     %rcx,%rax
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
addss  %xmm1,%xmm1
jmp    11d8 <compute_standard_deviation+0xb8>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     12aa <compute_standard_deviation+0x18a>
sqrtss %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define float @compute_standard_deviation(i64* %0) {
%2 = alloca i64*
%3 = alloca float
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
store i64* %0, i64** %2
store float 0.000000e+00, float* %3
store float 0.000000e+00, float* %4
store i32 0, i32* %5
br label %7
7: ; preds = %20, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i64*, i64** %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i64, i64* %11, i64 %13
%15 = load i64, i64* %14
%16 = uitofp i64 %15 to float
%17 = fdiv float %16, 1.000000e+03
%18 = load float, float* %3
%19 = fadd float %18, %17
store float %19, float* %3
br label %20
20: ; preds = %10
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %7
store i32 0, i32* %6
br label %24
24: ; preds = %40, %23
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 1000
br i1 %26, label %27, label %43
27: ; preds = %24
%28 = load i64*, i64** %2
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i64, i64* %28, i64 %30
%32 = load i64, i64* %31
%33 = uitofp i64 %32 to float
%34 = load float, float* %3
%35 = fsub float %33, %34
%36 = call float @pow(float %35, i32 2)
%37 = fdiv float %36, 1.000000e+03
%38 = load float, float* %4
%39 = fadd float %38, %37
store float %39, float* %4
br label %40
40: ; preds = %27
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %24
43: ; preds = %24
%44 = load float, float* %4
%45 = call float @sqrt(float %44)
ret float %45
}

LLVM IR (-O2):
define float @compute_standard_deviation(i64* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ 0, %1 ], [ %16, %2 ]
%4 = phi float [ 0.000000e+00, %1 ], [ %15, %2 ]
%5 = getelementptr inbounds i64, i64* %0, i64 %3
%6 = load i64, i64* %5
%7 = uitofp i64 %6 to float
%8 = fdiv float %7, 1.000000e+03
%9 = fadd float %4, %8
%10 = or i64 %3, 1
%11 = getelementptr inbounds i64, i64* %0, i64 %10
%12 = load i64, i64* %11
%13 = uitofp i64 %12 to float
%14 = fdiv float %13, 1.000000e+03
%15 = fadd float %9, %14
%16 = add nuw nsw i64 %3, 2
%17 = icmp eq i64 %16, 1000
br i1 %17, label %20, label %2
18: ; preds = %20
%19 = tail call float @sqrt(float %37)
ret float %19
20: ; preds = %2, %20
%21 = phi i64 [ %38, %20 ], [ 0, %2 ]
%22 = phi float [ %37, %20 ], [ 0.000000e+00, %2 ]
%23 = getelementptr inbounds i64, i64* %0, i64 %21
%24 = load i64, i64* %23
%25 = uitofp i64 %24 to float
%26 = fsub float %25, %15
%27 = tail call float @pow(float %26, i32 2)
%28 = fdiv float %27, 1.000000e+03
%29 = fadd float %22, %28
%30 = or i64 %21, 1
%31 = getelementptr inbounds i64, i64* %0, i64 %30
%32 = load i64, i64* %31
%33 = uitofp i64 %32 to float
%34 = fsub float %33, %15
%35 = tail call float @pow(float %34, i32 2)
%36 = fdiv float %35, 1.000000e+03
%37 = fadd float %29, %36
%38 = add nuw nsw i64 %21, 2
%39 = icmp eq i64 %38, 1000
br i1 %39, label %18, label %20
}