#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*/ assert(int *);
int /*<<< orphan*/ merge_version2(int *, int, int, int);
void merge_sort(int *arr, int begin, int end) {
  int m;
  assert(arr);
  if (end <= begin)
    return;
  m = (begin + end) / 2;
  merge_sort(arr, begin, m);
  merge_sort(arr, m + 1, end);
  merge_version2(arr, begin, m, end);
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     115c <merge_sort+0x2c>
jmp    11a0 <merge_sort+0x70>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1050 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <merge_version2@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
call   1030 <assert@plt>
cmp    %r15d,%r14d
jle    118e <merge_sort+0x5e>
lea    (%r14,%r15,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
call   1050 <merge_sort@plt>
lea    0x1(%rbx),%esi
mov    %r12,%rdi
mov    %r14d,%edx
call   1050 <merge_sort@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <merge_version2@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @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** %4
%9 = call i32 @assert(i32* %8)
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %3
br label %31
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %17, 2
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 = add nsw i32 %23, 1
%25 = load i32, i32* %6
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = call i32 @merge_version2(i32* %26, i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %14, %13
ret void
}

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