#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);
      if ((newPivot - 1) - lowerIdx > upperIdx - (newPivot + 1)) {
        quickSortMemory(sortBuffer, newPivot + 1, upperIdx);
        quickSortMemory(sortBuffer, lowerIdx, newPivot - 1);
      } else {
        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     11fb <quickSortMemory+0xcb>
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    11f6 <quickSortMemory+0xc6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <partitionMemory@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
sub    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%edx
add    $0x1,%edx
sub    %edx,%ecx
cmp    %ecx,%eax
jle    11cd <quickSortMemory+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <quickSortMemory@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1050 <quickSortMemory@plt>
jmp    11f1 <quickSortMemory+0xc1>
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    11f6 <quickSortMemory+0xc6>
jmp    11fb <quickSortMemory+0xcb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quickSortMemory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
mov    %edx,%ebp
mov    %esi,0xc(%rsp)
sub    %esi,%ebp
jle    11c6 <quickSortMemory+0x96>
mov    %edx,%r14d
mov    0x10(%rsp),%r15
mov    %ebp,%r13d
nopl   0x0(%rax,%rax,1)
cmp    $0xf,%r13d
jbe    11d5 <quickSortMemory+0xa5>
mov    %r15,%rdi
mov    0xc(%rsp),%ebp
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <partitionMemory@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%r12d
mov    %r12d,%r13d
sub    %ebp,%r13d
add    $0x1,%ebx
mov    %r14d,%ebp
sub    %ebx,%ebp
mov    %r15,%rdi
cmp    %ebp,%r13d
jle    11b0 <quickSortMemory+0x80>
mov    %ebx,%esi
mov    %r14d,%edx
call   1050 <quickSortMemory@plt>
mov    %r12d,%r14d
test   %r13d,%r13d
jg     1160 <quickSortMemory+0x30>
jmp    11c6 <quickSortMemory+0x96>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    %r12d,%edx
call   1050 <quickSortMemory@plt>
mov    %ebx,%eax
mov    %ebx,0xc(%rsp)
test   %ebp,%ebp
jg     1155 <quickSortMemory+0x25>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    %r14d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 %57
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 %56
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 i32, i32* %8
%29 = sub nsw i32 %28, 1
%30 = load i32, i32* %5
%31 = sub nsw i32 %29, %30
%32 = load i32, i32* %6
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
%35 = sub nsw i32 %32, %34
%36 = icmp sgt i32 %31, %35
br i1 %36, label %37, label %46
37: ; preds = %23
%38 = load %struct.IndexEntry*, %struct.IndexEntry** %4
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %6
%42 = load %struct.IndexEntry*, %struct.IndexEntry** %4
%43 = load i32, i32* %5
%44 = load i32, i32* %8
%45 = sub nsw i32 %44, 1
br label %55
46: ; preds = %23
%47 = load %struct.IndexEntry*, %struct.IndexEntry** %4
%48 = load i32, i32* %5
%49 = load i32, i32* %8
%50 = sub nsw i32 %49, 1
%51 = load %struct.IndexEntry*, %struct.IndexEntry** %4
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
%54 = load i32, i32* %6
br label %55
55: ; preds = %46, %37
br label %56
56: ; preds = %55, %18
br label %57
57: ; preds = %56, %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 %27
6: ; preds = %3, %25
%7 = phi i32 [ %21, %25 ], [ %4, %3 ]
%8 = phi i32 [ %12, %25 ], [ %2, %3 ]
%9 = phi i32 [ %20, %25 ], [ %1, %3 ]
br label %10
10: ; preds = %6, %23
%11 = phi i32 [ %7, %6 ], [ %19, %23 ]
%12 = phi i32 [ %8, %6 ], [ %18, %23 ]
%13 = icmp ult i32 %11, 16
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @insertionSortMemory(%struct.IndexEntry* %0, i32 %9, i32 %12)
br label %27
16: ; preds = %10
%17 = tail call i32 @partitionMemory(%struct.IndexEntry* %0, i32 %9, i32 %12)
%18 = add nsw i32 %17, -1
%19 = sub nsw i32 %18, %9
%20 = add nsw i32 %17, 1
%21 = sub nsw i32 %12, %20
%22 = icmp sgt i32 %19, %21
br i1 %22, label %23, label %25
23: ; preds = %16
tail call void @quickSortMemory(%struct.IndexEntry* %0, i32 %20, i32 %12)
%24 = icmp sgt i32 %19, 0
br i1 %24, label %10, label %27
25: ; preds = %16
tail call void @quickSortMemory(%struct.IndexEntry* %0, i32 %9, i32 %18)
%26 = icmp sgt i32 %21, 0
br i1 %26, label %6, label %27
27: ; preds = %25, %23, %3, %14
ret void
}