#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*/ sortDoubleArray(double *, int);
double median(double *array, int n) {
  sortDoubleArray(array, n);
  if (n % 2) {
    return (array[n / 2] + array[n / 2 + 1]) * 0.5;
  } else {
    return (array[n / 2 + 1]);
  }
}


x86 assembly (clang, -O0):
<median>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <sortDoubleArray@plt>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     119a <median+0x8a>
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
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  0xe74(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c3 <median+0xb3>
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
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<median>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <sortDoubleArray@plt>
mov    %ebp,%eax
shr    $0x1f,%eax
add    %ebp,%eax
sar    %eax
cltq
test   $0x1,%bpl
jne    1136 <median+0x26>
movsd  0x8(%rbx,%rax,8),%xmm0
jmp    1149 <median+0x39>
movsd  (%rbx,%rax,8),%xmm0
addsd  0x8(%rbx,%rax,8),%xmm0
mulsd  0xeb7(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @median(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 @sortDoubleArray(double* %6, i32 %7)
%9 = load i32, i32* %5
%10 = srem i32 %9, 2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %2
%13 = load double*, double** %4
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %13, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %4
%20 = load i32, i32* %5
%21 = sdiv i32 %20, 2
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %19, i64 %23
%25 = load double, double* %24
%26 = fadd double %18, %25
%27 = fmul double %26, 5.000000e-01
store double %27, double* %3
br label %36
28: ; preds = %2
%29 = load double*, double** %4
%30 = load i32, i32* %5
%31 = sdiv i32 %30, 2
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %29, i64 %33
%35 = load double, double* %34
store double %35, double* %3
br label %36
36: ; preds = %28, %12
%37 = load double, double* %3
ret double %37
}

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