#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, unsigned long const *);
void _quick_sort(int *sort, int p, int r, const unsigned long *ref) {
  if (p < r) {
    int q = _partition(sort, p, r, ref);
    _quick_sort(sort, p, q - 1, ref);
    _quick_sort(sort, q + 1, r, ref);
  }
}


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    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1184 <_quick_sort+0x64>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <_partition@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
call   1040 <_quick_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <_quick_sort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_quick_sort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %edx,%esi
jge    116c <_quick_sort+0x4c>
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <_partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
call   1040 <_quick_sort@plt>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %r15d,%ebx
jl     1140 <_quick_sort+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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