#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 /*<<< orphan*/ printf(char *, int);
int rand();
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ swap(int *, int *);
scalar_t__ time(int /*<<< orphan*/ *);
int random_partition(int *a, int p, int r) {
  int i;
  if (p <= r) {
    srand((unsigned)time(NULL));
    i = (rand() % (r - p + 1)) + p;
    printf("%d\n", i);
    swap(&a[i], &a[r]);
    return random_partition(a, p, r);
  }
}


x86 assembly (clang, -O0):
<random_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11eb <random_partition+0x8b>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    -0x14(%rbp),%edx
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1070 <swap@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <random_partition@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_partition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
sub    %esi,%r13d
jge    1172 <random_partition+0x22>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %esi,%r14d
mov    %rdi,%r12
add    $0x1,%r13d
movslq %edx,%rax
lea    (%rdi,%rax,4),%rbp
lea    0xe76(%rip),%r15
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
cltd
idiv   %r13d
mov    %edx,%ebx
add    %r14d,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
movslq %ebx,%rax
lea    (%r12,%rax,4),%rdi
mov    %rbp,%rsi
call   1060 <swap@plt>
jmp    1190 <random_partition+0x40>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @random_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** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = load i32, i32* %7
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %39
12: ; preds = %3
%13 = call i64 @time(i32* null)
%14 = trunc i64 %13 to i32
%15 = call i32 @srand(i32 %14)
%16 = call i32 (...) @rand()
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = sub nsw i32 %17, %18
%20 = add nsw i32 %19, 1
%21 = srem i32 %16, %20
%22 = load i32, i32* %6
%23 = add nsw i32 %21, %22
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %5
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32*, i32** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = call i32 @swap(i32* %29, i32* %33)
%35 = load i32*, i32** %5
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = call i32 @random_partition(i32* %35, i32 %36, i32 %37)
store i32 %38, i32* %4
br label %39
39: ; preds = %12, %3
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @random_partition(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, %1
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = sub i32 1, %1
%7 = add i32 %6, %2
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
br label %10
10: ; preds = %10, %5
%11 = tail call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @srand(i32 %12)
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, %7
%16 = add nsw i32 %15, %1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = tail call i32 @swap(i32* %19, i32* %9)
br label %10
21: ; preds = %3
ret i32 undef
}