#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);
void merge_sort(int *data, int start, int end) {
  if (start == end) {
    return;
  }
  int mid = (start + end) / 2;
  if (start < end) {
    merge_sort(data, start, mid);
    merge_sort(data, mid + 1, end);
    merge(data, start, 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
cmp    -0x10(%rbp),%eax
jne    1143 <merge_sort+0x23>
jmp    1190 <merge_sort+0x70>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1190 <merge_sort+0x70>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

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