#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 */
size_t choose(int *, int, int, int *, int);
int /*<<< orphan*/ choosepivot(int *, int, int, int *, int);
int return_index(int x[], int start, int stop, int *comp, int pivot_select) {
  if (pivot_select == 3) {
    int pivot = start;
    return x[choose(x, start, stop, comp, pivot_select)];
  } else {
    choosepivot(x, start, stop, comp, pivot_select);
    return x[stop];
  }
}


x86 assembly (clang, -O0):
<return_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jne    117b <return_index+0x5b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1030 <choose@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <return_index+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1040 <choosepivot@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<return_index>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
cmp    $0x3,%r8d
jne    113d <return_index+0x1d>
mov    %ebp,%edx
mov    $0x3,%r8d
call   1030 <choose@plt>
jmp    1147 <return_index+0x27>
mov    %ebp,%edx
call   1040 <choosepivot@plt>
movslq %ebp,%rax
mov    (%rbx,%rax,4),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @return_index(i32* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = icmp eq i32 %4, 3
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i64 @choose(i32* %0, i32 %1, i32 %2, i32* %3, i32 3)
br label %12
9: ; preds = %5
%10 = tail call i32 @choosepivot(i32* %0, i32 %1, i32 %2, i32* %3, i32 %4)
%11 = sext i32 %2 to i64
br label %12
12: ; preds = %9, %7
%13 = phi i64 [ %8, %7 ], [ %11, %9 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
ret i32 %15
}