#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 split(int length, int array[]) {
  if (length < 2) {
    return;
  }
  int left_num = length / 2;
  int right_num = length - left_num;
  int left[left_num];
  int right[right_num];
  for (int i = 0; i < left_num; i++) {
    left[i] = array[i];
  }
  for (int j = 0; j < right_num; j++) {
    right[j] = array[j + left_num];
  }
  split(left_num, left);
  split(right_num, right);
  merge(left_num, left, right_num, right, array);
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    113e <split+0x1e>
jmp    1248 <split+0x128>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
sar    %eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d6 <split+0xb6>
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x34(%rbp),%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a6 <split+0x86>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1212 <split+0xf2>
mov    -0x40(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x38(%rbp),%edx
add    -0x14(%rbp),%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%edx
movslq -0x38(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11dd <split+0xbd>
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edi
call   1030 <split@plt>
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edi
call   1030 <split@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rcx
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%r8
call   1040 <merge@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
cmp    $0x2,%edi
jl     11f8 <split+0xc8>
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r13d
mov    %rsp,-0x38(%rbp)
mov    %edi,%ebx
shr    %ebx
mov    %edi,%r15d
sub    %ebx,%r15d
mov    %rsp,%r12
lea    0xf(,%rbx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xf(,%r15,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
lea    0x0(,%rbx,4),%rdx
mov    %r12,%rdi
mov    %rsi,-0x30(%rbp)
call   1040 <memcpy@plt>
test   %r15d,%r15d
jle    11bd <split+0x8d>
mov    -0x30(%rbp),%rax
lea    (%rax,%rbx,4),%rsi
mov    %ebx,%eax
not    %eax
add    %r13d,%eax
lea    0x4(,%rax,4),%rdx
mov    %r14,%rdi
call   1040 <memcpy@plt>
mov    %ebx,%edi
mov    %r12,%rsi
call   1030 <split@plt>
mov    %r15d,%edi
mov    %r14,%rsi
call   1030 <split@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
mov    -0x30(%rbp),%r8
call   1050 <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 @split(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
br label %71
15: ; preds = %2
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = sub nsw i32 %18, %19
store i32 %20, i32* %6
%21 = load i32, i32* %5
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %7
%24 = alloca i32, i64 %22
store i64 %22, i64* %8
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = alloca i32, i64 %26
store i64 %26, i64* %9
store i32 0, i32* %10
br label %28
28: ; preds = %41, %15
%29 = load i32, i32* %10
%30 = load i32, i32* %5
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %44
32: ; preds = %28
%33 = load i32*, i32** %4
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %24, i64 %39
store i32 %37, i32* %40
br label %41
41: ; preds = %32
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %28
44: ; preds = %28
store i32 0, i32* %11
br label %45
45: ; preds = %60, %44
%46 = load i32, i32* %11
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %63
49: ; preds = %45
%50 = load i32*, i32** %4
%51 = load i32, i32* %11
%52 = load i32, i32* %5
%53 = add nsw i32 %51, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %50, i64 %54
%56 = load i32, i32* %55
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %27, i64 %58
store i32 %56, i32* %59
br label %60
60: ; preds = %49
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
br label %45
63: ; preds = %45
%64 = load i32, i32* %5
%65 = load i32, i32* %6
%66 = load i32, i32* %5
%67 = load i32, i32* %6
%68 = load i32*, i32** %4
%69 = call i32 @merge(i32 %66, i32* %24, i32 %67, i32* %27, i32* %68)
%70 = load i8*, i8** %7
br label %71
71: ; preds = %63, %14
ret void
}

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