#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 *);
void merge_sort(int x[], int size) {
  if (size == 1)
    return;
  int left[size / 2], right[size - size / 2], i;
  register int l_size = size / 2, r_size = size - size / 2;
  for (i = 0; i < l_size; i++)
    left[i] = x[i];
  for (i = 0; i < r_size; i++)
    right[i] = x[i + l_size];
  merge_sort(left, l_size);
  merge_sort(right, r_size);
  merge(left, l_size, right, r_size, x);
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    113e <merge_sort+0x1e>
jmp    126d <merge_sort+0x14d>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
sar    %eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%edx
shr    $0x1f,%edx
mov    %eax,%ecx
add    %edx,%ecx
sar    %ecx
sub    %ecx,%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    11fb <merge_sort+0xdb>
mov    -0x48(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cb <merge_sort+0xab>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    1237 <merge_sort+0x117>
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x2c(%rbp),%edx
add    -0x30(%rbp),%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1202 <merge_sort+0xe2>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1040 <merge_sort@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1040 <merge_sort@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%ecx
mov    -0x8(%rbp),%r8
call   1030 <merge@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    $0x1,%esi
je     120c <merge_sort+0xdc>
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r13d
mov    %rdi,-0x30(%rbp)
mov    %rsp,-0x38(%rbp)
mov    %esi,%ebx
shr    $0x1f,%ebx
add    %esi,%ebx
sar    %ebx
lea    0xf(,%rbx,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %esi,%r12d
sub    %ebx,%r12d
lea    0xf(,%r12,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
cmp    $0x2,%esi
jl     11aa <merge_sort+0x7a>
lea    -0x1(%rbx),%eax
lea    0x4(,%rax,4),%rdx
mov    %r15,%rdi
mov    -0x30(%rbp),%rsi
call   1030 <memcpy@plt>
test   %r12d,%r12d
jle    11d1 <merge_sort+0xa1>
movslq %ebx,%rax
mov    -0x30(%rbp),%rcx
lea    (%rcx,%rax,4),%rsi
mov    %ebx,%eax
not    %eax
add    %r13d,%eax
lea    0x4(,%rax,4),%rdx
mov    %r14,%rdi
call   1030 <memcpy@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <merge_sort@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1050 <merge_sort@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %r12d,%ecx
mov    -0x30(%rbp),%r8
call   1040 <merge@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @merge_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
br label %75
14: ; preds = %2
%15 = load i32, i32* %4
%16 = sdiv i32 %15, 2
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %5
%19 = alloca i32, i64 %17
store i64 %17, i64* %6
%20 = load i32, i32* %4
%21 = load i32, i32* %4
%22 = sdiv i32 %21, 2
%23 = sub nsw i32 %20, %22
%24 = zext i32 %23 to i64
%25 = alloca i32, i64 %24
store i64 %24, i64* %7
%26 = load i32, i32* %4
%27 = sdiv i32 %26, 2
store i32 %27, i32* %9
%28 = load i32, i32* %4
%29 = load i32, i32* %4
%30 = sdiv i32 %29, 2
%31 = sub nsw i32 %28, %30
store i32 %31, i32* %10
store i32 0, i32* %8
br label %32
32: ; preds = %45, %14
%33 = load i32, i32* %8
%34 = load i32, i32* %9
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i32*, i32** %3
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %19, i64 %43
store i32 %41, i32* %44
br label %45
45: ; preds = %36
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %32
48: ; preds = %32
store i32 0, i32* %8
br label %49
49: ; preds = %64, %48
%50 = load i32, i32* %8
%51 = load i32, i32* %10
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %67
53: ; preds = %49
%54 = load i32*, i32** %3
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = add nsw i32 %55, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %54, i64 %58
%60 = load i32, i32* %59
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %25, i64 %62
store i32 %60, i32* %63
br label %64
64: ; preds = %53
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %49
67: ; preds = %49
%68 = load i32, i32* %9
%69 = load i32, i32* %10
%70 = load i32, i32* %9
%71 = load i32, i32* %10
%72 = load i32*, i32** %3
%73 = call i32 @merge(i32* %19, i32 %70, i32* %25, i32 %71, i32* %72)
%74 = load i8*, i8** %5
br label %75
75: ; preds = %67, %13
ret void
}

LLVM IR (-O2):
define void @merge_sort(i32* %0, i32 %1) {
%3 = bitcast i32* %0 to i8*
%4 = icmp eq i32 %1, 1
br i1 %4, label %34, label %5
5: ; preds = %2
%6 = sdiv i32 %1, 2
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7
%10 = sub nsw i32 %1, %6
%11 = zext i32 %10 to i64
%12 = alloca i32, i64 %11
%13 = bitcast i32* %12 to i8*
%14 = icmp sgt i32 %1, 1
br i1 %14, label %15, label %21
15: ; preds = %5
%16 = bitcast i32* %9 to i8*
%17 = add nsw i32 %6, -1
%18 = zext i32 %17 to i64
%19 = shl nuw nsw i64 %18, 2
%20 = add nuw nsw i64 %19, 4
br label %21
21: ; preds = %15, %5
%22 = icmp sgt i32 %10, 0
br i1 %22, label %23, label %32
23: ; preds = %21
%24 = sext i32 %6 to i64
%25 = getelementptr i32, i32* %0, i64 %24
%26 = bitcast i32* %25 to i8*
%27 = xor i32 %6, -1
%28 = add i32 %27, %1
%29 = zext i32 %28 to i64
%30 = shl nuw nsw i64 %29, 2
%31 = add nuw nsw i64 %30, 4
br label %32
32: ; preds = %23, %21
%33 = call i32 @merge(i32* %9, i32 %6, i32* %12, i32 %10, i32* %0)
br label %34
34: ; preds = %2, %32
ret void
}