#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(size_t, int *, size_t);
void quicksort(size_t N, int arr[N]) {
  if (N <= 1) {
    return;
  }
  size_t mid = N / 2;
  size_t p = partition(N, arr, mid);
  quicksort(p, arr);
  quicksort(N - p - 1, arr + p + 1);
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x8(%rbp)
ja     1140 <quicksort+0x20>
jmp    1192 <quicksort+0x72>
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <partition@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <quicksort@plt>
mov    -0x8(%rbp),%rdi
sub    -0x20(%rbp),%rdi
sub    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
add    $0x4,%rsi
call   1040 <quicksort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%rdi
jb     1173 <quicksort+0x53>
mov    %rsi,%r14
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdx
shr    %rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <partition@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <quicksort@plt>
lea    (%r14,%rbx,4),%r14
add    $0x4,%r14
not    %rbx
add    %rbx,%r15
cmp    $0x1,%r15
ja     1140 <quicksort+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @quicksort(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i32* %1, i32** %4
%7 = load i64, i64* %3
%8 = load i64, i64* %3
%9 = icmp ule i64 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
br label %28
11: ; preds = %2
%12 = load i64, i64* %3
%13 = udiv i64 %12, 2
store i64 %13, i64* %5
%14 = load i64, i64* %3
%15 = load i32*, i32** %4
%16 = load i64, i64* %5
%17 = call i64 @partition(i64 %14, i32* %15, i64 %16)
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = load i32*, i32** %4
%20 = load i64, i64* %3
%21 = load i64, i64* %6
%22 = sub i64 %20, %21
%23 = sub i64 %22, 1
%24 = load i32*, i32** %4
%25 = load i64, i64* %6
%26 = getelementptr inbounds i32, i32* %24, i64 %25
%27 = getelementptr inbounds i32, i32* %26, i64 1
br label %28
28: ; preds = %11, %10
ret void
}

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