#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*/ EINVAL;
int /*<<< orphan*/ errno;
double mean(double arr[], size_t arrlen) {
  if (arrlen == 0) {
    errno = EINVAL;
    return 0.0;
  }
  unsigned int i;
  double m = 0.0;
  for (i = 0; i < arrlen; i++) {
    m += arr[i] / arrlen;
  }
  return m;
}


x86 assembly (clang, -O0):
<mean>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1136 <mean+0x36>
mov    0x2eba(%rip),%rax
mov    (%rax),%ecx
mov    0x2eb9(%rip),%rax
mov    %ecx,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ab <mean+0xab>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    11a1 <mean+0xa1>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe9b(%rip),%xmm2
movq   -0x18(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xe9a(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <mean+0x45>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<mean>:
test   %rsi,%rsi
je     1146 <mean+0x46>
movq   %rsi,%xmm0
punpckldq 0xeee(%rip),%xmm0
subpd  0xef6(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
xor    %eax,%eax
nopl   0x0(%rax)
movsd  (%rdi,%rax,8),%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%eax
cmp    %rsi,%rax
jb     1130 <mean+0x30>
ret
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    0x2e8a(%rip),%rcx
mov    %eax,(%rcx)
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
define double @mean(double* %0, i64 %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i64
%6 = alloca i32
%7 = alloca double
store double* %0, double** %4
store i64 %1, i64* %5
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* @EINVAL
store i32 %11, i32* @errno
store double 0.000000e+00, double* %3
br label %34
12: ; preds = %2
store double 0.000000e+00, double* %7
store i32 0, i32* %6
br label %13
13: ; preds = %29, %12
%14 = load i32, i32* %6
%15 = zext i32 %14 to i64
%16 = load i64, i64* %5
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %13
%19 = load double*, double** %4
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load i64, i64* %5
%25 = uitofp i64 %24 to double
%26 = fdiv double %23, %25
%27 = load double, double* %7
%28 = fadd double %27, %26
store double %28, double* %7
br label %29
29: ; preds = %18
%30 = load i32, i32* %6
%31 = add i32 %30, 1
store i32 %31, i32* %6
br label %13
32: ; preds = %13
%33 = load double, double* %7
store double %33, double* %3
br label %34
34: ; preds = %32, %10
%35 = load double, double* %3
ret double %35
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define double @mean(double* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = uitofp i64 %1 to double
br label %8
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %18
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %16, %8 ]
%10 = phi double [ 0.000000e+00, %4 ], [ %14, %8 ]
%11 = getelementptr inbounds double, double* %0, i64 %9
%12 = load double, double* %11
%13 = fdiv double %12, %5
%14 = fadd double %10, %13
%15 = add nuw nsw i64 %9, 1
%16 = and i64 %15, 4294967295
%17 = icmp ult i64 %16, %1
br i1 %17, label %8, label %18
18: ; preds = %8, %6
%19 = phi double [ 0.000000e+00, %6 ], [ %14, %8 ]
ret double %19
}