#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_array(int *, int, int *, int);
void merge_sort(int *array, int count) {
  if (count > 1) {
    int *array1 = array;
    int count1 = count / 2;
    int *array2 = array + count1;
    int count2 = count - count1;
    merge_sort(array1, count1);
    merge_sort(array2, count2);
    merge_array(array1, count1, array2, count2);
  }
}


x86 assembly (clang, -O0):
<merge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    1196 <merge_sort+0x76>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <merge_sort@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <merge_sort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <merge_array@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_sort>:
cmp    $0x1,%esi
jle    116c <merge_sort+0x4c>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%r15d
shr    %r15d
lea    (%rdi,%r15,4),%r12
sub    %r15d,%ebx
mov    %r15d,%esi
call   1040 <merge_sort@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <merge_sort@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <merge_array@plt>
ret

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

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