#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 choosePivotByMedianOfThree(int *, int, int);
int /*<<< orphan*/ insertionSort(int *, int);
int partition(int *, int, int);
void quickSortWithInsertionSort(int *theArray, int pivot, int right) {
  int aux;
  pivot = choosePivotByMedianOfThree(theArray, pivot, right);
  if (pivot < right && right > 20) {
    aux = partition(theArray, pivot, right);
    quickSortWithInsertionSort(theArray, pivot, aux - 1);
    quickSortWithInsertionSort(theArray, aux + 1, right);
  } else if (right <= 20) {
    insertionSort(theArray, right);
  }
}


x86 assembly (clang, -O0):
<quickSortWithInsertionSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <choosePivotByMedianOfThree@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b5 <quickSortWithInsertionSort+0x75>
cmpl   $0x14,-0x10(%rbp)
jle    11b5 <quickSortWithInsertionSort+0x75>
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   1060 <quickSortWithInsertionSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1060 <quickSortWithInsertionSort@plt>
jmp    11d0 <quickSortWithInsertionSort+0x90>
cmpl   $0x14,-0x10(%rbp)
jg     11cb <quickSortWithInsertionSort+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <insertionSort@plt>
jmp    11d0 <quickSortWithInsertionSort+0x90>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quickSortWithInsertionSort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rdi,%r14
call   1040 <choosePivotByMedianOfThree@plt>
cmp    $0x15,%r15d
jl     1193 <quickSortWithInsertionSort+0x53>
mov    %eax,%ebp
cmp    %r15d,%eax
jge    1193 <quickSortWithInsertionSort+0x53>
nop
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <quickSortWithInsertionSort@plt>
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1040 <choosePivotByMedianOfThree@plt>
mov    %eax,%ebp
cmp    %r15d,%eax
jl     1160 <quickSortWithInsertionSort+0x20>
cmp    $0x14,%r15d
jg     11ae <quickSortWithInsertionSort+0x6e>
mov    %r14,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <insertionSort@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quickSortWithInsertionSort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = call i32 @choosePivotByMedianOfThree(i32* %8, i32 %9, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %3
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 20
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 @partition(i32* %19, i32 %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = load i32*, i32** %4
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
%30 = load i32, i32* %6
br label %39
31: ; preds = %15, %3
%32 = load i32, i32* %6
%33 = icmp sle i32 %32, 20
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32*, i32** %4
%36 = load i32, i32* %6
%37 = call i32 @insertionSort(i32* %35, i32 %36)
br label %38
38: ; preds = %34, %31
br label %39
39: ; preds = %38, %18
ret void
}

LLVM IR (-O2):
define void @quickSortWithInsertionSort(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 @choosePivotByMedianOfThree(i32* %0, i32 %1, i32 %2)
%5 = icmp slt i32 %4, %2
%6 = icmp sgt i32 %2, 20
%7 = and i1 %6, %5
br i1 %7, label %8, label %15
8: ; preds = %3, %8
%9 = phi i32 [ %13, %8 ], [ %4, %3 ]
%10 = tail call i32 @partition(i32* %0, i32 %9, i32 %2)
%11 = add nsw i32 %10, -1
tail call void @quickSortWithInsertionSort(i32* %0, i32 %9, i32 %11)
%12 = add nsw i32 %10, 1
%13 = tail call i32 @choosePivotByMedianOfThree(i32* %0, i32 %12, i32 %2)
%14 = icmp slt i32 %13, %2
br i1 %14, label %8, label %15
15: ; preds = %8, %3
%16 = icmp slt i32 %2, 21
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 @insertionSort(i32* %0, i32 %2)
br label %19
19: ; preds = %15, %17
ret void
}