#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 /*<<< orphan*/ printf(char *, ...);
void quicksort(int a[], int p, int r) {
  int q, i;
  if (p < r) {
    q = partition(a, p, r);
    printf("Partition: ");
    for (i = 0; i < r; i++)
      printf("%d ", a[i]);
    printf("\n");
    quicksort(a, p, q - 1);
    printf("Sort Partition 01: ");
    for (i = 0; i < q; i++)
      printf("%d ", a[i]);
    printf("\n");
    quicksort(a, q + 1, r);
    printf("Sort Partition 02: ");
    for (i = q + 1; i <= r; i++)
      printf("%d ", a[i]);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<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    1288 <quicksort+0x158>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11a8 <quicksort+0x78>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1175 <quicksort+0x45>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <quicksort@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1210 <quicksort+0xe0>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11dd <quicksort+0xad>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <quicksort@plt>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     127a <quicksort+0x14a>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1247 <quicksort+0x117>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
cmp    %edx,%esi
jge    127f <quicksort+0x13f>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,%r12d
mov    %rdi,%r14
call   1040 <partition@plt>
mov    %rax,0x10(%rsp)
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,0x8(%rsp)
test   %ebx,%ebx
jle    11a7 <quicksort+0x67>
mov    0x8(%rsp),%ebp
lea    0xe82(%rip),%r13
xor    %r15d,%r15d
nopl   (%rax)
mov    (%r14,%r15,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1190 <quicksort+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x10(%rsp),%r15
lea    -0x1(%r15),%edx
mov    %r14,%rdi
mov    %r12d,%esi
call   1050 <quicksort@plt>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    1207 <quicksort+0xc7>
mov    %r15d,%ebp
lea    0xe2a(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11f0 <quicksort+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%r15),%esi
mov    %r14,%rdi
mov    0x8(%rsp),%r12
mov    %r12d,%edx
call   1050 <quicksort@plt>
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    %r12d,%r15d
jge    1267 <quicksort+0x127>
movslq %r15d,%rax
lea    (%r14,%rax,4),%rbp
add    $0x4,%rbp
sub    %r15d,%r12d
lea    0xdbf(%rip),%r15
xor    %ebx,%ebx
nop
mov    0x0(%rbp,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1250 <quicksort+0x110>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Partition: \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [20 x i8] c"Sort Partition 01: \00"
@.str.4 = [20 x i8] c"Sort Partition 02: \00"
define void @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 %78
12: ; preds = %3
%13 = load i32*, i32** %4
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @partition(i32* %13, i32 %14, i32 %15)
store i32 %16, i32* %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %18
18: ; preds = %29, %12
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32*, i32** %4
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %22
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %18
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32*, i32** %4
%35 = load i32, i32* %5
%36 = load i32, i32* %7
%37 = sub nsw i32 %36, 1
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %8
br label %39
39: ; preds = %50, %32
%40 = load i32, i32* %8
%41 = load i32, i32* %7
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = load i32*, i32** %4
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %43
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %39
53: ; preds = %39
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32*, i32** %4
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %62
62: ; preds = %73, %53
%63 = load i32, i32* %8
%64 = load i32, i32* %6
%65 = icmp sle i32 %63, %64
br i1 %65, label %66, label %76
66: ; preds = %62
%67 = load i32*, i32** %4
%68 = load i32, i32* %8
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %66
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
store i32 %75, i32* %8
br label %62
76: ; preds = %62
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %78
78: ; preds = %76, %3
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"Partition: \00"
@.str.1 = [4 x i8] c"%d \00"
@.str.3 = [20 x i8] c"Sort Partition 01: \00"
@.str.4 = [20 x i8] c"Sort Partition 02: \00"
define void @quicksort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %51
5: ; preds = %3
%6 = tail call i32 @partition(i32* %0, i32 %1, i32 %2)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %16, %11 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, %10
br i1 %17, label %18, label %11
18: ; preds = %11, %5
%19 = tail call i32 @putchar(i32 10)
%20 = add nsw i32 %6, -1
tail call void @quicksort(i32* %0, i32 %1, i32 %20)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp sgt i32 %6, 0
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = zext i32 %6 to i64
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %30, %25 ]
%27 = getelementptr inbounds i32, i32* %0, i64 %26
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = add nuw nsw i64 %26, 1
%31 = icmp eq i64 %30, %24
br i1 %31, label %32, label %25
32: ; preds = %25, %18
%33 = tail call i32 @putchar(i32 10)
%34 = add nsw i32 %6, 1
tail call void @quicksort(i32* %0, i32 %34, i32 %2)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp slt i32 %6, %2
br i1 %36, label %37, label %49
37: ; preds = %32
%38 = sext i32 %6 to i64
%39 = add nsw i64 %38, 1
%40 = add i32 %2, 1
br label %41
41: ; preds = %37, %41
%42 = phi i64 [ %39, %37 ], [ %46, %41 ]
%43 = getelementptr inbounds i32, i32* %0, i64 %42
%44 = load i32, i32* %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = add nsw i64 %42, 1
%47 = trunc i64 %46 to i32
%48 = icmp eq i32 %40, %47
br i1 %48, label %49, label %41
49: ; preds = %41, %32
%50 = tail call i32 @putchar(i32 10)
br label %51
51: ; preds = %49, %3
ret void
}