#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 average(double *);
scalar_t__ pow(double, int);
double variance(double input[100]) {
  int i;
  double distance_sum, av;
  distance_sum = 0;
  av = average(input);
  for (i = 0; i < 100; i++) {
    distance_sum += pow(input[i] - av, 2);
  }
  return distance_sum / (double)100;
}


x86 assembly (clang, -O0):
<variance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <average@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    118c <variance+0x6c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x20(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1149 <variance+0x29>
movsd  -0x18(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variance>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1030 <average@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
mov    $0x3,%ebx
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
movsd  -0x18(%r14,%rbx,8),%xmm0
subsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  -0x10(%r14,%rbx,8),%xmm0
subsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  -0x8(%r14,%rbx,8),%xmm0
subsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%r14,%rbx,8),%xmm0
subsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x4,%rbx
cmp    $0x67,%rbx
jne    1140 <variance+0x20>
divsd  0xdff(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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