#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);
void merge_sort(int *list, int begin, int end) {
  int middle = (begin + end + 1) / 2;
  if ((end - begin) < 1) {
    return;
  }
  merge_sort(list, begin, middle - 1);
  merge_sort(list, middle, end);
  merge(list, begin, middle, 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    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x1,%eax
jge    115a <merge_sort+0x3a>
jmp    118d <merge_sort+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    %esi,%edx
jle    117b <merge_sort+0x5b>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r15
lea    (%r12,%r14,1),%eax
lea    (%r12,%r14,1),%ecx
add    $0x1,%ecx
shr    $0x1f,%ecx
lea    (%rcx,%rax,1),%ebx
add    $0x1,%ebx
sar    %ebx
lea    -0x1(%rbx),%edx
call   1040 <merge_sort@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1040 <merge_sort@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <merge@plt>
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* %5
%9 = load i32, i32* %6
%10 = add nsw i32 %8, %9
%11 = add nsw i32 %10, 1
%12 = sdiv i32 %11, 2
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %3
br label %31
18: ; preds = %3
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 1
%23 = load i32*, i32** %4
%24 = load i32, i32* %7
%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(i32* %26, i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %18, %17
ret void
}

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