#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 */
struct IndexEntry {
  int dummy;
};
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ insertionSortMemory(struct IndexEntry *, int, int);
int partitionMemory(struct IndexEntry *, int, int);
void quickSortMemory(struct IndexEntry *sortBuffer, int64_t lowerIdx,
                     int64_t upperIdx) {
  int64_t size = upperIdx - lowerIdx + 1;
  if (size >= 2) {
    if (size <= 16) {
      insertionSortMemory(sortBuffer, lowerIdx, upperIdx);
    } else {
      int64_t newPivot = partitionMemory(sortBuffer, lowerIdx, upperIdx);
      quickSortMemory(sortBuffer, lowerIdx, newPivot - 1);
      quickSortMemory(sortBuffer, newPivot + 1, upperIdx);
    }
  }
}


x86 assembly (clang, -O0):
<quickSortMemory>:
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
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     11b1 <quickSortMemory+0x81>
cmpl   $0x10,-0x14(%rbp)
jg     1176 <quickSortMemory+0x46>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <insertionSortMemory@plt>
jmp    11ac <quickSortMemory+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partitionMemory@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1050 <quickSortMemory@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <quickSortMemory@plt>
jmp    11b1 <quickSortMemory+0x81>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quickSortMemory>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%eax
sub    %esi,%eax
jle    117d <quickSortMemory+0x4d>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xf,%eax
jbe    1188 <quickSortMemory+0x58>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <partitionMemory@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1050 <quickSortMemory@plt>
add    $0x1,%ebx
mov    %r14d,%eax
mov    %ebx,%ebp
sub    %ebx,%eax
jg     1150 <quickSortMemory+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <insertionSortMemory@plt>

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

LLVM IR (-O2):
%struct.IndexEntry = type { i32 }
define void @quickSortMemory(%struct.IndexEntry* %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %3, %12
%7 = phi i32 [ %16, %12 ], [ %4, %3 ]
%8 = phi i32 [ %15, %12 ], [ %1, %3 ]
%9 = icmp ult i32 %7, 16
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @insertionSortMemory(%struct.IndexEntry* %0, i32 %8, i32 %2)
br label %18
12: ; preds = %6
%13 = tail call i32 @partitionMemory(%struct.IndexEntry* %0, i32 %8, i32 %2)
%14 = add nsw i32 %13, -1
tail call void @quickSortMemory(%struct.IndexEntry* %0, i32 %8, i32 %14)
%15 = add nsw i32 %13, 1
%16 = sub nsw i32 %2, %15
%17 = icmp sgt i32 %16, 0
br i1 %17, label %6, label %18
18: ; preds = %12, %3, %10
ret void
}