#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 list[], int n, int left, int right) {
  if (left < right) {
    int pivot = partition(list, n, left, right);
    quicksort(list, n, left, pivot - 1);
    quicksort(list, n, pivot + 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    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1180 <quicksort+0x60>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <partition@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
call   1040 <quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
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    %ecx,%edx
jge    116c <quicksort+0x4c>
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%ecx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
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, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = load i32, i32* %8
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %4
%14 = load i32*, i32** %5
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = call i32 @partition(i32* %14, i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %9
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = load i32, i32* %9
%23 = sub nsw i32 %22, 1
%24 = load i32*, i32** %5
%25 = load i32, i32* %6
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
%28 = load i32, i32* %8
br label %29
29: ; preds = %13, %4
ret void
}

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