#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*/ die(char *);
void stat(double *smallest, double *average, double *largest, const double a[],
          unsigned elements) {
  double min = 0, mean = 0, max = 0;
  unsigned i = 0;
  if (elements == 0)
    die("Zero elements defined. stat() needs at least one element to "
        "examine.\n");
  min = *a;
  *smallest = min;
  mean = *a;
  *average = mean;
  max = *a;
  *largest = max;
  if (elements > 1) {
    for (i; i < elements; ++i) {
      if (min >= a[i]) {
        *smallest = a[i];
      }
      mean += a[i];
      if (max <= a[i]) {
        *largest = a[i];
      }
    }
    mean = mean / elements;
    *average = mean;
  }
}


x86 assembly (clang, -O0):
<stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1161 <stat+0x51>
lea    0xea4(%rip),%rdi
call   1030 <die@plt>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
cmpl   $0x1,-0x24(%rbp)
jbe    126b <stat+0x15b>
mov    -0x44(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1248 <stat+0x138>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
ucomisd (%rax,%rcx,8),%xmm0
jb     11f0 <stat+0xe0>
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1235 <stat+0x125>
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    123a <stat+0x12a>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11b9 <stat+0xa9>
movsd  -0x38(%rbp),%xmm0
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%ebp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
test   %r8d,%r8d
jne    1138 <stat+0x28>
lea    0xecd(%rip),%rdi
call   1030 <die@plt>
movsd  (%rbx),%xmm2
movsd  %xmm2,(%r12)
movsd  (%rbx),%xmm0
movsd  %xmm0,(%r14)
movsd  (%rbx),%xmm1
movsd  %xmm1,(%r15)
cmp    $0x2,%ebp
jb     1201 <stat+0xf1>
mov    %ebp,%eax
lea    0x0(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
xor    %ecx,%ecx
jmp    1181 <stat+0x71>
nop
addsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
add    $0x10,%rcx
cmp    %rcx,%rdx
je     11c7 <stat+0xb7>
movsd  (%rbx,%rcx,1),%xmm3
ucomisd %xmm3,%xmm2
jb     1197 <stat+0x87>
movsd  %xmm3,(%r12)
movsd  (%rbx,%rcx,1),%xmm3
ucomisd %xmm1,%xmm3
jb     11a2 <stat+0x92>
movsd  %xmm3,(%r15)
movsd  0x8(%rbx,%rcx,1),%xmm4
ucomisd %xmm4,%xmm2
jb     11ba <stat+0xaa>
movsd  %xmm4,(%r12)
movsd  0x8(%rbx,%rcx,1),%xmm4
ucomisd %xmm1,%xmm4
jb     1170 <stat+0x60>
movsd  %xmm4,(%r15)
jmp    1170 <stat+0x60>
test   $0x1,%al
je     11f0 <stat+0xe0>
movsd  (%rbx,%rcx,1),%xmm3
ucomisd %xmm3,%xmm2
jb     11e1 <stat+0xd1>
movsd  %xmm3,(%r12)
movsd  (%rbx,%rcx,1),%xmm3
addsd  %xmm3,%xmm0
ucomisd %xmm1,%xmm3
jb     11f0 <stat+0xe0>
movsd  %xmm3,(%r15)
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [70 x i8] c"Zero elements defined. stat() needs at least one element to examine.\0A\00"
define void @stat(double* %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %14
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = call i32 @die(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %5
%20 = load double*, double** %9
%21 = load double, double* %20
store double %21, double* %11
%22 = load double, double* %11
%23 = load double*, double** %6
store double %22, double* %23
%24 = load double*, double** %9
%25 = load double, double* %24
store double %25, double* %12
%26 = load double, double* %12
%27 = load double*, double** %7
store double %26, double* %27
%28 = load double*, double** %9
%29 = load double, double* %28
store double %29, double* %13
%30 = load double, double* %13
%31 = load double*, double** %8
store double %30, double* %31
%32 = load i32, i32* %10
%33 = icmp ugt i32 %32, 1
br i1 %33, label %34, label %88
34: ; preds = %19
%35 = load i32, i32* %14
br label %36
36: ; preds = %78, %34
%37 = load i32, i32* %14
%38 = load i32, i32* %10
%39 = icmp ult i32 %37, %38
br i1 %39, label %40, label %81
40: ; preds = %36
%41 = load double, double* %11
%42 = load double*, double** %9
%43 = load i32, i32* %14
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = fcmp oge double %41, %46
br i1 %47, label %48, label %55
48: ; preds = %40
%49 = load double*, double** %9
%50 = load i32, i32* %14
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = load double*, double** %6
store double %53, double* %54
br label %55
55: ; preds = %48, %40
%56 = load double*, double** %9
%57 = load i32, i32* %14
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = load double, double* %12
%62 = fadd double %61, %60
store double %62, double* %12
%63 = load double, double* %13
%64 = load double*, double** %9
%65 = load i32, i32* %14
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
%68 = load double, double* %67
%69 = fcmp ole double %63, %68
br i1 %69, label %70, label %77
70: ; preds = %55
%71 = load double*, double** %9
%72 = load i32, i32* %14
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = load double*, double** %8
store double %75, double* %76
br label %77
77: ; preds = %70, %55
br label %78
78: ; preds = %77
%79 = load i32, i32* %14
%80 = add i32 %79, 1
store i32 %80, i32* %14
br label %36
81: ; preds = %36
%82 = load double, double* %12
%83 = load i32, i32* %10
%84 = uitofp i32 %83 to double
%85 = fdiv double %82, %84
store double %85, double* %12
%86 = load double, double* %12
%87 = load double*, double** %7
store double %86, double* %87
br label %88
88: ; preds = %81, %19
ret void
}

LLVM IR (-O2):
@.str = [70 x i8] c"Zero elements defined. stat() needs at least one element to examine.\0A\00"
define void @stat(double* nocapture writeonly %0, double* nocapture writeonly %1, double* nocapture writeonly %2, double* nocapture %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @die(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %5
%10 = load double, double* %3
store double %10, double* %0
%11 = load double, double* %3
store double %11, double* %1
%12 = load double, double* %3
store double %12, double* %2
%13 = icmp ugt i32 %4, 1
br i1 %13, label %14, label %65
14: ; preds = %9
%15 = zext i32 %4 to i64
%16 = and i64 %15, 1
%17 = and i64 %15, 4294967294
br label %18
18: ; preds = %44, %14
%19 = phi i64 [ 0, %14 ], [ %45, %44 ]
%20 = phi double [ %11, %14 ], [ %41, %44 ]
%21 = phi i64 [ 0, %14 ], [ %46, %44 ]
%22 = getelementptr inbounds double, double* %3, i64 %19
%23 = load double, double* %22
%24 = fcmp ult double %10, %23
br i1 %24, label %27, label %25
25: ; preds = %18
store double %23, double* %0
%26 = load double, double* %22
br label %27
27: ; preds = %25, %18
%28 = phi double [ %26, %25 ], [ %23, %18 ]
%29 = fadd double %20, %28
%30 = fcmp ugt double %12, %28
br i1 %30, label %32, label %31
31: ; preds = %27
store double %28, double* %2
br label %32
32: ; preds = %27, %31
%33 = or i64 %19, 1
%34 = getelementptr inbounds double, double* %3, i64 %33
%35 = load double, double* %34
%36 = fcmp ult double %10, %35
br i1 %36, label %39, label %37
37: ; preds = %32
store double %35, double* %0
%38 = load double, double* %34
br label %39
39: ; preds = %37, %32
%40 = phi double [ %38, %37 ], [ %35, %32 ]
%41 = fadd double %29, %40
%42 = fcmp ugt double %12, %40
br i1 %42, label %44, label %43
43: ; preds = %39
store double %40, double* %2
br label %44
44: ; preds = %43, %39
%45 = add nuw nsw i64 %19, 2
%46 = add i64 %21, 2
%47 = icmp eq i64 %46, %17
br i1 %47, label %48, label %18
48: ; preds = %44
%49 = icmp eq i64 %16, 0
br i1 %49, label %61, label %50
50: ; preds = %48
%51 = getelementptr inbounds double, double* %3, i64 %45
%52 = load double, double* %51
%53 = fcmp ult double %10, %52
br i1 %53, label %56, label %54
54: ; preds = %50
store double %52, double* %0
%55 = load double, double* %51
br label %56
56: ; preds = %54, %50
%57 = phi double [ %55, %54 ], [ %52, %50 ]
%58 = fadd double %41, %57
%59 = fcmp ugt double %12, %57
br i1 %59, label %61, label %60
60: ; preds = %56
store double %57, double* %2
br label %61
61: ; preds = %56, %60, %48
%62 = phi double [ %41, %48 ], [ %58, %60 ], [ %58, %56 ]
%63 = uitofp i32 %4 to double
%64 = fdiv double %62, %63
store double %64, double* %1
br label %65
65: ; preds = %61, %9
ret void
}