double median(double *x, int n, double *aux) {
  double kthplace(double *, int, int);
  double t;
  register int i;
  for (i = 0; i < n; i++)
    aux[i] = x[i];
  if ((n / 2) == (double)n / 2)
    t = (kthplace(aux, n, n / 2) + kthplace(aux, n, n / 2 + 1)) / 2;
  else
    t = kthplace(aux, n, n / 2 + 1);
  return (t);
}


x86 assembly (clang, -O0):
<median>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    115e <median+0x4e>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112a <median+0x1a>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe86(%rip),%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jne    11ea <median+0xda>
jp     11ea <median+0xda>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1030 <kthplace@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
add    $0x1,%edx
call   1030 <kthplace@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xe24(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120b <median+0xfb>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
add    $0x1,%edx
call   1030 <kthplace@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<median>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
test   %esi,%esi
jle    1295 <median+0x185>
mov    %r14d,%eax
cmp    $0x4,%r14d
jb     1145 <median+0x35>
lea    (%rdi,%rax,8),%rcx
cmp    %rbx,%rcx
jbe    11bc <median+0xac>
lea    (%rbx,%rax,8),%rcx
cmp    %rdi,%rcx
jbe    11bc <median+0xac>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
add    %rax,%rdx
mov    %rax,%rsi
and    $0x3,%rsi
je     1174 <median+0x64>
nopl   0x0(%rax)
movsd  (%rdi,%rcx,8),%xmm0
movsd  %xmm0,(%rbx,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    1160 <median+0x50>
cmp    $0x3,%rdx
jb     1295 <median+0x185>
xchg   %ax,%ax
movsd  (%rdi,%rcx,8),%xmm0
movsd  %xmm0,(%rbx,%rcx,8)
movsd  0x8(%rdi,%rcx,8),%xmm0
movsd  %xmm0,0x8(%rbx,%rcx,8)
movsd  0x10(%rdi,%rcx,8),%xmm0
movsd  %xmm0,0x10(%rbx,%rcx,8)
movsd  0x18(%rdi,%rcx,8),%xmm0
movsd  %xmm0,0x18(%rbx,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%rax
jne    1180 <median+0x70>
jmp    1295 <median+0x185>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdx
mov    %rdx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%r8d
and    $0x3,%r8d
cmp    $0xc,%rdx
jae    11e1 <median+0xd1>
xor    %ebp,%ebp
jmp    1248 <median+0x138>
and    $0xfffffffffffffffc,%rsi
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movups (%rdi,%rbp,8),%xmm0
movups 0x10(%rdi,%rbp,8),%xmm1
movups %xmm0,(%rbx,%rbp,8)
movups %xmm1,0x10(%rbx,%rbp,8)
movups 0x20(%rdi,%rbp,8),%xmm0
movups 0x30(%rdi,%rbp,8),%xmm1
movups %xmm0,0x20(%rbx,%rbp,8)
movups %xmm1,0x30(%rbx,%rbp,8)
movups 0x40(%rdi,%rbp,8),%xmm0
movups 0x50(%rdi,%rbp,8),%xmm1
movups %xmm0,0x40(%rbx,%rbp,8)
movups %xmm1,0x50(%rbx,%rbp,8)
movups 0x60(%rdi,%rbp,8),%xmm0
movups 0x70(%rdi,%rbp,8),%xmm1
movups %xmm0,0x60(%rbx,%rbp,8)
movups %xmm1,0x70(%rbx,%rbp,8)
add    $0x10,%rbp
add    $0xfffffffffffffffc,%rsi
jne    11f0 <median+0xe0>
test   %r8,%r8
je     128c <median+0x17c>
lea    (%rbx,%rbp,8),%rsi
add    $0x10,%rsi
lea    (%rdi,%rbp,8),%rbp
add    $0x10,%rbp
shl    $0x5,%r8
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups -0x10(%rbp,%rdx,1),%xmm0
movups 0x0(%rbp,%rdx,1),%xmm1
movups %xmm0,-0x10(%rsi,%rdx,1)
movups %xmm1,(%rsi,%rdx,1)
add    $0x20,%rdx
cmp    %rdx,%r8
jne    1270 <median+0x160>
cmp    %rax,%rcx
jne    1147 <median+0x37>
mov    %r14d,%ebp
shr    $0x1f,%ebp
add    %r14d,%ebp
sar    %ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
mulsd  0xd49(%rip),%xmm1
ucomisd %xmm0,%xmm1
jne    12f9 <median+0x1e9>
jp     12f9 <median+0x1e9>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <kthplace@plt>
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <kthplace@plt>
addsd  0x8(%rsp),%xmm0
mulsd  0xd10(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <kthplace@plt>

LLVM IR (-O0):
define double @median(double* %0, i32 %1, double* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double*
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double* %2, double** %6
store i32 0, i32* %8
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load double*, double** %4
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %6
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
store double %18, double* %22
br label %23
23: ; preds = %13
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %9
26: ; preds = %9
%27 = load i32, i32* %5
%28 = sdiv i32 %27, 2
%29 = sitofp i32 %28 to double
%30 = load i32, i32* %5
%31 = sitofp i32 %30 to double
%32 = fdiv double %31, 2.000000e+00
%33 = fcmp oeq double %29, %32
br i1 %33, label %34, label %48
34: ; preds = %26
%35 = load double*, double** %6
%36 = load i32, i32* %5
%37 = load i32, i32* %5
%38 = sdiv i32 %37, 2
%39 = call double @kthplace(double* %35, i32 %36, i32 %38)
%40 = load double*, double** %6
%41 = load i32, i32* %5
%42 = load i32, i32* %5
%43 = sdiv i32 %42, 2
%44 = add nsw i32 %43, 1
%45 = call double @kthplace(double* %40, i32 %41, i32 %44)
%46 = fadd double %39, %45
%47 = fdiv double %46, 2.000000e+00
store double %47, double* %7
br label %55
48: ; preds = %26
%49 = load double*, double** %6
%50 = load i32, i32* %5
%51 = load i32, i32* %5
%52 = sdiv i32 %51, 2
%53 = add nsw i32 %52, 1
%54 = call double @kthplace(double* %49, i32 %50, i32 %53)
store double %54, double* %7
br label %55
55: ; preds = %48, %34
%56 = load double, double* %7
ret double %56
}

LLVM IR (-O2):
define double @median(double* nocapture %0, i32 %1, double* %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %130
5: ; preds = %3
%6 = zext i32 %1 to i64
%7 = icmp ult i32 %1, 4
br i1 %7, label %93, label %8
8: ; preds = %5
%9 = getelementptr double, double* %2, i64 %6
%10 = getelementptr double, double* %0, i64 %6
%11 = icmp ugt double* %10, %2
%12 = icmp ugt double* %9, %0
%13 = and i1 %11, %12
br i1 %13, label %93, label %14
14: ; preds = %8
%15 = and i64 %6, 4294967292
%16 = add nsw i64 %15, -4
%17 = lshr exact i64 %16, 2
%18 = add nuw nsw i64 %17, 1
%19 = and i64 %18, 3
%20 = icmp ult i64 %16, 12
br i1 %20, label %72, label %21
21: ; preds = %14
%22 = and i64 %18, 9223372036854775804
br label %23
23: ; preds = %23, %21
%24 = phi i64 [ 0, %21 ], [ %69, %23 ]
%25 = phi i64 [ 0, %21 ], [ %70, %23 ]
%26 = getelementptr inbounds double, double* %0, i64 %24
%27 = bitcast double* %26 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = getelementptr inbounds double, double* %26, i64 2
%30 = bitcast double* %29 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = getelementptr inbounds double, double* %2, i64 %24
%33 = bitcast double* %32 to <2 x double>*
store <2 x double> %28, <2 x double>* %33
%34 = getelementptr inbounds double, double* %32, i64 2
%35 = bitcast double* %34 to <2 x double>*
store <2 x double> %31, <2 x double>* %35
%36 = or i64 %24, 4
%37 = getelementptr inbounds double, double* %0, i64 %36
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = getelementptr inbounds double, double* %37, i64 2
%41 = bitcast double* %40 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = getelementptr inbounds double, double* %2, i64 %36
%44 = bitcast double* %43 to <2 x double>*
store <2 x double> %39, <2 x double>* %44
%45 = getelementptr inbounds double, double* %43, i64 2
%46 = bitcast double* %45 to <2 x double>*
store <2 x double> %42, <2 x double>* %46
%47 = or i64 %24, 8
%48 = getelementptr inbounds double, double* %0, i64 %47
%49 = bitcast double* %48 to <2 x double>*
%50 = load <2 x double>, <2 x double>* %49
%51 = getelementptr inbounds double, double* %48, i64 2
%52 = bitcast double* %51 to <2 x double>*
%53 = load <2 x double>, <2 x double>* %52
%54 = getelementptr inbounds double, double* %2, i64 %47
%55 = bitcast double* %54 to <2 x double>*
store <2 x double> %50, <2 x double>* %55
%56 = getelementptr inbounds double, double* %54, i64 2
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %53, <2 x double>* %57
%58 = or i64 %24, 12
%59 = getelementptr inbounds double, double* %0, i64 %58
%60 = bitcast double* %59 to <2 x double>*
%61 = load <2 x double>, <2 x double>* %60
%62 = getelementptr inbounds double, double* %59, i64 2
%63 = bitcast double* %62 to <2 x double>*
%64 = load <2 x double>, <2 x double>* %63
%65 = getelementptr inbounds double, double* %2, i64 %58
%66 = bitcast double* %65 to <2 x double>*
store <2 x double> %61, <2 x double>* %66
%67 = getelementptr inbounds double, double* %65, i64 2
%68 = bitcast double* %67 to <2 x double>*
store <2 x double> %64, <2 x double>* %68
%69 = add nuw i64 %24, 16
%70 = add nuw i64 %25, 4
%71 = icmp eq i64 %70, %22
br i1 %71, label %72, label %23
72: ; preds = %23, %14
%73 = phi i64 [ 0, %14 ], [ %69, %23 ]
%74 = icmp eq i64 %19, 0
br i1 %74, label %91, label %75
75: ; preds = %72, %75
%76 = phi i64 [ %88, %75 ], [ %73, %72 ]
%77 = phi i64 [ %89, %75 ], [ 0, %72 ]
%78 = getelementptr inbounds double, double* %0, i64 %76
%79 = bitcast double* %78 to <2 x double>*
%80 = load <2 x double>, <2 x double>* %79
%81 = getelementptr inbounds double, double* %78, i64 2
%82 = bitcast double* %81 to <2 x double>*
%83 = load <2 x double>, <2 x double>* %82
%84 = getelementptr inbounds double, double* %2, i64 %76
%85 = bitcast double* %84 to <2 x double>*
store <2 x double> %80, <2 x double>* %85
%86 = getelementptr inbounds double, double* %84, i64 2
%87 = bitcast double* %86 to <2 x double>*
store <2 x double> %83, <2 x double>* %87
%88 = add nuw i64 %76, 4
%89 = add i64 %77, 1
%90 = icmp eq i64 %89, %19
br i1 %90, label %91, label %75
91: ; preds = %75, %72
%92 = icmp eq i64 %15, %6
br i1 %92, label %130, label %93
93: ; preds = %8, %5, %91
%94 = phi i64 [ 0, %8 ], [ 0, %5 ], [ %15, %91 ]
%95 = xor i64 %94, -1
%96 = add nsw i64 %95, %6
%97 = and i64 %6, 3
%98 = icmp eq i64 %97, 0
br i1 %98, label %108, label %99
99: ; preds = %93, %99
%100 = phi i64 [ %105, %99 ], [ %94, %93 ]
%101 = phi i64 [ %106, %99 ], [ 0, %93 ]
%102 = getelementptr inbounds double, double* %0, i64 %100
%103 = load double, double* %102
%104 = getelementptr inbounds double, double* %2, i64 %100
store double %103, double* %104
%105 = add nuw nsw i64 %100, 1
%106 = add i64 %101, 1
%107 = icmp eq i64 %106, %97
br i1 %107, label %108, label %99
108: ; preds = %99, %93
%109 = phi i64 [ %94, %93 ], [ %105, %99 ]
%110 = icmp ult i64 %96, 3
br i1 %110, label %130, label %111
111: ; preds = %108, %111
%112 = phi i64 [ %128, %111 ], [ %109, %108 ]
%113 = getelementptr inbounds double, double* %0, i64 %112
%114 = load double, double* %113
%115 = getelementptr inbounds double, double* %2, i64 %112
store double %114, double* %115
%116 = add nuw nsw i64 %112, 1
%117 = getelementptr inbounds double, double* %0, i64 %116
%118 = load double, double* %117
%119 = getelementptr inbounds double, double* %2, i64 %116
store double %118, double* %119
%120 = add nuw nsw i64 %112, 2
%121 = getelementptr inbounds double, double* %0, i64 %120
%122 = load double, double* %121
%123 = getelementptr inbounds double, double* %2, i64 %120
store double %122, double* %123
%124 = add nuw nsw i64 %112, 3
%125 = getelementptr inbounds double, double* %0, i64 %124
%126 = load double, double* %125
%127 = getelementptr inbounds double, double* %2, i64 %124
store double %126, double* %127
%128 = add nuw nsw i64 %112, 4
%129 = icmp eq i64 %128, %6
br i1 %129, label %130, label %111
130: ; preds = %108, %111, %91, %3
%131 = sdiv i32 %1, 2
%132 = sitofp i32 %131 to double
%133 = sitofp i32 %1 to double
%134 = fmul double %133, 5.000000e-01
%135 = fcmp oeq double %134, %132
br i1 %135, label %136, label %142
136: ; preds = %130
%137 = tail call double @kthplace(double* %2, i32 %1, i32 %131)
%138 = add nsw i32 %131, 1
%139 = tail call double @kthplace(double* %2, i32 %1, i32 %138)
%140 = fadd double %137, %139
%141 = fmul double %140, 5.000000e-01
br label %145
142: ; preds = %130
%143 = add nsw i32 %131, 1
%144 = tail call double @kthplace(double* %2, i32 %1, i32 %143)
br label %145
145: ; preds = %142, %136
%146 = phi double [ %141, %136 ], [ %144, %142 ]
ret double %146
}