#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(long *, long, long, long);
void merge_sort(long arr[], long start, long end) {
  long mid = 0;
  if (start < end) {
    mid = start + ((end - start) >> 1);
    merge_sort(arr, start, mid);
    merge_sort(arr, mid + 1, end);
    merge(arr, start, mid, end);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    119c <merge_sort+0x7c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    -0x10(%rbp),%rcx
sar    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
sub    %rsi,%rbx
jle    1176 <merge_sort+0x56>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
sar    %rbx
lea    (%rbx,%rsi,1),%r12
mov    %r12,%rdx
call   1040 <merge_sort@plt>
lea    (%rbx,%r13,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <merge_sort@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <merge@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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