#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 /*<<< orphan*/ insertion_sort(size_t *, int, int);
int partition(size_t *, int, int);
void quicksort(size_t *addrs, int min, int max) {
  if (max - min > 16) {
    int mid = partition(addrs, min, max);
    quicksort(addrs, min, mid - 1);
    quicksort(addrs, mid + 1, max);
  } else {
    insertion_sort(addrs, min, max);
  }
}


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    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x10,%eax
jle    118c <quicksort+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <quicksort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <quicksort@plt>
jmp    119b <quicksort+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <insertion_sort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    %edx,%eax
sub    %esi,%eax
cmp    $0x11,%eax
jl     117d <quicksort+0x4d>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <quicksort@plt>
add    $0x1,%ebx
mov    %r14d,%eax
sub    %ebx,%eax
mov    %ebx,%ebp
cmp    $0x10,%eax
jg     1150 <quicksort+0x20>
jmp    117f <quicksort+0x4f>
mov    %ebp,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <insertion_sort@plt>

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

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