#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 rand_partition(int *, int, int);
void rand_quicksort(int *A, int p, int r) {
  int i;
  int q;
  if (p < r) {
    q = rand_partition(A, p, r);
    for (i = 0; i < 8; i++)
      printf("%d   ", A[i]);
    printf("\n\n");
    rand_quicksort(A, p, q - 1);
    rand_quicksort(A, q + 1, r);
  }
}


x86 assembly (clang, -O0):
<rand_quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ca <rand_quicksort+0x9a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <rand_partition@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    1198 <rand_quicksort+0x68>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1167 <rand_quicksort+0x37>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1040 <rand_quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <rand_quicksort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_quicksort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%esi
jge    120c <rand_quicksort+0xcc>
mov    %edx,%r14d
mov    %esi,%r13d
mov    %rdi,%rbx
lea    0xe9d(%rip),%r15
lea    0xe9c(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
call   1060 <rand_partition@plt>
mov    %eax,%ebp
mov    (%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
lea    -0x1(%rbp),%edx
mov    %rbx,%rdi
mov    %r13d,%esi
call   1050 <rand_quicksort@plt>
add    $0x1,%ebp
mov    %ebp,%r13d
cmp    %r14d,%ebp
jl     1170 <rand_quicksort+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%d \00"
@str = [2 x i8] c"\0A\00"
define void @rand_quicksort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %36
5: ; preds = %3
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = getelementptr inbounds i32, i32* %0, i64 3
%9 = getelementptr inbounds i32, i32* %0, i64 4
%10 = getelementptr inbounds i32, i32* %0, i64 5
%11 = getelementptr inbounds i32, i32* %0, i64 6
%12 = getelementptr inbounds i32, i32* %0, i64 7
br label %13
13: ; preds = %5, %13
%14 = phi i32 [ %34, %13 ], [ %1, %5 ]
%15 = tail call i32 @rand_partition(i32* %0, i32 %14, i32 %2)
%16 = load i32, i32* %0
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %6
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %7
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %8
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %9
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %10
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %11
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %12
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%33 = add nsw i32 %15, -1
tail call void @rand_quicksort(i32* %0, i32 %14, i32 %33)
%34 = add nsw i32 %15, 1
%35 = icmp slt i32 %34, %2
br i1 %35, label %13, label %36
36: ; preds = %13, %3
ret void
}