#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 *list, int lower, int upper) {
  if (lower >= upper)
    return;
  int pivot = partition(list, lower, upper);
  if (upper != lower + 1) {
    QuickSort(list, lower, pivot - 1);
    QuickSort(list, pivot + 1, upper);
  }
}


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
jl     1143 <QuickSort+0x23>
jmp    118a <QuickSort+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     118a <QuickSort+0x6a>
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
cmp    %edx,%esi
jge    116e <QuickSort+0x4e>
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    0x1(%rbp),%eax
cmp    %r15d,%eax
je     116e <QuickSort+0x4e>
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <QuickSort@plt>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %r15d,%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* %5
%9 = load i32, i32* %6
%10 = icmp sge i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %3
br label %30
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 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %30
21: ; preds = %12
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
%26 = load i32*, i32** %4
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %6
br label %30
30: ; preds = %11, %21, %12
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 %14
5: ; preds = %3, %10
%6 = phi i32 [ %12, %10 ], [ %1, %3 ]
%7 = tail call i32 @partition(i32* %0, i32 %6, i32 %2)
%8 = add nsw i32 %6, 1
%9 = icmp eq i32 %8, %2
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = add nsw i32 %7, -1
tail call void @QuickSort(i32* %0, i32 %6, i32 %11)
%12 = add nsw i32 %7, 1
%13 = icmp slt i32 %12, %2
br i1 %13, label %5, label %14
14: ; preds = %10, %5, %3
ret void
}