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


x86 assembly (clang, -O0):
<median_nocopy_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1139 <median_nocopy_long+0x29>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11d6 <median_nocopy_long+0xc6>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ae <median_nocopy_long+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_long@plt>
mov    %rax,-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_long@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xe64(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
jmp    11ce <median_nocopy_long+0xbe>
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_long@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<median_nocopy_long>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1124 <median_nocopy_long+0x14>
mov    (%r14),%rax
jmp    1167 <median_nocopy_long+0x57>
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x1f,%ebp
add    %edi,%ebp
sar    %ebp
test   $0x1,%bl
jne    1172 <median_nocopy_long+0x62>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_long@plt>
mov    %rax,%r15
add    $0x1,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_long@plt>
add    %r15,%rax
cvtsi2sd %rax,%xmm0
mulsd  0xe9e(%rip),%xmm0
cvttsd2si %xmm0,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <quickselect_long@plt>

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

LLVM IR (-O2):
define i64 @median_nocopy_long(i32 %0, i64* %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i64, i64* %1
br label %21
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 %18
10: ; preds = %6
%11 = tail call i64 @quickselect_long(i32 %9, i32 %0, i64* %1)
%12 = add nsw i32 %9, 1
%13 = tail call i64 @quickselect_long(i32 %12, i32 %0, i64* %1)
%14 = add nsw i64 %13, %11
%15 = sitofp i64 %14 to double
%16 = fmul double %15, 5.000000e-01
%17 = fptosi double %16 to i64
br label %21
18: ; preds = %6
%19 = add nsw i32 %9, 1
%20 = tail call i64 @quickselect_long(i32 %19, i32 %0, i64* %1)
br label %21
21: ; preds = %10, %18, %4
%22 = phi i64 [ %5, %4 ], [ %17, %10 ], [ %20, %18 ]
ret i64 %22
}