#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 const, size_t const, size_t);
void quicksort(int *arr, const size_t left, const size_t right) {
  size_t pivot, newp;
  if (left < right) {
    pivot = left + (right - left) / 2;
    newp = partition(arr, left, right, pivot);
    if (newp != 0)
      quicksort(arr, left, newp - 1);
    quicksort(arr, newp + 1, right);
  }
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a7 <quicksort+0x87>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    -0x10(%rbp),%rcx
shr    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <partition@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1192 <quicksort+0x72>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1040 <quicksort@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    %rsi,%rdx
jbe    117f <quicksort+0x5f>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
jmp    114c <quicksort+0x2c>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rbx,%r12
cmp    %r15,%rbx
jae    117f <quicksort+0x5f>
mov    %r15,%rcx
sub    %r12,%rcx
shr    %rcx
add    %r12,%rcx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <partition@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1140 <quicksort+0x20>
lea    -0x1(%rbx),%rdx
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <quicksort@plt>
jmp    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
%8 = alloca i64
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %5
%10 = load i64, i64* %6
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %3
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = load i64, i64* %5
%16 = sub i64 %14, %15
%17 = udiv i64 %16, 2
%18 = add i64 %13, %17
store i64 %18, i64* %7
%19 = load i32*, i32** %4
%20 = load i64, i64* %5
%21 = load i64, i64* %6
%22 = load i64, i64* %7
%23 = call i64 @partition(i32* %19, i64 %20, i64 %21, i64 %22)
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %12
%27 = load i32*, i32** %4
%28 = load i64, i64* %5
%29 = load i64, i64* %8
%30 = sub i64 %29, 1
br label %31
31: ; preds = %26, %12
%32 = load i32*, i32** %4
%33 = load i64, i64* %8
%34 = add i64 %33, 1
%35 = load i64, i64* %6
br label %36
36: ; preds = %31, %3
ret void
}

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