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


x86 assembly (clang, -O0):
<median_nocopy_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1137 <median_nocopy_int+0x27>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <median_nocopy_int+0xbb>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a6 <median_nocopy_int+0x96>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <quickselect_int@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <quickselect_int@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
jmp    11c5 <median_nocopy_int+0xb5>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <quickselect_int@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<median_nocopy_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1124 <median_nocopy_int+0x14>
mov    (%r14),%eax
jmp    1165 <median_nocopy_int+0x55>
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x1f,%ebp
add    %edi,%ebp
sar    %ebp
test   $0x1,%bl
jne    1170 <median_nocopy_int+0x60>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_int@plt>
mov    %eax,%r15d
add    $0x1,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_int@plt>
add    %r15d,%eax
cvtsi2sd %eax,%xmm0
mulsd  0xe9f(%rip),%xmm0
cvttsd2si %xmm0,%eax
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_int@plt>

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

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