#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 */
size_t partition(int *, size_t, size_t);
void quicksort(int a[], size_t p, size_t r) {
  if (p < r && ~r) {
    size_t q = partition(a, p, r);
    quicksort(a, p, q - 1);
    quicksort(a, q + 1, r);
  }
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1193 <quicksort+0x73>
mov    -0x18(%rbp),%rax
xor    $0xffffffffffffffff,%rax
cmp    $0x0,%rax
je     1193 <quicksort+0x73>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <partition@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1040 <quicksort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0xffffffffffffffff,%rdx
je     116c <quicksort+0x4c>
mov    %rdx,%r15
mov    %rsi,%r12
cmp    %rdx,%rsi
jae    116c <quicksort+0x4c>
mov    %rdi,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <partition@plt>
mov    %rax,%rbx
lea    -0x1(%rax),%rdx
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <quicksort@plt>
add    $0x1,%rbx
mov    %rbx,%r12
cmp    %r15,%rbx
jb     1140 <quicksort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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