#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*/ intSort(int, int *);
int intMedian(int count, int *array) {
  int median;
  intSort(count, array);
  if ((count & 1) == 1)
    median = array[count >> 1];
  else {
    count >>= 1;
    median = (array[count] + array[count - 1]) * 0.5;
  }
  return median;
}


x86 assembly (clang, -O0):
<intMedian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <intSort@plt>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    1152 <intMedian+0x42>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sar    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
jmp    118d <intMedian+0x7d>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
mov    -0x4(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
add    (%rcx,%rdx,4),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe7e(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intMedian>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <intSort@plt>
mov    %ebp,%eax
sar    %eax
movslq %eax,%rcx
mov    (%rbx,%rcx,4),%eax
test   $0x1,%bpl
jne    1141 <intMedian+0x31>
add    -0x4(%rbx,%rcx,4),%eax
cvtsi2sd %eax,%xmm0
mulsd  0xec3(%rip),%xmm0
cvttsd2si %xmm0,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @intMedian(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%6 = load i32, i32* %3
%7 = load i32*, i32** %4
%8 = call i32 @intSort(i32 %6, i32* %7)
%9 = load i32, i32* %3
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32*, i32** %4
%14 = load i32, i32* %3
%15 = ashr i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %13, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %5
br label %37
19: ; preds = %2
%20 = load i32, i32* %3
%21 = ashr i32 %20, 1
store i32 %21, i32* %3
%22 = load i32*, i32** %4
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = load i32*, i32** %4
%28 = load i32, i32* %3
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %27, i64 %30
%32 = load i32, i32* %31
%33 = add nsw i32 %26, %32
%34 = sitofp i32 %33 to double
%35 = fmul double %34, 5.000000e-01
%36 = fptosi double %35 to i32
store i32 %36, i32* %5
br label %37
37: ; preds = %19, %12
%38 = load i32, i32* %5
ret i32 %38
}

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