unsigned long long *ave_max_min_cpu(unsigned long long cpucycles[],
                                    int length) {
  static unsigned long long result[3];
  result[0] = 0;
  result[1] = 0;
  result[2] = 1000000000;
  for (int i = 0; i < length; i++) {
    result[0] = result[0] + cpucycles[i];
    if (result[1] <= cpucycles[i])
      result[1] = cpucycles[i];
    if (result[2] >= cpucycles[i])
      result[2] = cpucycles[i];
  }
  result[0] = result[0] / length;
  return result;
}


x86 assembly (clang, -O0):
<ave_max_min_cpu>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,0x2f1a(%rip)
movq   $0x0,0x2f17(%rip)
movq   $0x3b9aca00,0x2f14(%rip)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c4 <ave_max_min_cpu+0xc4>
mov    0x2eea(%rip),%rax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
add    (%rcx,%rdx,8),%rax
mov    %rax,0x2ed7(%rip)
mov    0x2ed8(%rip),%rax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
ja     1185 <ave_max_min_cpu+0x85>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,0x2eb3(%rip)
mov    0x2eb4(%rip),%rax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
jb     11b1 <ave_max_min_cpu+0xb1>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,0x2e8f(%rip)
jmp    11b6 <ave_max_min_cpu+0xb6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1133 <ave_max_min_cpu+0x33>
mov    0x2e65(%rip),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,0x2e55(%rip)
lea    0x2e4e(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ave_max_min_cpu>:
xorps  %xmm0,%xmm0
movaps %xmm0,0x2f26(%rip)
movq   $0x3b9aca00,0x2f2b(%rip)
test   %esi,%esi
jle    117f <ave_max_min_cpu+0x7f>
mov    %esi,%r8d
mov    $0x3b9aca00,%r9d
xor    %r10d,%r10d
xor    %eax,%eax
xor    %edx,%edx
jmp    1139 <ave_max_min_cpu+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    %rdx,%r8
je     1181 <ave_max_min_cpu+0x81>
add    (%rdi,%rdx,8),%rax
mov    %rax,0x2eec(%rip)
mov    (%rdi,%rdx,8),%rcx
cmp    %rcx,%r10
jbe    1160 <ave_max_min_cpu+0x60>
mov    %rcx,%r11
cmp    %r11,%r9
jb     1130 <ave_max_min_cpu+0x30>
jmp    1173 <ave_max_min_cpu+0x73>
nopw   0x0(%rax,%rax,1)
mov    %rcx,0x2ed1(%rip)
mov    (%rdi,%rdx,8),%r11
mov    %rcx,%r10
cmp    %r11,%r9
jb     1130 <ave_max_min_cpu+0x30>
mov    %r11,0x2ec6(%rip)
mov    %r11,%r9
jmp    1130 <ave_max_min_cpu+0x30>
xor    %eax,%eax
movslq %esi,%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1197 <ave_max_min_cpu+0x97>
xor    %edx,%edx
div    %rcx
jmp    119b <ave_max_min_cpu+0x9b>
xor    %edx,%edx
div    %esi
mov    %rax,0x2e8e(%rip)
lea    0x2e87(%rip),%rax
ret

LLVM IR (-O0):
@ave_max_min_cpu.result = internal global [3 x i64] zeroinitializer
define i64* @ave_max_min_cpu(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i32
store i64* %0, i64** %3
store i32 %1, i32* %4
store i64 0, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
store i64 0, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 1)
store i64 1000000000, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 2)
store i32 0, i32* %5
br label %6
6: ; preds = %46, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %49
10: ; preds = %6
%11 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
%12 = load i64*, i64** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i64, i64* %12, i64 %14
%16 = load i64, i64* %15
%17 = add i64 %11, %16
store i64 %17, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
%18 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 1)
%19 = load i64*, i64** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i64, i64* %19, i64 %21
%23 = load i64, i64* %22
%24 = icmp ule i64 %18, %23
br i1 %24, label %25, label %31
25: ; preds = %10
%26 = load i64*, i64** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i64, i64* %26, i64 %28
%30 = load i64, i64* %29
store i64 %30, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 1)
br label %31
31: ; preds = %25, %10
%32 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 2)
%33 = load i64*, i64** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i64, i64* %33, i64 %35
%37 = load i64, i64* %36
%38 = icmp uge i64 %32, %37
br i1 %38, label %39, label %45
39: ; preds = %31
%40 = load i64*, i64** %3
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i64, i64* %40, i64 %42
%44 = load i64, i64* %43
store i64 %44, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 2)
br label %45
45: ; preds = %39, %31
br label %46
46: ; preds = %45
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %6
49: ; preds = %6
%50 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = udiv i64 %50, %52
store i64 %53, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
ret i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
}

LLVM IR (-O2):
@ave_max_min_cpu.result = internal global [3 x i64] zeroinitializer
define i64* @ave_max_min_cpu(i64* nocapture %0, i32 %1) {
store i64 1000000000, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 2)
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %10
6: ; preds = %27, %2
%7 = phi i64 [ 0, %2 ], [ %17, %27 ]
%8 = sext i32 %1 to i64
%9 = udiv i64 %7, %8
store i64 %9, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
ret i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
10: ; preds = %4, %27
%11 = phi i64 [ 1000000000, %4 ], [ %28, %27 ]
%12 = phi i64 [ 0, %4 ], [ %24, %27 ]
%13 = phi i64 [ 0, %4 ], [ %17, %27 ]
%14 = phi i64 [ 0, %4 ], [ %29, %27 ]
%15 = getelementptr inbounds i64, i64* %0, i64 %14
%16 = load i64, i64* %15
%17 = add i64 %16, %13
store i64 %17, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 0)
%18 = load i64, i64* %15
%19 = icmp ugt i64 %12, %18
br i1 %19, label %22, label %20
20: ; preds = %10
store i64 %18, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 1)
%21 = load i64, i64* %15
br label %22
22: ; preds = %20, %10
%23 = phi i64 [ %21, %20 ], [ %18, %10 ]
%24 = phi i64 [ %18, %20 ], [ %12, %10 ]
%25 = icmp ult i64 %11, %23
br i1 %25, label %27, label %26
26: ; preds = %22
store i64 %23, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @ave_max_min_cpu.result, i64 0, i64 2)
br label %27
27: ; preds = %22, %26
%28 = phi i64 [ %11, %22 ], [ %23, %26 ]
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %5
br i1 %30, label %6, label %10
}