double *ave_max_min(double time[], int length) {
  static double result_time[3];
  result_time[0] = 0;
  result_time[1] = 0;
  result_time[2] = 10000000;
  for (int i = 0; i < length; i++) {
    result_time[0] = result_time[0] + time[i];
    if (result_time[1] <= time[i])
      result_time[1] = time[i];
    if (result_time[2] >= time[i])
      result_time[2] = time[i];
  }
  result_time[0] = result_time[0] / (double)length;
  return result_time;
}


x86 assembly (clang, -O0):
<ave_max_min>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2f1a(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2f17(%rip)
movsd  0xed7(%rip),%xmm0
movsd  %xmm0,0x2f0f(%rip)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d8 <ave_max_min+0xd8>
movsd  0x2ee4(%rip),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,0x2ecf(%rip)
movsd  0x2ecf(%rip),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     1195 <ave_max_min+0x95>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,0x2ea3(%rip)
movsd  0x2ea3(%rip),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jb     11c5 <ave_max_min+0xc5>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,0x2e7b(%rip)
jmp    11ca <ave_max_min+0xca>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <ave_max_min+0x38>
movsd  0x2e50(%rip),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2e3f(%rip)
lea    0x2e38(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ave_max_min>:
xorpd  %xmm0,%xmm0
movapd %xmm0,0x2f24(%rip)
movabs $0x416312d000000000,%rax
12 63 41
mov    %rax,0x2f23(%rip)
test   %esi,%esi
jle    1195 <ave_max_min+0x95>
mov    %esi,%eax
xorpd  %xmm2,%xmm2
movsd  0xed1(%rip),%xmm1
xor    %ecx,%ecx
xorpd  %xmm0,%xmm0
jmp    1149 <ave_max_min+0x49>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %rcx,%rax
je     1199 <ave_max_min+0x99>
addsd  (%rdi,%rcx,8),%xmm0
movsd  %xmm0,0x2eda(%rip)
movsd  (%rdi,%rcx,8),%xmm4
ucomisd %xmm2,%xmm4
jae    1170 <ave_max_min+0x70>
movapd %xmm4,%xmm3
ucomisd %xmm3,%xmm1
jb     1140 <ave_max_min+0x40>
jmp    1187 <ave_max_min+0x87>
nopl   (%rax)
movsd  %xmm4,0x2ec0(%rip)
movsd  (%rdi,%rcx,8),%xmm3
movapd %xmm4,%xmm2
ucomisd %xmm3,%xmm1
jb     1140 <ave_max_min+0x40>
movsd  %xmm3,0x2eb1(%rip)
movapd %xmm3,%xmm1
jmp    1140 <ave_max_min+0x40>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %esi,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x2e84(%rip)
lea    0x2e7d(%rip),%rax
ret

LLVM IR (-O0):
@ave_max_min.result_time = internal global [3 x double] zeroinitializer
define double* @ave_max_min(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
store double 0.000000e+00, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 1)
store double 1.000000e+07, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, 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 double, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
%12 = load double*, double** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %12, i64 %14
%16 = load double, double* %15
%17 = fadd double %11, %16
store double %17, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
%18 = load double, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 1)
%19 = load double*, double** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fcmp ole double %18, %23
br i1 %24, label %25, label %31
25: ; preds = %10
%26 = load double*, double** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
store double %30, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 1)
br label %31
31: ; preds = %25, %10
%32 = load double, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 2)
%33 = load double*, double** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = fcmp oge double %32, %37
br i1 %38, label %39, label %45
39: ; preds = %31
%40 = load double*, double** %3
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
store double %44, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, 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 double, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
%51 = load i32, i32* %4
%52 = sitofp i32 %51 to double
%53 = fdiv double %50, %52
store double %53, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
ret double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
}

LLVM IR (-O2):
@ave_max_min.result_time = internal global [3 x double] zeroinitializer
define double* @ave_max_min(double* nocapture %0, i32 %1) {
store double 1.000000e+07, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, 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 double [ 0.000000e+00, %2 ], [ %17, %27 ]
%8 = sitofp i32 %1 to double
%9 = fdiv double %7, %8
store double %9, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
ret double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
10: ; preds = %4, %27
%11 = phi double [ 1.000000e+07, %4 ], [ %28, %27 ]
%12 = phi double [ 0.000000e+00, %4 ], [ %24, %27 ]
%13 = phi double [ 0.000000e+00, %4 ], [ %17, %27 ]
%14 = phi i64 [ 0, %4 ], [ %29, %27 ]
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = fadd double %13, %16
store double %17, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 0)
%18 = load double, double* %15
%19 = fcmp ugt double %12, %18
br i1 %19, label %22, label %20
20: ; preds = %10
store double %18, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 1)
%21 = load double, double* %15
br label %22
22: ; preds = %20, %10
%23 = phi double [ %21, %20 ], [ %18, %10 ]
%24 = phi double [ %18, %20 ], [ %12, %10 ]
%25 = fcmp ult double %11, %23
br i1 %25, label %27, label %26
26: ; preds = %22
store double %23, double* getelementptr inbounds ([3 x double], [3 x double]* @ave_max_min.result_time, i64 0, i64 2)
br label %27
27: ; preds = %22, %26
%28 = phi double [ %11, %22 ], [ %23, %26 ]
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %5
br i1 %30, label %6, label %10
}