#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);
int rand();
int /*<<< orphan*/ swap(int *, int *);
int randomized_partition(int *input, int start, int end) {
  int pivot_element_index = rand() % (end + 1 - start) + start;
  swap(input + pivot_element_index, input + end);
  return partition(input, start, end);
}


x86 assembly (clang, -O0):
<randomized_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
sub    -0xc(%rbp),%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%edx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomized_partition>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
mov    %r14d,%ecx
sub    %r15d,%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    %r15d,%edx
movslq %edx,%rax
lea    (%rbx,%rax,4),%rdi
movslq %r14d,%rbp
lea    (%rbx,%rbp,4),%rsi
call   1040 <swap@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <partition@plt>

LLVM IR (-O0):
define i32 @randomized_partition(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = call i32 (...) @rand()
%9 = load i32, i32* %6
%10 = add nsw i32 %9, 1
%11 = load i32, i32* %5
%12 = sub nsw i32 %10, %11
%13 = srem i32 %8, %12
%14 = load i32, i32* %5
%15 = add nsw i32 %13, %14
store i32 %15, i32* %7
%16 = load i32*, i32** %4
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32*, i32** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = call i32 @swap(i32* %19, i32* %23)
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i32 @partition(i32* %25, i32 %26, i32 %27)
ret i32 %28
}

LLVM IR (-O2):
define i32 @randomized_partition(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 (...) @rand()
%5 = sub i32 1, %1
%6 = add i32 %5, %2
%7 = srem i32 %4, %6
%8 = add nsw i32 %7, %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = sext i32 %2 to i64
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = tail call i32 @swap(i32* %10, i32* %12)
%14 = tail call i32 @partition(i32* %0, i32 %1, i32 %2)
ret i32 %14
}