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


x86 assembly (clang, -O0):
<median_nocopy_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1139 <median_nocopy_short+0x29>
mov    -0x10(%rbp),%rax
mov    (%rax),%ax
mov    %ax,-0x2(%rbp)
jmp    11d8 <median_nocopy_short+0xc8>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b0 <median_nocopy_short+0xa0>
mov    -0x8(%rbp),%esi
mov    %esi,%eax
shr    $0x1f,%eax
mov    %esi,%edi
add    %eax,%edi
sar    %edi
mov    -0x10(%rbp),%rdx
call   1030 <quickselect_short@plt>
mov    %ax,-0x12(%rbp)
mov    -0x8(%rbp),%esi
mov    %esi,%eax
shr    $0x1f,%eax
mov    %esi,%edi
add    %eax,%edi
sar    %edi
add    $0x1,%edi
mov    -0x10(%rbp),%rdx
call   1030 <quickselect_short@plt>
mov    %ax,%cx
movzwl -0x12(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x12(%rbp)
movswl -0x12(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe61(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,-0x12(%rbp)
jmp    11d0 <median_nocopy_short+0xc0>
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_short@plt>
mov    %ax,-0x12(%rbp)
mov    -0x12(%rbp),%ax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<median_nocopy_short>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1125 <median_nocopy_short+0x15>
movzwl (%r14),%eax
jmp    1167 <median_nocopy_short+0x57>
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x1f,%ebp
add    %edi,%ebp
sar    %ebp
test   $0x1,%bl
jne    1172 <median_nocopy_short+0x62>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_short@plt>
mov    %eax,%r15d
add    $0x1,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <quickselect_short@plt>
add    %r15d,%eax
cwtl
cvtsi2sd %eax,%xmm0
mulsd  0xe9d(%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_short@plt>

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

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