#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 median(int *, int, int);
int partition(int *, int, int);
int /*<<< orphan*/ swap(int *, int, int);
void quickSort(int *array, int start, int end) {
  if (start < end) {
    int medianIndex = median(array, start, end);
    swap(array, medianIndex, end);
    int mid = partition(array, start, end);
    quickSort(array, start, mid - 1);
    quickSort(array, mid + 1, end);
  }
}


x86 assembly (clang, -O0):
<quickSort>:
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
jge    11b5 <quickSort+0x75>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <median@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <partition@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1050 <quickSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <quickSort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quickSort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %edx,%esi
jge    11a0 <quickSort+0x60>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <median@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14d,%edx
call   1060 <swap@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <quickSort@plt>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %r14d,%ebx
jl     1160 <quickSort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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