#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*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int randomized_partition(int *A, int p, int r) {
  int i, tmp;
  srand((unsigned)time(NULL));
  i = rand() % (r - p) + p;
  do {
    tmp = A[i];
    A[i] = A[r];
    A[r] = tmp;
  } while (0);
  return partition(A, p, r);
}


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)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x10(%rbp),%ecx
sub    -0xc(%rbp),%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%edx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
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   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %r14d,%ecx
sub    %ebp,%ecx
cltd
idiv   %ecx
add    %ebp,%edx
movslq %edx,%rax
mov    (%rbx,%rax,4),%ecx
movslq %r14d,%rdx
mov    (%rbx,%rdx,4),%esi
mov    %esi,(%rbx,%rax,4)
mov    %ecx,(%rbx,%rdx,4)
mov    %rbx,%rdi
mov    %ebp,%esi
pop    %rbx
pop    %r14
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
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
%11 = call i32 @srand(i32 %10)
%12 = call i32 (...) @rand()
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
%16 = srem i32 %12, %15
%17 = load i32, i32* %5
%18 = add nsw i32 %16, %17
store i32 %18, i32* %7
br label %19
19: ; preds = %3
%20 = load i32*, i32** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
store i32 %24, i32* %8
%25 = load i32*, i32** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = load i32*, i32** %4
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
%34 = load i32, i32* %8
%35 = load i32*, i32** %4
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
br label %39
39: ; preds = %19
%40 = load i32*, i32** %4
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = call i32 @partition(i32* %40, i32 %41, i32 %42)
ret i32 %43
}

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