#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 */
double fabs(double);
double median_abs(double *x, int n, double *aux) {
  double kthplace(double *, int, int);
  double t;
  register int i;
  for (i = 0; i < n; i++)
    aux[i] = fabs(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_abs>:
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    1169 <median_abs+0x59>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xec6(%rip),%xmm1
pand   %xmm1,%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_abs+0x1a>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe7b(%rip),%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jne    11f5 <median_abs+0xe5>
jp     11f5 <median_abs+0xe5>
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  0xe19(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1216 <median_abs+0x106>
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_abs>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
test   %esi,%esi
jle    128a <median_abs+0x17a>
mov    %r14d,%eax
cmp    $0x4,%r14d
jb     1149 <median_abs+0x39>
lea    (%rdi,%rax,8),%rcx
cmp    %rbx,%rcx
jbe    11e4 <median_abs+0xd4>
lea    (%rbx,%rax,8),%rcx
cmp    %rdi,%rcx
jbe    11e4 <median_abs+0xd4>
xor    %ecx,%ecx
mov    %rcx,%rdx
not    %rdx
add    %rax,%rdx
mov    %rax,%rsi
and    $0x3,%rsi
je     1186 <median_abs+0x76>
movaps 0xe9c(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rdi,%rcx,8),%xmm1
andps  %xmm0,%xmm1
movlps %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rsi
jne    1170 <median_abs+0x60>
cmp    $0x3,%rdx
jb     128a <median_abs+0x17a>
movaps 0xe69(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm1
andps  %xmm0,%xmm1
movlps %xmm1,(%rbx,%rcx,8)
movsd  0x8(%rdi,%rcx,8),%xmm1
andps  %xmm0,%xmm1
movlps %xmm1,0x8(%rbx,%rcx,8)
movsd  0x10(%rdi,%rcx,8),%xmm1
andps  %xmm0,%xmm1
movlps %xmm1,0x10(%rbx,%rcx,8)
movsd  0x18(%rdi,%rcx,8),%xmm1
andps  %xmm0,%xmm1
movlps %xmm1,0x18(%rbx,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%rax
jne    11a0 <median_abs+0x90>
jmp    128a <median_abs+0x17a>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdx
mov    %rdx,%rbp
shr    $0x2,%rbp
add    $0x1,%rbp
test   %rdx,%rdx
je     1306 <median_abs+0x1f6>
mov    %rbp,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
movaps 0xdef(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movups (%rdi,%rdx,8),%xmm1
movups 0x10(%rdi,%rdx,8),%xmm2
andps  %xmm0,%xmm1
andps  %xmm0,%xmm2
movups %xmm1,(%rbx,%rdx,8)
movups %xmm2,0x10(%rbx,%rdx,8)
movups 0x20(%rdi,%rdx,8),%xmm1
movups 0x30(%rdi,%rdx,8),%xmm2
andps  %xmm0,%xmm1
andps  %xmm0,%xmm2
movups %xmm1,0x20(%rbx,%rdx,8)
movups %xmm2,0x30(%rbx,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rsi
jne    1220 <median_abs+0x110>
test   $0x1,%bpl
je     1281 <median_abs+0x171>
movups (%rdi,%rdx,8),%xmm0
movups 0x10(%rdi,%rdx,8),%xmm1
movaps 0xd8e(%rip),%xmm2
andps  %xmm2,%xmm0
andps  %xmm2,%xmm1
movups %xmm0,(%rbx,%rdx,8)
movups %xmm1,0x10(%rbx,%rdx,8)
cmp    %rax,%rcx
jne    114b <median_abs+0x3b>
mov    %r14d,%ebp
shr    $0x1f,%ebp
add    %r14d,%ebp
sar    %ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
mulsd  0xd64(%rip),%xmm1
ucomisd %xmm0,%xmm1
jne    12ee <median_abs+0x1de>
jp     12ee <median_abs+0x1de>
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  0xd2b(%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>
xor    %edx,%edx
test   $0x1,%bpl
jne    1262 <median_abs+0x152>
jmp    1281 <median_abs+0x171>

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

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