#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, int);
void merge_sort(int *arr, int *bufferArr, int begin, int last) {
  if (begin == last)
    return;
  if (begin < last) {
    int mid = begin + (last - begin) / 2;
    merge_sort(arr, bufferArr, begin, mid);
    merge_sort(arr, bufferArr, mid + 1, last);
    merge(arr, bufferArr, begin, mid, last);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1147 <merge_sort+0x27>
jmp    11b1 <merge_sort+0x91>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b1 <merge_sort+0x91>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
mov    %ecx,%eax
sub    %edx,%eax
jle    1186 <merge_sort+0x66>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    (%rbx,%rbp,1),%r12d
mov    %r12d,%ecx
call   1040 <merge_sort@plt>
lea    (%rbx,%rbp,1),%edx
add    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13d,%ecx
call   1040 <merge_sort@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>
ret

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

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