#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 quickselect_double(int, int, double *);
double median_nocopy_double(int n, double *data) {
  double temp;
  if (n == 1)
    return (data[0]);
  if (n % 2 == 0) {
    temp = quickselect_double((n / 2), n, data);
    temp += quickselect_double((n / 2) + 1, n, data);
    temp = temp / 2.0;
  } else {
    temp = quickselect_double((n / 2) + 1, n, data);
  }
  return (temp);
}


x86 assembly (clang, -O0):
<median_nocopy_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    113b <median_nocopy_double+0x2b>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <median_nocopy_double+0xc9>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ae <median_nocopy_double+0x9e>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <quickselect_double@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <quickselect_double@plt>
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe60(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11cf <median_nocopy_double+0xbf>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <quickselect_double@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<median_nocopy_double>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1127 <median_nocopy_double+0x17>
movsd  (%r14),%xmm0
jmp    1166 <median_nocopy_double+0x56>
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x1f,%ebp
add    %edi,%ebp
sar    %ebp
test   $0x1,%bl
jne    116f <median_nocopy_double+0x5f>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_double@plt>
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_double@plt>
addsd  0x8(%rsp),%xmm0
mulsd  0xe9a(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
add    $0x1,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <quickselect_double@plt>

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

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