void mean_variance(int num, double *record, double *min, double *max,
                   double *med, double *var) {
  double s, sq, meanv, meanq;
  int i;
  *min = 1e9;
  *max = 0;
  s = 0;
  sq = 0;
  for (i = 0; i < 2; i++)
    record[i] = 0;
  sort(record, num);
  for (i = 2; i < num - 2; i++) {
    *min = (record[i] < *min ? record[i] : *min);
    *max = (record[i] > *max ? record[i] : *max);
    s += record[i];
    sq += record[i] * record[i];
  }
  meanv = s / (num - 2 - 2);
  meanq = sq / ((float)num - 2 - 2);
  *var = meanq - ((meanv) * (meanv));
  *med = (record[(int)ceil((float)num / 2) - 1] +
          record[(int)ceil((float)num / 2)]) /
         2;
}


x86 assembly (clang, -O0):
<mean_variance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x2,-0x54(%rbp)
jge    119c <mean_variance+0x7c>
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1174 <mean_variance+0x54>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0x0,%al
call   1040 <sort@plt>
movl   $0x2,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    12af <mean_variance+0x18f>
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f8 <mean_variance+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1205 <mean_variance+0xe5>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
ucomisd (%rax),%xmm0
jbe    1244 <mean_variance+0x124>
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1251 <mean_variance+0x131>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11b1 <mean_variance+0x91>
movsd  -0x38(%rbp),%xmm0
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
sub    $0x2,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
cvtsi2ssl -0x4(%rbp),%xmm1
movss  0xd34(%rip),%xmm2
subss  %xmm2,%xmm1
movss  0xd28(%rip),%xmm2
subss  %xmm2,%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xccc(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <ceil@plt>
mov    -0x80(%rbp),%rax
cvttsd2si %xmm0,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xc92(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
call   1030 <ceil@plt>
mov    -0x78(%rbp),%rax
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
cvttsd2si %xmm1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  0xc5d(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mean_variance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r12d
movabs $0x41cdcd6500000000,%rax
cd cd 41
mov    %rax,(%rdx)
movq   $0x0,(%rcx)
xorpd  %xmm0,%xmm0
movupd %xmm0,(%rsi)
mov    %rsi,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <sort@plt>
xorpd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
cmp    $0x5,%r12d
jl     11ca <mean_variance+0xaa>
lea    -0x2(%r12),%eax
xorpd  %xmm2,%xmm2
mov    $0x2,%ecx
xorpd  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
movsd  (%rbx,%rcx,8),%xmm0
minsd  0x0(%rbp),%xmm0
movsd  %xmm0,0x0(%rbp)
movsd  (%rbx,%rcx,8),%xmm0
maxsd  0x0(%r13),%xmm0
movsd  %xmm0,0x0(%r13)
movsd  (%rbx,%rcx,8),%xmm0
addsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm0,%xmm1
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1190 <mean_variance+0x70>
lea    -0x4(%r12),%eax
cvtsi2sd %eax,%xmm3
xorps  %xmm0,%xmm0
cvtsi2ss %r12d,%xmm0
divsd  %xmm3,%xmm2
movss  0xe19(%rip),%xmm3
movaps %xmm0,%xmm4
addss  %xmm3,%xmm4
addss  %xmm3,%xmm4
xorps  %xmm3,%xmm3
cvtss2sd %xmm4,%xmm3
divsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,(%r15)
mulss  0xdf2(%rip),%xmm0
call   1040 <ceilf@plt>
cvttss2si %xmm0,%eax
cltq
movsd  -0x8(%rbx,%rax,8),%xmm0
addsd  (%rbx,%rax,8),%xmm0
mulsd  0xdd8(%rip),%xmm0
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mean_variance(i32 %0, double* %1, double* %2, double* %3, double* %4, double* %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i32
store i32 %0, i32* %7
store double* %1, double** %8
store double* %2, double** %9
store double* %3, double** %10
store double* %4, double** %11
store double* %5, double** %12
%18 = load double*, double** %9
store double 1.000000e+09, double* %18
%19 = load double*, double** %10
store double 0.000000e+00, double* %19
store double 0.000000e+00, double* %13
store double 0.000000e+00, double* %14
store i32 0, i32* %17
br label %20
20: ; preds = %28, %6
%21 = load i32, i32* %17
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load double*, double** %8
%25 = load i32, i32* %17
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double 0.000000e+00, double* %27
br label %28
28: ; preds = %23
%29 = load i32, i32* %17
%30 = add nsw i32 %29, 1
store i32 %30, i32* %17
br label %20
31: ; preds = %20
%32 = load double*, double** %8
%33 = load i32, i32* %7
%34 = call i32 (double*, i32, ...) bitcast (i32 (...)* @sort to i32 (double*, i32, ...)*)(double* %32, i32 %33)
store i32 2, i32* %17
br label %35
35: ; preds = %100, %31
%36 = load i32, i32* %17
%37 = load i32, i32* %7
%38 = sub nsw i32 %37, 2
%39 = icmp slt i32 %36, %38
br i1 %39, label %40, label %103
40: ; preds = %35
%41 = load double*, double** %8
%42 = load i32, i32* %17
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = load double*, double** %9
%47 = load double, double* %46
%48 = fcmp olt double %45, %47
br i1 %48, label %49, label %55
49: ; preds = %40
%50 = load double*, double** %8
%51 = load i32, i32* %17
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
br label %58
55: ; preds = %40
%56 = load double*, double** %9
%57 = load double, double* %56
br label %58
58: ; preds = %55, %49
%59 = phi double [ %54, %49 ], [ %57, %55 ]
%60 = load double*, double** %9
store double %59, double* %60
%61 = load double*, double** %8
%62 = load i32, i32* %17
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = load double*, double** %10
%67 = load double, double* %66
%68 = fcmp ogt double %65, %67
br i1 %68, label %69, label %75
69: ; preds = %58
%70 = load double*, double** %8
%71 = load i32, i32* %17
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
br label %78
75: ; preds = %58
%76 = load double*, double** %10
%77 = load double, double* %76
br label %78
78: ; preds = %75, %69
%79 = phi double [ %74, %69 ], [ %77, %75 ]
%80 = load double*, double** %10
store double %79, double* %80
%81 = load double*, double** %8
%82 = load i32, i32* %17
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double, double* %81, i64 %83
%85 = load double, double* %84
%86 = load double, double* %13
%87 = fadd double %86, %85
store double %87, double* %13
%88 = load double*, double** %8
%89 = load i32, i32* %17
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds double, double* %88, i64 %90
%92 = load double, double* %91
%93 = load double*, double** %8
%94 = load i32, i32* %17
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds double, double* %93, i64 %95
%97 = load double, double* %96
%98 = load double, double* %14
%99 = call double @llvm.fmuladd.f64(double %92, double %97, double %98)
store double %99, double* %14
br label %100
100: ; preds = %78
%101 = load i32, i32* %17
%102 = add nsw i32 %101, 1
store i32 %102, i32* %17
br label %35
103: ; preds = %35
%104 = load double, double* %13
%105 = load i32, i32* %7
%106 = sub nsw i32 %105, 2
%107 = sub nsw i32 %106, 2
%108 = sitofp i32 %107 to double
%109 = fdiv double %104, %108
store double %109, double* %15
%110 = load double, double* %14
%111 = load i32, i32* %7
%112 = sitofp i32 %111 to float
%113 = fsub float %112, 2.000000e+00
%114 = fsub float %113, 2.000000e+00
%115 = fpext float %114 to double
%116 = fdiv double %110, %115
store double %116, double* %16
%117 = load double, double* %16
%118 = load double, double* %15
%119 = load double, double* %15
%120 = fneg double %118
%121 = call double @llvm.fmuladd.f64(double %120, double %119, double %117)
%122 = load double*, double** %12
store double %121, double* %122
%123 = load double*, double** %8
%124 = load i32, i32* %7
%125 = sitofp i32 %124 to float
%126 = fdiv float %125, 2.000000e+00
%127 = fpext float %126 to double
%128 = call double @llvm.ceil.f64(double %127)
%129 = fptosi double %128 to i32
%130 = sub nsw i32 %129, 1
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds double, double* %123, i64 %131
%133 = load double, double* %132
%134 = load double*, double** %8
%135 = load i32, i32* %7
%136 = sitofp i32 %135 to float
%137 = fdiv float %136, 2.000000e+00
%138 = fpext float %137 to double
%139 = call double @llvm.ceil.f64(double %138)
%140 = fptosi double %139 to i32
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double, double* %134, i64 %141
%143 = load double, double* %142
%144 = fadd double %133, %143
%145 = fdiv double %144, 2.000000e+00
%146 = load double*, double** %11
store double %145, double* %146
ret void
}

LLVM IR (-O2):
define void @mean_variance(i32 %0, double* %1, double* nocapture %2, double* nocapture %3, double* nocapture writeonly %4, double* nocapture writeonly %5) {
%7 = bitcast double* %1 to i8*
store double 1.000000e+09, double* %2
store double 0.000000e+00, double* %3
%8 = tail call i32 (double*, i32, ...) bitcast (i32 (...)* @sort to i32 (double*, i32, ...)*)(double* %1, i32 %0)
%9 = icmp sgt i32 %0, 4
br i1 %9, label %10, label %31
10: ; preds = %6
%11 = add nsw i32 %0, -2
%12 = zext i32 %11 to i64
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 2, %10 ], [ %29, %13 ]
%15 = phi double [ 0.000000e+00, %10 ], [ %27, %13 ]
%16 = phi double [ 0.000000e+00, %10 ], [ %28, %13 ]
%17 = getelementptr inbounds double, double* %1, i64 %14
%18 = load double, double* %17
%19 = load double, double* %2
%20 = fcmp olt double %18, %19
%21 = select i1 %20, double %18, double %19
store double %21, double* %2
%22 = load double, double* %17
%23 = load double, double* %3
%24 = fcmp ogt double %22, %23
%25 = select i1 %24, double %22, double %23
store double %25, double* %3
%26 = load double, double* %17
%27 = fadd double %15, %26
%28 = tail call double @llvm.fmuladd.f64(double %26, double %26, double %16)
%29 = add nuw nsw i64 %14, 1
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %13
31: ; preds = %13, %6
%32 = phi double [ 0.000000e+00, %6 ], [ %28, %13 ]
%33 = phi double [ 0.000000e+00, %6 ], [ %27, %13 ]
%34 = add nsw i32 %0, -4
%35 = sitofp i32 %34 to double
%36 = fdiv double %33, %35
%37 = sitofp i32 %0 to float
%38 = fadd float %37, -2.000000e+00
%39 = fadd float %38, -2.000000e+00
%40 = fpext float %39 to double
%41 = fdiv double %32, %40
%42 = fneg double %36
%43 = tail call double @llvm.fmuladd.f64(double %42, double %36, double %41)
store double %43, double* %5
%44 = fmul float %37, 5.000000e-01
%45 = tail call float @llvm.ceil.f32(float %44)
%46 = fptosi float %45 to i32
%47 = add nsw i32 %46, -1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %1, i64 %48
%50 = load double, double* %49
%51 = sext i32 %46 to i64
%52 = getelementptr inbounds double, double* %1, i64 %51
%53 = load double, double* %52
%54 = fadd double %50, %53
%55 = fmul double %54, 5.000000e-01
store double %55, double* %4
ret void
}