#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 */
int /*<<< orphan*/ qsort(double *, int, int,
                         int (*)(void const *, void const *));
double dqmedian(double *ra, int n) {
  int dqcmp(const void *p1, const void *p2);
  qsort(ra, n, sizeof(double), dqcmp);
  if (n < 2)
    return *ra;
  else
    return n & 1 ? ra[n / 2] : (ra[n / 2 - 1] + ra[n / 2]) / 2.0;
}


x86 assembly (clang, -O0):
<dqmedian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x8,%edx
mov    0x2eb6(%rip),%rcx
call   1030 <qsort@plt>
cmpl   $0x2,-0x14(%rbp)
jge    1153 <dqmedian+0x43>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ed <dqmedian+0xdd>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     118d <dqmedian+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11e3 <dqmedian+0xd3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  0xe26(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dqmedian>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2ec8(%rip),%rcx
mov    $0x8,%edx
call   1030 <qsort@plt>
cmp    $0x1,%ebx
jg     1136 <dqmedian+0x26>
movsd  (%r14),%xmm0
jmp    1161 <dqmedian+0x51>
mov    %ebx,%eax
shr    %ebx
test   $0x1,%al
jne    1159 <dqmedian+0x49>
lea    -0x1(%rbx),%eax
movsd  (%r14,%rax,8),%xmm0
mov    %ebx,%eax
addsd  (%r14,%rax,8),%xmm0
mulsd  0xea9(%rip),%xmm0
jmp    1161 <dqmedian+0x51>
mov    %ebx,%eax
movsd  (%r14,%rax,8),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @dqmedian(double* %0, i32 %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
%6 = load double*, double** %4
%7 = load i32, i32* %5
%8 = call i32 @qsort(double* %6, i32 %7, i32 8, i32 (i8*, i8*)* @dqcmp)
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load double*, double** %4
%13 = load double, double* %12
store double %13, double* %3
br label %43
14: ; preds = %2
%15 = load i32, i32* %5
%16 = and i32 %15, 1
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load double*, double** %4
%20 = load i32, i32* %5
%21 = sdiv i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %19, i64 %22
%24 = load double, double* %23
br label %41
25: ; preds = %14
%26 = load double*, double** %4
%27 = load i32, i32* %5
%28 = sdiv i32 %27, 2
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %26, i64 %30
%32 = load double, double* %31
%33 = load double*, double** %4
%34 = load i32, i32* %5
%35 = sdiv i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %33, i64 %36
%38 = load double, double* %37
%39 = fadd double %32, %38
%40 = fdiv double %39, 2.000000e+00
br label %41
41: ; preds = %25, %18
%42 = phi double [ %24, %18 ], [ %40, %25 ]
store double %42, double* %3
br label %43
43: ; preds = %41, %11
%44 = load double, double* %3
ret double %44
}

LLVM IR (-O2):
define double @dqmedian(double* %0, i32 %1) {
%3 = tail call i32 @qsort(double* %0, i32 %1, i32 8, i32 (i8*, i8*)* @dqcmp)
%4 = icmp slt i32 %1, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load double, double* %0
br label %25
7: ; preds = %2
%8 = and i32 %1, 1
%9 = icmp eq i32 %8, 0
%10 = lshr i32 %1, 1
br i1 %9, label %15, label %11
11: ; preds = %7
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
br label %25
15: ; preds = %7
%16 = add nsw i32 %10, -1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = zext i32 %10 to i64
%21 = getelementptr inbounds double, double* %0, i64 %20
%22 = load double, double* %21
%23 = fadd double %19, %22
%24 = fmul double %23, 5.000000e-01
br label %25
25: ; preds = %11, %15, %5
%26 = phi double [ %6, %5 ], [ %14, %11 ], [ %24, %15 ]
ret double %26
}