#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 pick_by_sort(int *, int /*<<< orphan*/, int, int);
int select(int *, int, int);
int pick(int *x, int len, int n) {
  if (n < 1 || n > len)
    return (-1);
  if (n < 8)
    return (select(x, len, n));
  return (pick_by_sort(x, 0, len - 1, n));
}


x86 assembly (clang, -O0):
<pick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jl     1148 <pick+0x28>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1154 <pick+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    118c <pick+0x6c>
cmpl   $0x8,-0x18(%rbp)
jge    1175 <pick+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <select@plt>
mov    %eax,-0x4(%rbp)
jmp    118c <pick+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%ecx
xor    %esi,%esi
call   1030 <pick_by_sort@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pick>:
mov    %edx,%ecx
test   %edx,%edx
jle    113a <pick+0x1a>
mov    %esi,%edx
cmp    %esi,%ecx
jg     113a <pick+0x1a>
cmp    $0x7,%ecx
ja     1140 <pick+0x20>
mov    %edx,%esi
mov    %ecx,%edx
jmp    1040 <select@plt>
mov    $0xffffffff,%eax
ret
add    $0xffffffff,%edx
xor    %esi,%esi
jmp    1030 <pick_by_sort@plt>

LLVM IR (-O0):
define i32 @pick(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp slt i32 %8, 1
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp sgt i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10, %3
store i32 -1, i32* %4
br label %29
15: ; preds = %10
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 8
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = call i32 @select(i32* %19, i32 %20, i32 %21)
store i32 %22, i32* %4
br label %29
23: ; preds = %15
%24 = load i32*, i32** %5
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = load i32, i32* %7
%28 = call i32 @pick_by_sort(i32* %24, i32 0, i32 %26, i32 %27)
store i32 %28, i32* %4
br label %29
29: ; preds = %23, %18, %14
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @pick(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 1
%5 = icmp sgt i32 %2, %1
%6 = or i1 %4, %5
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = icmp ult i32 %2, 8
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @select(i32* %0, i32 %1, i32 %2)
br label %14
11: ; preds = %7
%12 = add nsw i32 %1, -1
%13 = tail call i32 @pick_by_sort(i32* %0, i32 0, i32 %12, i32 %2)
br label %14
14: ; preds = %3, %11, %9
%15 = phi i32 [ %10, %9 ], [ %13, %11 ], [ -1, %3 ]
ret i32 %15
}