#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 */
double RAND_MAX;
int partition(int *, int, int);
int rand();
int random_partition(int *a, int p, int r) {
  int i = p + (int)((r - p + 1) * rand() / (RAND_MAX + 1.0));
  int t = a[i];
  a[i] = a[r];
  a[r] = t;
  return partition(a, p, r);
}


x86 assembly (clang, -O0):
<random_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x20(%rbp),%ecx
mov    %eax,%edx
mov    -0x1c(%rbp),%eax
imul   %edx,%ecx
cvtsi2sd %ecx,%xmm0
movsd  0xe9e(%rip),%xmm1
mov    0x2e7f(%rip),%rcx
addsd  (%rcx),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
add    %ecx,%eax
mov    %eax,-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):
<random_partition>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
mov    %edx,%ebx
sub    %esi,%ebx
add    $0x1,%ebx
xor    %eax,%eax
call   1040 <rand@plt>
imul   %ebx,%eax
cvtsi2sd %eax,%xmm0
mov    0x2e9c(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xea8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    %r15d,%eax
cltq
mov    0x0(%rbp,%rax,4),%ecx
movslq %r14d,%rdx
mov    0x0(%rbp,%rdx,4),%esi
mov    %esi,0x0(%rbp,%rax,4)
mov    %ecx,0x0(%rbp,%rdx,4)
mov    %rbp,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <partition@plt>

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+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** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = sub nsw i32 %10, %11
%13 = add nsw i32 %12, 1
%14 = call i32 (...) @rand()
%15 = mul nsw i32 %13, %14
%16 = sitofp i32 %15 to double
%17 = load double, double* @RAND_MAX
%18 = fadd double %17, 1.000000e+00
%19 = fdiv double %16, %18
%20 = fptosi double %19 to i32
%21 = add nsw i32 %9, %20
store i32 %21, i32* %7
%22 = load i32*, i32** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
store i32 %26, i32* %8
%27 = load i32*, i32** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32*, i32** %4
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
%36 = load i32, i32* %8
%37 = load i32*, i32** %4
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %36, i32* %40
%41 = load i32*, i32** %4
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 @partition(i32* %41, i32 %42, i32 %43)
ret i32 %44
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i32 @random_partition(i32* %0, i32 %1, i32 %2) {
%4 = sub i32 1, %1
%5 = add i32 %4, %2
%6 = tail call i32 (...) @rand()
%7 = mul nsw i32 %6, %5
%8 = sitofp i32 %7 to double
%9 = load double, double* @RAND_MAX
%10 = fadd double %9, 1.000000e+00
%11 = fdiv double %8, %10
%12 = fptosi double %11 to i32
%13 = add nsw i32 %12, %1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = sext i32 %2 to i64
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %15
store i32 %16, i32* %18
%20 = tail call i32 @partition(i32* %0, i32 %1, i32 %2)
ret i32 %20
}