#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 selectKth(void **, int (*)(void const *, void const *), int, int, int);
void mediansort(void **ar, int (*cmp)(const void *, const void *), int left,
                int right) {
  int me, mid;
  if (right <= left) {
    return;
  }
  mid = (right - left + 1) / 2;
  me = selectKth(ar, cmp, mid + 1, left, right);
  mediansort(ar, cmp, left, left + mid - 1);
  mediansort(ar, cmp, left + mid + 1, right);
}


x86 assembly (clang, -O0):
<mediansort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1147 <mediansort+0x27>
jmp    11aa <mediansort+0x8a>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <selectKth@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    -0x20(%rbp),%ecx
sub    $0x1,%ecx
call   1040 <mediansort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1040 <mediansort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mediansort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%ecx
jle    117e <mediansort+0x5e>
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x1(%r14),%r13d
xchg   %ax,%ax
mov    %r13d,%eax
sub    %ebx,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    0x1(%rbp),%edx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%ecx
mov    %r14d,%r8d
call   1030 <selectKth@plt>
lea    (%rbx,%rbp,1),%ecx
add    $0xffffffff,%ecx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <mediansort@plt>
add    %ebp,%ebx
add    $0x1,%ebx
cmp    %r14d,%ebx
jl     1140 <mediansort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @mediansort(i8** %0, i32 (i8*, i8*)* %1, i32 %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32 (i8*, i8*)*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %5
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = load i32, i32* %7
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %4
br label %42
15: ; preds = %4
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = sub nsw i32 %16, %17
%19 = add nsw i32 %18, 1
%20 = sdiv i32 %19, 2
store i32 %20, i32* %10
%21 = load i8**, i8*** %5
%22 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = call i32 @selectKth(i8** %21, i32 (i8*, i8*)* %22, i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %9
%28 = load i8**, i8*** %5
%29 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%30 = load i32, i32* %7
%31 = load i32, i32* %7
%32 = load i32, i32* %10
%33 = add nsw i32 %31, %32
%34 = sub nsw i32 %33, 1
%35 = load i8**, i8*** %5
%36 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%37 = load i32, i32* %7
%38 = load i32, i32* %10
%39 = add nsw i32 %37, %38
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %8
br label %42
42: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
define void @mediansort(i8** %0, i32 (i8*, i8*)* %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, %2
br i1 %5, label %6, label %18
6: ; preds = %4
%7 = add i32 %3, 1
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ %2, %6 ], [ %16, %8 ]
%10 = sub i32 %7, %9
%11 = sdiv i32 %10, 2
%12 = add nsw i32 %11, 1
%13 = tail call i32 @selectKth(i8** %0, i32 (i8*, i8*)* %1, i32 %12, i32 %9, i32 %3)
%14 = add nsw i32 %11, %9
%15 = add nsw i32 %14, -1
tail call void @mediansort(i8** %0, i32 (i8*, i8*)* %1, i32 %9, i32 %15)
%16 = add nsw i32 %14, 1
%17 = icmp slt i32 %16, %3
br i1 %17, label %8, label %18
18: ; preds = %8, %4
ret void
}