#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, int *, int);
int /*<<< orphan*/ sort2(int *, int *);
int /*<<< orphan*/ sort3(int *, int *);
int /*<<< orphan*/ sort4(int *, int *);
int /*<<< orphan*/ sort5(int *, int *);
void quicksort(int x[], int start, int stop, int *comp, int pivot_select) {
  if (stop - start <= 4) {
    if (start >= stop) {
      return;
    }
    switch (stop - start) {
    case 1:
      sort2(x + start, comp);
      return;
    case 2:
      sort3(x + start, comp);
      return;
    case 3:
      sort4(x + start, comp);
      return;
    case 4:
      sort5(x + start, comp);
      return;
    }
  }
  int pivotpos = partition(x, start, stop, comp, pivot_select);
  quicksort(x, start, pivotpos - 1, comp, pivot_select);
  quicksort(x, pivotpos + 1, stop, comp, pivot_select);
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x4,%eax
jg     1240 <quicksort+0xe0>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     119a <quicksort+0x3a>
jmp    128e <quicksort+0x12e>
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
not    %eax
add    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     123b <quicksort+0xdb>
mov    -0x28(%rbp),%rax
lea    0xe42(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <sort2@plt>
jmp    128e <quicksort+0x12e>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1070 <sort3@plt>
jmp    128e <quicksort+0x12e>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <sort4@plt>
jmp    128e <quicksort+0x12e>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1080 <sort5@plt>
jmp    128e <quicksort+0x12e>
jmp    1240 <quicksort+0xe0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1030 <partition@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1040 <quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1040 <quicksort@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r12d
mov    %rcx,%r14
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%r15
jmp    11ad <quicksort+0x4d>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r14,%rcx
mov    %r12d,%r8d
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %r12d,%r8d
call   1040 <quicksort@plt>
add    $0x1,%ebx
mov    %ebx,%ebp
mov    %r13d,%eax
sub    %ebp,%eax
cmp    $0x4,%eax
jg     1180 <quicksort+0x20>
cmp    %r13d,%ebp
jge    11f1 <quicksort+0x91>
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1180 <quicksort+0x20>
lea    0xe35(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movslq %ebp,%rax
lea    (%r15,%rax,4),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <sort2@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %ebp,%rax
lea    (%r15,%rax,4),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <sort3@plt>
movslq %ebp,%rax
lea    (%r15,%rax,4),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sort4@plt>
movslq %ebp,%rax
lea    (%r15,%rax,4),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sort5@plt>

LLVM IR (-O0):
define void @quicksort(i32* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%12 = load i32, i32* %8
%13 = load i32, i32* %7
%14 = sub nsw i32 %12, %13
%15 = icmp sle i32 %14, 4
br i1 %15, label %16, label %54
16: ; preds = %5
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = icmp sge i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
br label %73
21: ; preds = %16
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = sub nsw i32 %22, %23
switch i32 %24, label %53 [
i32 1, label %25
i32 2, label %32
i32 3, label %39
i32 4, label %46
]
25: ; preds = %21
%26 = load i32*, i32** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32*, i32** %9
%31 = call i32 @sort2(i32* %29, i32* %30)
br label %73
32: ; preds = %21
%33 = load i32*, i32** %6
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32*, i32** %9
%38 = call i32 @sort3(i32* %36, i32* %37)
br label %73
39: ; preds = %21
%40 = load i32*, i32** %6
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32*, i32** %9
%45 = call i32 @sort4(i32* %43, i32* %44)
br label %73
46: ; preds = %21
%47 = load i32*, i32** %6
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32*, i32** %9
%52 = call i32 @sort5(i32* %50, i32* %51)
br label %73
53: ; preds = %21
br label %54
54: ; preds = %53, %5
%55 = load i32*, i32** %6
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = load i32*, i32** %9
%59 = load i32, i32* %10
%60 = call i32 @partition(i32* %55, i32 %56, i32 %57, i32* %58, i32 %59)
store i32 %60, i32* %11
%61 = load i32*, i32** %6
%62 = load i32, i32* %7
%63 = load i32, i32* %11
%64 = sub nsw i32 %63, 1
%65 = load i32*, i32** %9
%66 = load i32, i32* %10
%67 = load i32*, i32** %6
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
%70 = load i32, i32* %8
%71 = load i32*, i32** %9
%72 = load i32, i32* %10
br label %73
73: ; preds = %54, %46, %39, %32, %25, %20
ret void
}

LLVM IR (-O2):
define void @quicksort(i32* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
br label %6
6: ; preds = %29, %5
%7 = phi i32 [ %1, %5 ], [ %32, %29 ]
%8 = sub nsw i32 %2, %7
%9 = icmp slt i32 %8, 5
br i1 %9, label %10, label %29
10: ; preds = %6
%11 = icmp slt i32 %7, %2
br i1 %11, label %12, label %33
12: ; preds = %10
switch i32 %8, label %29 [
i32 1, label %13
i32 2, label %17
i32 3, label %21
i32 4, label %25
]
13: ; preds = %12
%14 = sext i32 %7 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = tail call i32 @sort2(i32* %15, i32* %3)
br label %33
17: ; preds = %12
%18 = sext i32 %7 to i64
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = tail call i32 @sort3(i32* %19, i32* %3)
br label %33
21: ; preds = %12
%22 = sext i32 %7 to i64
%23 = getelementptr inbounds i32, i32* %0, i64 %22
%24 = tail call i32 @sort4(i32* %23, i32* %3)
br label %33
25: ; preds = %12
%26 = sext i32 %7 to i64
%27 = getelementptr inbounds i32, i32* %0, i64 %26
%28 = tail call i32 @sort5(i32* %27, i32* %3)
br label %33
29: ; preds = %12, %6
%30 = tail call i32 @partition(i32* %0, i32 %7, i32 %2, i32* %3, i32 %4)
%31 = add nsw i32 %30, -1
tail call void @quicksort(i32* %0, i32 %7, i32 %31, i32* %3, i32 %4)
%32 = add nsw i32 %30, 1
br label %6
33: ; preds = %10, %25, %21, %17, %13
ret void
}