#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 */
unsigned int partition(int *, unsigned int, unsigned int, unsigned int);
void quick_sort(int array[], unsigned left, unsigned right) {
  unsigned pivot;
  if (left < right) {
    pivot = (left + right) >> 1;
    pivot = partition(array, left, right, pivot);
    quick_sort(array, left, pivot - 1);
    quick_sort(array, pivot + 1, right);
  }
}


x86 assembly (clang, -O0):
<quick_sort>:
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
jae    1183 <quick_sort+0x63>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
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 <quick_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <quick_sort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick_sort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    %edx,%esi
jae    116f <quick_sort+0x4f>
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r12,%r15,1),%ecx
shr    %ecx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <quick_sort@plt>
add    $0x1,%ebx
mov    %ebx,%r12d
cmp    %r15d,%ebx
jb     1140 <quick_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @quick_sort(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 ult i32 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = add i32 %12, %13
%15 = lshr i32 %14, 1
store i32 %15, i32* %7
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = call i32 @partition(i32* %16, i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %7
%24 = sub i32 %23, 1
%25 = load i32*, i32** %4
%26 = load i32, i32* %7
%27 = add i32 %26, 1
%28 = load i32, i32* %6
br label %29
29: ; preds = %11, %3
ret void
}

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