#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
double sqrt(double);
int /*<<< orphan*/ stdout;
double std(double x[], int n, double mu, bool verbose) {
  double sigma;
  int m, i;
  sigma = 0.;
  m = 0;
  if (verbose)
    printf("Calculating sigma...\n");
  for (i = 0; i < n; i++) {
    sigma += (x[i] - mu) * (x[i] - mu);
    if (verbose)
      if (((int)(100 * (i / (n + 0.)))) == m) {
        printf("\r\r\r\r%d%%", m);
        fflush(stdout);
        m++;
      }
  }
  sigma = sqrt(sigma / (n - 1.));
  if (verbose)
    printf("\r\r\r\rDone!\n");
  return sigma;
}


x86 assembly (clang, -O0):
<std>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     116e <std+0x3e>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    122f <std+0xff>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
subsd  -0x18(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     121c <std+0xec>
cvtsi2sdl -0x30(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm0
xorps  %xmm2,%xmm2
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xe2a(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
cmp    -0x2c(%rbp),%eax
jne    1217 <std+0xe7>
mov    -0x2c(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    121c <std+0xec>
jmp    1221 <std+0xf1>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1175 <std+0x45>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xdbf(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     126b <std+0x13b>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<std>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r12
test   %edx,%edx
movsd  %xmm0,0x10(%rsp)
je     1172 <std+0x32>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
movsd  0x10(%rsp),%xmm0
cvtsi2sd %ebp,%xmm3
xorpd  %xmm2,%xmm2
test   %ebp,%ebp
jle    1235 <std+0xf5>
mov    %ebp,%ebx
xorpd  %xmm2,%xmm2
movsd  0xe70(%rip),%xmm4
mov    0x2e49(%rip),%r13
xor    %r14d,%r14d
xor    %ebp,%ebp
movsd  %xmm3,0x18(%rsp)
jmp    11c5 <std+0x85>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
subsd  %xmm0,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm5,%xmm2
add    $0x1,%r14
cmp    %r14,%rbx
je     1235 <std+0xf5>
movsd  (%r12,%r14,8),%xmm5
test   %r15d,%r15d
je     11b0 <std+0x70>
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm3,%xmm1
mulsd  %xmm4,%xmm1
cvttsd2si %xmm1,%eax
cmp    %eax,%ebp
jne    11b0 <std+0x70>
lea    0xe29(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
movsd  %xmm2,0x8(%rsp)
movsd  %xmm5,0x20(%rsp)
call   1040 <printf@plt>
mov    0x0(%r13),%edi
call   1050 <fflush@plt>
movsd  0x20(%rsp),%xmm5
movsd  0xde5(%rip),%xmm4
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm0
add    $0x1,%ebp
jmp    11b0 <std+0x70>
addsd  0xdcb(%rip),%xmm3
divsd  %xmm3,%xmm2
ucomisd 0xdc7(%rip),%xmm2
jb     1259 <std+0x119>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
test   %r15d,%r15d
jne    1267 <std+0x127>
jmp    127f <std+0x13f>
movapd %xmm2,%xmm0
call   1060 <sqrt@plt>
test   %r15d,%r15d
je     127f <std+0x13f>
lea    0xdb3(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Calculating sigma...\0A\00"
@.str.1 = [9 x i8] c"\0D\0D\0D\0D%d%%\00"
@stdout = global i32 0
@.str.2 = [11 x i8] c"\0D\0D\0D\0DDone!\0A\00"
define double @std(double* %0, i32 %1, double %2, i32 %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %9
store i32 0, i32* %10
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %4
store i32 0, i32* %11
br label %17
17: ; preds = %60, %16
%18 = load i32, i32* %11
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %63
21: ; preds = %17
%22 = load double*, double** %5
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double, double* %7
%28 = fsub double %26, %27
%29 = load double*, double** %5
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = load double, double* %7
%35 = fsub double %33, %34
%36 = load double, double* %9
%37 = call double @llvm.fmuladd.f64(double %28, double %35, double %36)
store double %37, double* %9
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %59
40: ; preds = %21
%41 = load i32, i32* %11
%42 = sitofp i32 %41 to double
%43 = load i32, i32* %6
%44 = sitofp i32 %43 to double
%45 = fadd double %44, 0.000000e+00
%46 = fdiv double %42, %45
%47 = fmul double 1.000000e+02, %46
%48 = fptosi double %47 to i32
%49 = load i32, i32* %10
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %58
51: ; preds = %40
%52 = load i32, i32* %10
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %52)
%54 = load i32, i32* @stdout
%55 = call i32 @fflush(i32 %54)
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
br label %58
58: ; preds = %51, %40
br label %59
59: ; preds = %58, %21
br label %60
60: ; preds = %59
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %17
63: ; preds = %17
%64 = load double, double* %9
%65 = load i32, i32* %6
%66 = sitofp i32 %65 to double
%67 = fsub double %66, 1.000000e+00
%68 = fdiv double %64, %67
%69 = call double @sqrt(double %68)
store double %69, double* %9
%70 = load i32, i32* %8
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %63
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %74
74: ; preds = %72, %63
%75 = load double, double* %9
ret double %75
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"\0D\0D\0D\0D%d%%\00"
@stdout = global i32 0
@str = [10 x i8] c"\0D\0D\0D\0DDone!\00"
@str.3 = [21 x i8] c"Calculating sigma...\00"
define double @std(double* nocapture %0, i32 %1, double %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.3, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = icmp sgt i32 %1, 0
%10 = sitofp i32 %1 to double
br i1 %9, label %11, label %37
11: ; preds = %8
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %11, %33
%14 = phi i64 [ 0, %11 ], [ %35, %33 ]
%15 = phi i32 [ 0, %11 ], [ %34, %33 ]
%16 = phi double [ 0.000000e+00, %11 ], [ %20, %33 ]
%17 = getelementptr inbounds double, double* %0, i64 %14
%18 = load double, double* %17
%19 = fsub double %18, %2
%20 = tail call double @llvm.fmuladd.f64(double %19, double %19, double %16)
br i1 %5, label %33, label %21
21: ; preds = %13
%22 = trunc i64 %14 to i32
%23 = sitofp i32 %22 to double
%24 = fdiv double %23, %10
%25 = fmul double %24, 1.000000e+02
%26 = fptosi double %25 to i32
%27 = icmp eq i32 %15, %26
br i1 %27, label %28, label %33
28: ; preds = %21
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%30 = load i32, i32* @stdout
%31 = tail call i32 @fflush(i32 %30)
%32 = add nsw i32 %15, 1
br label %33
33: ; preds = %13, %28, %21
%34 = phi i32 [ %32, %28 ], [ %15, %21 ], [ %15, %13 ]
%35 = add nuw nsw i64 %14, 1
%36 = icmp eq i64 %35, %12
br i1 %36, label %37, label %13
37: ; preds = %33, %8
%38 = phi double [ 0.000000e+00, %8 ], [ %20, %33 ]
%39 = fadd double %10, -1.000000e+00
%40 = fdiv double %38, %39
%41 = tail call double @sqrt(double %40)
br i1 %5, label %44, label %42
42: ; preds = %37
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %44
44: ; preds = %42, %37
ret double %41
}