#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 */
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ sorter_binary_insertion_sort(int /*<<< orphan*/ *,
                                                size_t const);
int /*<<< orphan*/ sorter_merge_sort_recursive(int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ *,
                                               size_t const);
int /*<<< orphan*/ sorter_sort_delete_buffer(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sorter_sort_new_buffer(size_t const);
void sorter_merge_sort(int64_t *dst, const size_t size) {
  int64_t *newdst;
  if (size <= 1) {
    return;
  }
  if (size <= 16) {
    sorter_binary_insertion_sort(dst, size);
    return;
  }
  newdst = sorter_sort_new_buffer(size);
  sorter_merge_sort_recursive(newdst, dst, size);
  sorter_sort_delete_buffer(newdst);
}


x86 assembly (clang, -O0):
<sorter_merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     1160 <sorter_merge_sort+0x20>
jmp    11a4 <sorter_merge_sort+0x64>
cmpq   $0x10,-0x10(%rbp)
ja     117d <sorter_merge_sort+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <sorter_binary_insertion_sort@plt>
jmp    11a4 <sorter_merge_sort+0x64>
mov    -0x10(%rbp),%rdi
call   1030 <sorter_sort_new_buffer@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <sorter_merge_sort_recursive@plt>
mov    -0x18(%rbp),%rdi
call   1050 <sorter_sort_delete_buffer@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorter_merge_sort>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%rsi
jae    1151 <sorter_merge_sort+0x11>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    $0x10,%rsi
ja     116d <sorter_merge_sort+0x2d>
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <sorter_binary_insertion_sort@plt>
mov    %rbx,%rdi
call   1030 <sorter_sort_new_buffer@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <sorter_merge_sort_recursive@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <sorter_sort_delete_buffer@plt>

LLVM IR (-O0):
define void @sorter_merge_sort(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32*
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp ule i64 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %2
br label %25
9: ; preds = %2
%10 = load i64, i64* %4
%11 = icmp ule i64 %10, 16
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32*, i32** %3
%14 = load i64, i64* %4
%15 = call i32 @sorter_binary_insertion_sort(i32* %13, i64 %14)
br label %25
16: ; preds = %9
%17 = load i64, i64* %4
%18 = call i32* @sorter_sort_new_buffer(i64 %17)
store i32* %18, i32** %5
%19 = load i32*, i32** %5
%20 = load i32*, i32** %3
%21 = load i64, i64* %4
%22 = call i32 @sorter_merge_sort_recursive(i32* %19, i32* %20, i64 %21)
%23 = load i32*, i32** %5
%24 = call i32 @sorter_sort_delete_buffer(i32* %23)
br label %25
25: ; preds = %16, %12, %8
ret void
}

LLVM IR (-O2):
define void @sorter_merge_sort(i32* %0, i64 %1) {
%3 = icmp ult i64 %1, 2
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = icmp ult i64 %1, 17
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @sorter_binary_insertion_sort(i32* %0, i64 %1)
br label %12
8: ; preds = %4
%9 = tail call i32* @sorter_sort_new_buffer(i64 %1)
%10 = tail call i32 @sorter_merge_sort_recursive(i32* %9, i32* %0, i64 %1)
%11 = tail call i32 @sorter_sort_delete_buffer(i32* %9)
br label %12
12: ; preds = %2, %8, %6
ret void
}