#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 floor(int);
void MergeSort(int a[], int start, int end) {
  if (end - start > 0) {
    MergeSort(a, start, floor((start + end) / 2));
    MergeSort(a, floor((start + end) / 2) + 1, end);
    Merge(a, start, end);
  }
}


x86 assembly (clang, -O0):
<MergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x0,%eax
jle    11bf <MergeSort+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
call   1040 <MergeSort@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <floor@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <MergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <Merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MergeSort>:
cmp    %esi,%edx
jle    118f <MergeSort+0x5f>
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,%edi
call   1050 <floor@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <MergeSort@plt>
mov    %ebp,%edi
call   1050 <floor@plt>
lea    0x1(%rax),%esi
mov    %r15,%rdi
mov    %r14d,%edx
call   1040 <MergeSort@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <Merge@plt>
ret

LLVM IR (-O0):
define void @MergeSort(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = load i32, i32* %5
%9 = sub nsw i32 %7, %8
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = load i32, i32* %5
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = add nsw i32 %14, %15
%17 = sdiv i32 %16, 2
%18 = call i32 @floor(i32 %17)
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = add nsw i32 %20, %21
%23 = sdiv i32 %22, 2
%24 = call i32 @floor(i32 %23)
%25 = add nsw i32 %24, 1
%26 = load i32, i32* %6
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call i32 @Merge(i32* %27, i32 %28, i32 %29)
br label %31
31: ; preds = %11, %3
ret void
}

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