#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int rselect(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int size_of_problem, nth;
  scanf("%d", &size_of_problem);
  scanf("%d", &nth);
  int *numbers_to_select = (int *)malloc(size_of_problem * sizeof(int));
  for (int i = 0; i < size_of_problem; i++) {
    scanf("%d", &numbers_to_select[i]);
  }
  printf("%d", rselect(numbers_to_select, 0, size_of_problem - 1, nth));
  free(numbers_to_select);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe6a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
lea    0xe5a(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fe <main+0x8e>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe15(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c9 <main+0x59>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
mov    -0xc(%rbp),%ecx
xor    %esi,%esi
call   1090 <rselect@plt>
mov    %eax,%esi
lea    0xde5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe73(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    (%rsp),%edx
test   %edx,%edx
jle    11ec <main+0x7c>
xor    %r12d,%r12d
lea    0xe3c(%rip),%r15
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x1,%r12
movslq (%rsp),%rdx
add    $0x4,%rbx
cmp    %rdx,%r12
jl     11d0 <main+0x60>
add    $0xffffffff,%edx
mov    0x4(%rsp),%ecx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <rselect@plt>
lea    0xdfc(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %4
store i32 0, i32* %5
br label %16
16: ; preds = %26, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %24)
br label %26
26: ; preds = %20
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %16
29: ; preds = %16
%30 = load i32*, i32** %4
%31 = load i32, i32* %2
%32 = sub nsw i32 %31, 1
%33 = load i32, i32* %3
%34 = call i32 @rselect(i32* %30, i32 0, i32 %32, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32*, i32** %4
%37 = call i32 @free(i32* %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = shl i32 %9, 2
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i32*
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %22, %0
%16 = phi i32 [ %13, %0 ], [ %27, %22 ]
%17 = add nsw i32 %16, -1
%18 = load i32, i32* %2
%19 = call i32 @rselect(i32* %12, i32 0, i32 %17, i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 @free(i32* %12)
ret i32 0
22: ; preds = %0, %22
%23 = phi i64 [ %26, %22 ], [ 0, %0 ]
%24 = getelementptr inbounds i32, i32* %12, i64 %23
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %24)
%26 = add nuw nsw i64 %23, 1
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %22, label %15
}