#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 partition(int *, int, int);
void find_kth_element_r(int *l, int low, int high, int k) {
  int i;
  if (high <= low)
    return;
  i = partition(l, low, high);
  if (i > k)
    find_kth_element_r(l, low, i - 1, k);
  if (i < k)
    find_kth_element_r(l, i + 1, high, k);
}


x86 assembly (clang, -O0):
<find_kth_element_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1146 <find_kth_element_r+0x26>
jmp    119a <find_kth_element_r+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1179 <find_kth_element_r+0x59>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1040 <find_kth_element_r@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119a <find_kth_element_r+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <find_kth_element_r@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_kth_element_r>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %esi,%edx
jle    1173 <find_kth_element_r+0x53>
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
cmp    %r12d,%eax
jle    1164 <find_kth_element_r+0x44>
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%ecx
call   1040 <find_kth_element_r@plt>
cmp    %r12d,%ebx
jge    1173 <find_kth_element_r+0x53>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %r15d,%ebx
jl     1140 <find_kth_element_r+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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