#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);
void quicksort(int *array, int low, int high) {
  int partition_index;
  if (!array || (low >= high)) {
    return;
  }
  partition_index = partition(array, low, high);
  quicksort(array, low, partition_index - 1);
  quicksort(array, partition_index + 1, high);
}


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)
cmpq   $0x0,-0x8(%rbp)
je     1149 <quicksort+0x29>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     114e <quicksort+0x2e>
jmp    1184 <quicksort+0x64>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
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   %rbx
push   %rax
test   %rdi,%rdi
je     1166 <quicksort+0x46>
mov    %edx,%r14d
mov    %esi,%ebp
cmp    %edx,%esi
jge    1166 <quicksort+0x46>
mov    %rdi,%r15
nopl   0x0(%rax,%rax,1)
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>
add    $0x8,%rsp
pop    %rbx
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** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp sge i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10, %3
br label %28
15: ; preds = %10
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @partition(i32* %16, i32 %17, i32 %18)
store i32 %19, i32* %7
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = load i32, i32* %7
%23 = sub nsw i32 %22, 1
%24 = load i32*, i32** %4
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %6
br label %28
28: ; preds = %15, %14
ret void
}

LLVM IR (-O2):
define void @quicksort(i32* %0, i32 %1, i32 %2) {
%4 = icmp ne i32* %0, null
%5 = icmp slt i32 %1, %2
%6 = and i1 %4, %5
br i1 %6, label %7, label %13
7: ; preds = %3, %7
%8 = phi i32 [ %11, %7 ], [ %1, %3 ]
%9 = tail call i32 @partition(i32* %0, i32 %8, i32 %2)
%10 = add nsw i32 %9, -1
tail call void @quicksort(i32* %0, i32 %8, i32 %10)
%11 = add nsw i32 %9, 1
%12 = icmp slt i32 %11, %2
br i1 %12, label %7, label %13
13: ; preds = %7, %3
ret void
}