#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 *sort(int a[], int n) {
  if (n < 2)
    return a;
  int m = n / 2;
  sort(a, m);
  sort(a + m, n - m);
  merge(a, n, m);
  return a;
}


x86 assembly (clang, -O0):
<sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1146 <sort+0x26>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1191 <sort+0x71>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <sort@plt>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x18(%rbp),%esi
call   1030 <sort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <merge@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
cmp    $0x1,%esi
jle    1155 <sort+0x35>
mov    %esi,%ebp
mov    %esi,%ebx
shr    %ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <sort@plt>
lea    (%r14,%rbx,4),%rdi
mov    %ebp,%esi
sub    %ebx,%esi
call   1030 <sort@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <merge@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32* @sort(i32* returned %0, i32 %1) {
%3 = icmp slt i32 %1, 2
br i1 %3, label %4, label %5
4: ; preds = %2, %5
ret i32* %0
5: ; preds = %2
%6 = lshr i32 %1, 1
%7 = tail call i32* @sort(i32* %0, i32 %6)
%8 = zext i32 %6 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = sub nsw i32 %1, %6
%11 = tail call i32* @sort(i32* %9, i32 %10)
%12 = tail call i32 @merge(i32* %0, i32 %1, i32 %6)
br label %4
}