#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);
int /*<<< orphan*/ swap(int *, int *);
scalar_t__ time(int /*<<< orphan*/ *);
int randPartition(int *A, int p, int r) {
  srand((unsigned)time(NULL));
  int random;
  random = (rand() % (r - p + 1)) + p;
  swap(&A[random], &A[r]);
  return partition(A, p, r);
}


x86 assembly (clang, -O0):
<randPartition>:
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 <partition@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randPartition>:
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 <partition@plt>

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

LLVM IR (-O2):
define i32 @randPartition(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 i32 1, %1
%9 = add i32 %8, %2
%10 = srem i32 %7, %9
%11 = add nsw i32 %10, %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = sext i32 %2 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = tail call i32 @swap(i32* %13, i32* %15)
%17 = tail call i32 @partition(i32* %0, i32 %1, i32 %2)
ret i32 %17
}