#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 */
double sqrt(double);
void calc_sdev(double *val, int N) {
  int i;
  for (i = 0; i < N; i++)
    val[i] = sqrt(val[i] / (double)N);
}


x86 assembly (clang, -O0):
<calc_sdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1168 <calc_sdev+0x58>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <calc_sdev+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_sdev>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11e6 <calc_sdev+0xd6>
mov    %rdi,%r14
cvtsi2sd %esi,%xmm1
mov    %esi,%r15d
cmp    $0x1,%esi
jne    115c <calc_sdev+0x4c>
xor    %ebx,%ebx
test   $0x1,%r15b
je     11e6 <calc_sdev+0xd6>
movsd  (%r14,%rbx,8),%xmm0
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11db <calc_sdev+0xcb>
sqrtsd %xmm0,%xmm0
jmp    11e0 <calc_sdev+0xd0>
mov    %r15d,%r12d
and    $0xfffffffe,%r12d
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
movsd  %xmm1,(%rsp)
jmp    118e <calc_sdev+0x7e>
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  (%rsp),%xmm1
movsd  %xmm0,0x8(%r14,%rbx,8)
add    $0x2,%rbx
cmp    %rbx,%r12
je     1131 <calc_sdev+0x21>
movsd  (%r14,%rbx,8),%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     11b0 <calc_sdev+0xa0>
sqrtsd %xmm0,%xmm0
jmp    11be <calc_sdev+0xae>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1030 <sqrt@plt>
xorpd  %xmm2,%xmm2
movsd  (%rsp),%xmm1
movsd  %xmm0,(%r14,%rbx,8)
movsd  0x8(%r14,%rbx,8),%xmm0
divsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     1170 <calc_sdev+0x60>
sqrtsd %xmm0,%xmm0
jmp    117e <calc_sdev+0x6e>
call   1030 <sqrt@plt>
movsd  %xmm0,(%r14,%rbx,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @calc_sdev(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %24, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = load double*, double** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds double, double* %11, i64 %13
%15 = load double, double* %14
%16 = load i32, i32* %4
%17 = sitofp i32 %16 to double
%18 = fdiv double %15, %17
%19 = call double @sqrt(double %18)
%20 = load double*, double** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
store double %19, double* %23
br label %24
24: ; preds = %10
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %6
27: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @calc_sdev(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %34
4: ; preds = %2
%5 = sitofp i32 %1 to double
%6 = zext i32 %1 to i64
%7 = and i64 %6, 1
%8 = icmp eq i32 %1, 1
br i1 %8, label %26, label %9
9: ; preds = %4
%10 = and i64 %6, 4294967294
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %23, %11 ]
%13 = phi i64 [ 0, %9 ], [ %24, %11 ]
%14 = getelementptr inbounds double, double* %0, i64 %12
%15 = load double, double* %14
%16 = fdiv double %15, %5
%17 = tail call double @sqrt(double %16)
store double %17, double* %14
%18 = or i64 %12, 1
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = load double, double* %19
%21 = fdiv double %20, %5
%22 = tail call double @sqrt(double %21)
store double %22, double* %19
%23 = add nuw nsw i64 %12, 2
%24 = add i64 %13, 2
%25 = icmp eq i64 %24, %10
br i1 %25, label %26, label %11
26: ; preds = %11, %4
%27 = phi i64 [ 0, %4 ], [ %23, %11 ]
%28 = icmp eq i64 %7, 0
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = getelementptr inbounds double, double* %0, i64 %27
%31 = load double, double* %30
%32 = fdiv double %31, %5
%33 = tail call double @sqrt(double %32)
store double %33, double* %30
br label %34
34: ; preds = %29, %26, %2
ret void
}