#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*/ doubleSort(int, double *);
double doubleMedian(int count, double *array) {
  double median;
  doubleSort(count, array);
  if ((count & 1) == 1)
    median = array[count >> 1];
  else {
    count >>= 1;
    median = (array[count] + array[count - 1]) * 0.5;
  }
  return median;
}


x86 assembly (clang, -O0):
<doubleMedian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <doubleSort@plt>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    1156 <doubleMedian+0x46>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sar    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    118f <doubleMedian+0x7f>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  0xe7a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubleMedian>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <doubleSort@plt>
mov    %ebp,%eax
sar    %eax
cltq
movsd  (%rbx,%rax,8),%xmm0
test   $0x1,%bpl
jne    113c <doubleMedian+0x2c>
addsd  -0x8(%rbx,%rax,8),%xmm0
mulsd  0xec4(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @doubleMedian(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca double
store i32 %0, i32* %3
store double* %1, double** %4
%6 = load i32, i32* %3
%7 = load double*, double** %4
%8 = call i32 @doubleSort(i32 %6, double* %7)
%9 = load i32, i32* %3
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load double*, double** %4
%14 = load i32, i32* %3
%15 = ashr i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %13, i64 %16
%18 = load double, double* %17
store double %18, double* %5
br label %35
19: ; preds = %2
%20 = load i32, i32* %3
%21 = ashr i32 %20, 1
store i32 %21, i32* %3
%22 = load double*, double** %4
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %4
%28 = load i32, i32* %3
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %27, i64 %30
%32 = load double, double* %31
%33 = fadd double %26, %32
%34 = fmul double %33, 5.000000e-01
store double %34, double* %5
br label %35
35: ; preds = %19, %12
%36 = load double, double* %5
ret double %36
}

LLVM IR (-O2):
define double @doubleMedian(i32 %0, double* %1) {
%3 = tail call i32 @doubleSort(i32 %0, double* %1)
%4 = and i32 %0, 1
%5 = icmp eq i32 %4, 0
%6 = ashr i32 %0, 1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds double, double* %1, i64 %7
%9 = load double, double* %8
br i1 %5, label %10, label %17
10: ; preds = %2
%11 = add nsw i32 %6, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %1, i64 %12
%14 = load double, double* %13
%15 = fadd double %9, %14
%16 = fmul double %15, 5.000000e-01
br label %17
17: ; preds = %2, %10
%18 = phi double [ %16, %10 ], [ %9, %2 ]
ret double %18
}