#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 findmean(float *, int);
scalar_t__ malloc(int);
scalar_t__ pow(float, int);
int /*<<< orphan*/ printf(char *, float);
scalar_t__ sqrt(float);
float findstd(float *signal, int signal_length) {
  int i = 0, j = 0;
  float *array = (float *)malloc(sizeof(float) * signal_length);
  float sum = 0, mean = 0, variance = 0, std = 0;
  mean = findmean(signal, signal_length);
  for (j = 0; j < signal_length; j++) {
    array[i] = (float)pow((signal[i] - mean), 2);
    sum += array[i];
    i++;
  }
  variance = sum / signal_length;
  std = (float)sqrt(variance);
  printf("The standard deviation is %f!\n", std);
  return std;
}


x86 assembly (clang, -O0):
<findstd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <findmean@plt>
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1220 <findstd+0xd0>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
subss  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
cvtsi2ss %rax,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <findstd+0x68>
movss  -0x24(%rbp),%xmm0
cvtsi2ssl -0xc(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1060 <sqrt@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
lea    0xdad(%rip),%rdi
call   1030 <printf@plt>
movss  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findstd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r12
lea    0x0(,%r14,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %r14d,%esi
call   1070 <findmean@plt>
test   %r14d,%r14d
jle    119a <findstd+0x4a>
movss  %xmm0,0x4(%rsp)
mov    %r14d,%r13d
cmp    $0x1,%r14d
jne    11a2 <findstd+0x52>
xorps  %xmm1,%xmm1
xor    %ebx,%ebx
jmp    121f <findstd+0xcf>
xorps  %xmm1,%xmm1
jmp    1257 <findstd+0x107>
mov    %r13d,%ebp
and    $0xfffffffe,%ebp
xorps  %xmm1,%xmm1
xor    %ebx,%ebx
nopl   (%rax)
movss  %xmm1,(%rsp)
movss  (%r12,%rbx,4),%xmm0
subss  0x4(%rsp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,(%r15,%rbx,4)
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
movss  0x4(%r12,%rbx,4),%xmm0
subss  0x4(%rsp),%xmm0
mov    $0x2,%edi
call   1050 <pow@plt>
movss  (%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,0x4(%r15,%rbx,4)
addss  %xmm0,%xmm1
add    $0x2,%rbx
cmp    %rbx,%rbp
jne    11b0 <findstd+0x60>
test   $0x1,%r13b
je     1257 <findstd+0x107>
movss  (%r12,%rbx,4),%xmm0
subss  0x4(%rsp),%xmm0
mov    $0x2,%edi
movss  %xmm1,(%rsp)
call   1050 <pow@plt>
movss  (%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,(%r15,%rbx,4)
addss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %r14d,%xmm0
divss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1060 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  %xmm0,(%rsp)
lea    0xd81(%rip),%rdi
call   1030 <printf@plt>
movss  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [31 x i8] c"The standard deviation is %f!\0A\00"
define float @findstd(float* %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to float*
%6 = tail call float @findmean(float* %0, i32 %1)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %49
8: ; preds = %2
%9 = zext i32 %1 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %1, 1
br i1 %11, label %36, label %12
12: ; preds = %8
%13 = and i64 %9, 4294967294
br label %14
14: ; preds = %14, %12
%15 = phi i64 [ 0, %12 ], [ %33, %14 ]
%16 = phi float [ 0.000000e+00, %12 ], [ %32, %14 ]
%17 = phi i64 [ 0, %12 ], [ %34, %14 ]
%18 = getelementptr inbounds float, float* %0, i64 %15
%19 = load float, float* %18
%20 = fsub float %19, %6
%21 = tail call i64 @pow(float %20, i32 2)
%22 = sitofp i64 %21 to float
%23 = getelementptr inbounds float, float* %5, i64 %15
store float %22, float* %23
%24 = fadd float %16, %22
%25 = or i64 %15, 1
%26 = getelementptr inbounds float, float* %0, i64 %25
%27 = load float, float* %26
%28 = fsub float %27, %6
%29 = tail call i64 @pow(float %28, i32 2)
%30 = sitofp i64 %29 to float
%31 = getelementptr inbounds float, float* %5, i64 %25
store float %30, float* %31
%32 = fadd float %24, %30
%33 = add nuw nsw i64 %15, 2
%34 = add i64 %17, 2
%35 = icmp eq i64 %34, %13
br i1 %35, label %36, label %14
36: ; preds = %14, %8
%37 = phi float [ undef, %8 ], [ %32, %14 ]
%38 = phi i64 [ 0, %8 ], [ %33, %14 ]
%39 = phi float [ 0.000000e+00, %8 ], [ %32, %14 ]
%40 = icmp eq i64 %10, 0
br i1 %40, label %49, label %41
41: ; preds = %36
%42 = getelementptr inbounds float, float* %0, i64 %38
%43 = load float, float* %42
%44 = fsub float %43, %6
%45 = tail call i64 @pow(float %44, i32 2)
%46 = sitofp i64 %45 to float
%47 = getelementptr inbounds float, float* %5, i64 %38
store float %46, float* %47
%48 = fadd float %39, %46
br label %49
49: ; preds = %41, %36, %2
%50 = phi float [ 0.000000e+00, %2 ], [ %37, %36 ], [ %48, %41 ]
%51 = sitofp i32 %1 to float
%52 = fdiv float %50, %51
%53 = tail call i64 @sqrt(float %52)
%54 = sitofp i64 %53 to float
%55 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), float %54)
ret float %54
}