#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*/ insertionsort(int *, int);
int /*<<< orphan*/ merge(int *, int, int, int);
void mergesort(int array[], int low, int high) {
  int mid = (low + high) / 2;
  if (low < high) {
    if (high - low < 5) {
      insertionsort(array, (high - low + 1));
    }
    mergesort(array, low, mid);
    mergesort(array, mid + 1, high);
    merge(array, low, mid, high);
  }
}


x86 assembly (clang, -O0):
<mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b3 <mergesort+0x83>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x5,%eax
jge    1180 <mergesort+0x50>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
add    $0x1,%esi
call   1030 <insertionsort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %edx,%esi
sub    %r12d,%esi
jle    119b <mergesort+0x6b>
mov    %edx,%r14d
mov    %rdi,%r15
lea    (%r14,%r12,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
cmp    $0x4,%esi
jg     1165 <mergesort+0x35>
add    $0x1,%esi
mov    %r15,%rdi
call   1030 <insertionsort@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1050 <mergesort@plt>
lea    0x1(%rbx),%esi
mov    %r15,%rdi
mov    %r14d,%edx
call   1050 <mergesort@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <merge@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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