#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 _collection[], int _size, int _left, int _right) {
  int middle;
  if (_right > _left) {
    middle = (_left + _right) / 2;
    merge_sort(_collection, _size / 2, _left, middle);
    merge_sort(_collection, _size / 2, middle + 1, _right);
    merge(_collection, _size, _left, middle, _right);
  }
}


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    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11a3 <merge_sort+0x83>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%ecx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    %edx,%ecx
jle    118b <merge_sort+0x6b>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %esi,%r15d
mov    %rdi,%r12
lea    (%r14,%r13,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %esi,%ebx
shr    $0x1f,%ebx
add    %esi,%ebx
sar    %ebx
mov    %ebx,%esi
mov    %ebp,%ecx
call   1040 <merge_sort@plt>
lea    0x1(%rbp),%edx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14d,%ecx
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r13d,%edx
mov    %ebp,%ecx
mov    %r14d,%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* %8
%11 = load i32, i32* %7
%12 = icmp sgt i32 %10, %11
br i1 %12, label %13, label %35
13: ; preds = %4
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = add nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %6
%20 = sdiv i32 %19, 2
%21 = load i32, i32* %7
%22 = load i32, i32* %9
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = sdiv i32 %24, 2
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
%28 = load i32, i32* %8
%29 = load i32*, i32** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = call i32 @merge(i32* %29, i32 %30, i32 %31, i32 %32, i32 %33)
br label %35
35: ; preds = %13, %4
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 = add nsw i32 %3, %2
%9 = sdiv i32 %8, 2
%10 = sdiv i32 %1, 2
tail call void @merge_sort(i32* %0, i32 %10, i32 %2, i32 %9)
%11 = add nsw i32 %9, 1
tail call void @merge_sort(i32* %0, i32 %10, i32 %11, i32 %3)
%12 = tail call i32 @merge(i32* %0, i32 %1, i32 %2, i32 %9, i32 %3)
br label %6
}