#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 /*<<< orphan*/ _merge(int *, int *, int, int, int);
void _optimize_merge_sort(int *array, int *aux, int low, int high) {
  if (low >= high)
    return;
  if ((high - low) < 15) {
    _helper_insertion_sort(array, low, high);
    return;
  }
  int mid = low + (high - low) / 2;
  _optimize_merge_sort(array, aux, low, mid);
  _optimize_merge_sort(array, aux, mid + 1, high);
  if (array[mid] < array[mid + 1]) {
    return;
  }
  _merge(array, aux, low, mid, high);
}


x86 assembly (clang, -O0):
<_optimize_merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1157 <_optimize_merge_sort+0x27>
jmp    11fe <_optimize_merge_sort+0xce>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0xf,%eax
jge    117a <_optimize_merge_sort+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <_helper_insertion_sort@plt>
jmp    11fe <_optimize_merge_sort+0xce>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <_optimize_merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1030 <_optimize_merge_sort@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jge    11e7 <_optimize_merge_sort+0xb7>
jmp    11fe <_optimize_merge_sort+0xce>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1040 <_merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_optimize_merge_sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
sub    %edx,%ebp
jle    11a2 <_optimize_merge_sort+0x72>
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %rdi,%r13
cmp    $0xe,%ebp
jg     1169 <_optimize_merge_sort+0x39>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_helper_insertion_sort@plt>
mov    %rsi,%r14
shr    %ebp
lea    (%rbx,%rbp,1),%r12d
mov    %r13,%rdi
mov    %ebx,%edx
mov    %r12d,%ecx
call   1030 <_optimize_merge_sort@plt>
lea    (%rbx,%rbp,1),%edx
add    $0x1,%edx
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r15d,%ecx
call   1030 <_optimize_merge_sort@plt>
movslq %r12d,%rax
mov    0x0(%r13,%rax,4),%ecx
cmp    0x4(%r13,%rax,4),%ecx
jge    11b1 <_optimize_merge_sort+0x81>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_merge@plt>

LLVM IR (-O0):
define void @_optimize_merge_sort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = load i32, i32* %8
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %4
br label %60
14: ; preds = %4
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = sub nsw i32 %15, %16
%18 = icmp slt i32 %17, 15
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32*, i32** %5
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i32 @_helper_insertion_sort(i32* %20, i32 %21, i32 %22)
br label %60
24: ; preds = %14
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = sub nsw i32 %26, %27
%29 = sdiv i32 %28, 2
%30 = add nsw i32 %25, %29
store i32 %30, i32* %9
%31 = load i32*, i32** %5
%32 = load i32*, i32** %6
%33 = load i32, i32* %7
%34 = load i32, i32* %9
%35 = load i32*, i32** %5
%36 = load i32*, i32** %6
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
%39 = load i32, i32* %8
%40 = load i32*, i32** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = load i32*, i32** %5
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
%50 = load i32, i32* %49
%51 = icmp slt i32 %44, %50
br i1 %51, label %52, label %53
52: ; preds = %24
br label %60
53: ; preds = %24
%54 = load i32*, i32** %5
%55 = load i32*, i32** %6
%56 = load i32, i32* %7
%57 = load i32, i32* %9
%58 = load i32, i32* %8
%59 = call i32 @_merge(i32* %54, i32* %55, i32 %56, i32 %57, i32 %58)
br label %60
60: ; preds = %53, %52, %19, %13
ret void
}

LLVM IR (-O2):
define void @_optimize_merge_sort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, %2
br i1 %5, label %6, label %24
6: ; preds = %4
%7 = sub nsw i32 %3, %2
%8 = icmp slt i32 %7, 15
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @_helper_insertion_sort(i32* %0, i32 %2, i32 %3)
br label %24
11: ; preds = %6
%12 = lshr i32 %7, 1
%13 = add nsw i32 %12, %2
tail call void @_optimize_merge_sort(i32* %0, i32* %1, i32 %2, i32 %13)
%14 = add nsw i32 %13, 1
tail call void @_optimize_merge_sort(i32* %0, i32* %1, i32 %14, i32 %3)
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = sext i32 %14 to i64
%19 = getelementptr inbounds i32, i32* %0, i64 %18
%20 = load i32, i32* %19
%21 = icmp slt i32 %17, %20
br i1 %21, label %24, label %22
22: ; preds = %11
%23 = tail call i32 @_merge(i32* %0, i32* %1, i32 %2, i32 %13, i32 %3)
br label %24
24: ; preds = %22, %11, %4, %9
ret void
}