#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 */
typedef int int32_t;

/* Variables and functions */
int i_Partitionner(int *, int *, int, int);
int rand();
int32_t i_PartitionStochastique(int32_t *A, int32_t *T, int32_t p, int32_t r) {
  int32_t t, q;
  q = p + (rand() % (r - p + 1));
  t = A[p];
  A[p] = A[q];
  A[q] = t;
  return i_Partitionner(A, T, p, r);
}


x86 assembly (clang, -O0):
<i_PartitionStochastique>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    -0x18(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <i_Partitionner@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i_PartitionStochastique>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <rand@plt>
mov    %r15d,%ecx
sub    %ebp,%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    %ebp,%edx
movslq %ebp,%rax
mov    (%rbx,%rax,4),%ecx
movslq %edx,%rdx
mov    (%rbx,%rdx,4),%esi
mov    %esi,(%rbx,%rax,4)
mov    %ecx,(%rbx,%rdx,4)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    %r15d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <i_Partitionner@plt>

LLVM IR (-O0):
define i32 @i_PartitionStochastique(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %7
%12 = call i32 (...) @rand()
%13 = load i32, i32* %8
%14 = load i32, i32* %7
%15 = sub nsw i32 %13, %14
%16 = add nsw i32 %15, 1
%17 = srem i32 %12, %16
%18 = add nsw i32 %11, %17
store i32 %18, i32* %10
%19 = load i32*, i32** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
store i32 %23, i32* %9
%24 = load i32*, i32** %5
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = load i32*, i32** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
%33 = load i32, i32* %9
%34 = load i32*, i32** %5
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
%38 = load i32*, i32** %5
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 @i_Partitionner(i32* %38, i32* %39, i32 %40, i32 %41)
ret i32 %42
}

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