#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);
void quickSort(int *array, int left, int right) {
  if (left < right) {
    int partitionPoint = partition(array, left, right, array[right]);
    quickSort(array, left, partitionPoint - 1);
    quickSort(array, partitionPoint + 1, right);
  }
}


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    117f <quickSort+0x5f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <quickSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <quickSort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quickSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %edx,%esi
jge    116a <quickSort+0x4a>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
movslq %edx,%r12
nopw   0x0(%rax,%rax,1)
mov    (%r15,%r12,4),%ecx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <quickSort@plt>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %r14d,%ebx
jl     1140 <quickSort+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quickSort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = load i32*, i32** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = call i32 @partition(i32* %12, i32 %13, i32 %14, i32 %19)
store i32 %20, i32* %7
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 1
%25 = load i32*, i32** %4
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
%28 = load i32, i32* %6
br label %29
29: ; preds = %11, %3
ret void
}

LLVM IR (-O2):
define void @quickSort(i32* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i32, i32* %0, i64 %6
br label %8
8: ; preds = %5, %8
%9 = phi i32 [ %1, %5 ], [ %13, %8 ]
%10 = load i32, i32* %7
%11 = tail call i32 @partition(i32* %0, i32 %9, i32 %2, i32 %10)
%12 = add nsw i32 %11, -1
tail call void @quickSort(i32* %0, i32 %9, i32 %12)
%13 = add nsw i32 %11, 1
%14 = icmp slt i32 %13, %2
br i1 %14, label %8, label %15
15: ; preds = %8, %3
ret void
}