#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 lib_qsort_partition(int *, int, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ swap(int *, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int lib_qsort_randomized_partition(int *array, int start, int end) {
  int partition_index;
  srand(time(NULL));
  partition_index = (rand() % (end - start + 1)) + start;
  swap(&array[partition_index], &array[end]);
  return lib_qsort_partition(array, start, end);
}


x86 assembly (clang, -O0):
<lib_qsort_randomized_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
add    $0x1,%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   1060 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <lib_qsort_partition@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib_qsort_randomized_partition>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <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   1060 <swap@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <lib_qsort_partition@plt>

LLVM IR (-O0):
define i32 @lib_qsort_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 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%10 = call i32 (...) @rand()
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = sub nsw i32 %11, %12
%14 = add nsw i32 %13, 1
%15 = srem i32 %10, %14
%16 = load i32, i32* %5
%17 = add nsw i32 %15, %16
store i32 %17, i32* %7
%18 = load i32*, i32** %4
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
%22 = load i32*, i32** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = call i32 @swap(i32* %21, i32* %25)
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 @lib_qsort_partition(i32* %27, i32 %28, i32 %29)
ret i32 %30
}

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