#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 mergeSort(int *a, int start, int end) {
  if (start + 1 < end) {
    int mid = (end - start) / 2 + start;
    mergeSort(a, start, mid);
    mergeSort(a, mid, end);
    merge(a, start, mid, end);
  }
}


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    $0x1,%eax
cmp    -0x10(%rbp),%eax
jge    1185 <mergeSort+0x65>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <mergeSort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <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   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
lea    0x1(%rbx),%eax
cmp    %edx,%eax
jge    1174 <mergeSort+0x54>
mov    %edx,%r15d
mov    %rdi,%r14
mov    %edx,%eax
sub    %ebx,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
add    %ebx,%ebp
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <mergeSort@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1030 <mergeSort@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 = add nsw i32 %8, 1
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %30
12: ; preds = %3
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
%16 = sdiv i32 %15, 2
%17 = load i32, i32* %5
%18 = add nsw i32 %16, %17
store i32 %18, i32* %7
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = load i32*, i32** %4
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = call i32 @merge(i32* %25, i32 %26, i32 %27, i32 %28)
br label %30
30: ; preds = %12, %3
ret void
}

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