#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 *);
int MergeSort(int arr[], int first, int last, int temp[]) {
  if (first == last)
    return 0;
  int mid = (first + last) / 2;
  MergeSort(arr, first, mid, temp);
  MergeSort(arr, mid + 1, last, temp);
  Merge(arr, first, mid, last, temp);
  return 0;
}


x86 assembly (clang, -O0):
<MergeSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    114e <MergeSort+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <MergeSort+0x85>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1040 <MergeSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1040 <MergeSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
call   1030 <Merge@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MergeSort>:
cmp    %edx,%esi
je     117a <MergeSort+0x5a>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%r13d
mov    %rdi,%r12
lea    (%r15,%r13,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
mov    %ebx,%edx
call   1040 <MergeSort@plt>
lea    0x1(%rbx),%esi
mov    %r12,%rdi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <MergeSort@plt>
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %r14,%r8
call   1030 <Merge@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
xor    %eax,%eax
ret

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

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