#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*/ _helper_insertion_sort(int *, int, int);
int _partition(int *, int, int);
void _optimize_quick_sort(int *array, int low, int high) {
  if (low >= high)
    return;
  if ((high - low) < 10) {
    _helper_insertion_sort(array, low, high);
    return;
  }
  int partition_index = _partition(array, low, high);
  _optimize_quick_sort(array, low, partition_index - 1);
  _optimize_quick_sort(array, partition_index + 1, high);
}


x86 assembly (clang, -O0):
<_optimize_quick_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1153 <_optimize_quick_sort+0x23>
jmp    11ac <_optimize_quick_sort+0x7c>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0xa,%eax
jge    1176 <_optimize_quick_sort+0x46>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <_helper_insertion_sort@plt>
jmp    11ac <_optimize_quick_sort+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <_partition@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <_optimize_quick_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1030 <_optimize_quick_sort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_optimize_quick_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %esi,%edx
jle    1180 <_optimize_quick_sort+0x50>
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%eax
sub    %ebp,%eax
cmp    $0x9,%eax
jle    118b <_optimize_quick_sort+0x5b>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1050 <_partition@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <_optimize_quick_sort@plt>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %r15d,%ebx
jl     1150 <_optimize_quick_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_helper_insertion_sort@plt>

LLVM IR (-O0):
define void @_optimize_quick_sort(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* %5
%9 = load i32, i32* %6
%10 = icmp sge i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %3
br label %35
12: ; preds = %3
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
%16 = icmp slt i32 %15, 10
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @_helper_insertion_sort(i32* %18, i32 %19, i32 %20)
br label %35
22: ; preds = %12
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = call i32 @_partition(i32* %23, i32 %24, i32 %25)
store i32 %26, i32* %7
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 1
%31 = load i32*, i32** %4
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %6
br label %35
35: ; preds = %22, %17, %11
ret void
}

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