#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 quick_sort(int input[], int low, int high) {
  int index = partition(input, low, high);
  if (low < index - 1)
    quick_sort(input, low, index - 1);
  if (high > index)
    quick_sort(input, index, high);
}


x86 assembly (clang, -O0):
<quick_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1167 <quick_sort+0x47>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1040 <quick_sort@plt>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1182 <quick_sort+0x62>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <quick_sort@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
jmp    1147 <quick_sort+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%ebp
cmp    %r15d,%ebx
jge    1169 <quick_sort+0x49>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
cmp    %ebp,%edx
jle    1140 <quick_sort+0x20>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <quick_sort@plt>
jmp    1140 <quick_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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