#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 merge(int *, int, int);
int merge_sort(int ar[], int start, int n) {
  if (n > 1) {
    int rA, rB, r;
    int half = n / 2;
    rA = merge_sort(ar, start, half);
    rB = merge_sort(ar, start + half, n - half);
    r = merge(ar, start, n);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    1186 <merge_sort+0x66>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1040 <merge_sort@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    -0x28(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    -0x28(%rbp),%edx
call   1040 <merge_sort@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <merge@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    $0x1,%edx
jle    1167 <merge_sort+0x47>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %edx,%ebx
shr    %ebx
mov    %ebx,%edx
call   1040 <merge_sort@plt>
mov    %ebp,%edx
sub    %ebx,%edx
add    %r14d,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <merge_sort@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <merge@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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