#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*/ _merge(int *, int, int, int);
void top_down_merge_sort(int *array, int start, int end) {
  int middle = (end + start) / 2;
  if (end - start < 2)
    return;
  top_down_merge_sort(array, start, middle);
  top_down_merge_sort(array, middle, end);
  _merge(array, start, middle, end);
}


x86 assembly (clang, -O0):
<top_down_merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x2,%eax
jge    1157 <top_down_merge_sort+0x37>
jmp    1187 <top_down_merge_sort+0x67>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <top_down_merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <top_down_merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <_merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<top_down_merge_sort>:
mov    %edx,%eax
sub    %esi,%eax
cmp    $0x1,%eax
jg     112a <top_down_merge_sort+0xa>
ret
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%edx
call   1040 <top_down_merge_sort@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <top_down_merge_sort@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_merge@plt>

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

LLVM IR (-O2):
define void @top_down_merge_sort(i32* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, %1
%5 = sdiv i32 %4, 2
%6 = sub nsw i32 %2, %1
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %9
8: ; preds = %3, %9
ret void
9: ; preds = %3
tail call void @top_down_merge_sort(i32* %0, i32 %1, i32 %5)
tail call void @top_down_merge_sort(i32* %0, i32 %5, i32 %2)
%10 = tail call i32 @_merge(i32* %0, i32 %1, i32 %5, i32 %2)
br label %8
}