#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, int *);
int merge_sort(int len, int *num) {
  ;
  if (len == 1) {
    return 0;
  }
  int mid = len / 2;
  merge_sort(mid, num);
  merge_sort(len - mid, &num[mid]);
  merge(mid, num, len - mid, &num[mid], len, num);
  return 0;
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1145 <merge_sort+0x25>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <merge_sort+0x89>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <merge_sort@plt>
mov    -0x8(%rbp),%edi
sub    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <merge_sort@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
sub    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x8(%rbp),%r8d
mov    -0x10(%rbp),%r9
call   1030 <merge@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    $0x1,%edi
je     1178 <merge_sort+0x58>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x1f,%ebp
add    %edi,%ebp
sar    %ebp
mov    %ebp,%edi
call   1040 <merge_sort@plt>
mov    %ebx,%r15d
sub    %ebp,%r15d
movslq %ebp,%rbp
lea    (%r14,%rbp,4),%r12
mov    %r15d,%edi
mov    %r12,%rsi
call   1040 <merge_sort@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %r12,%rcx
mov    %ebx,%r8d
mov    %r14,%r9
call   1030 <merge@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @merge_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* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %36
10: ; preds = %2
%11 = load i32, i32* %4
%12 = sdiv i32 %11, 2
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = load i32*, i32** %5
%15 = call i32 @merge_sort(i32 %13, i32* %14)
%16 = load i32, i32* %4
%17 = load i32, i32* %6
%18 = sub nsw i32 %16, %17
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @merge_sort(i32 %18, i32* %22)
%24 = load i32, i32* %6
%25 = load i32*, i32** %5
%26 = load i32, i32* %4
%27 = load i32, i32* %6
%28 = sub nsw i32 %26, %27
%29 = load i32*, i32** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %4
%34 = load i32*, i32** %5
%35 = call i32 @merge(i32 %24, i32* %25, i32 %28, i32* %32, i32 %33, i32* %34)
store i32 0, i32* %3
br label %36
36: ; preds = %10, %9
%37 = load i32, i32* %3
ret i32 %37
}

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