#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);
void mergesort(int array[], int length) {
  int middle;
  int *left, *right;
  int llength;
  if (length <= 1)
    return;
  middle = length / 2;
  llength = length - middle;
  left = array;
  right = array + llength;
  mergesort(left, llength);
  mergesort(right, middle);
  merge(left, llength, right, middle);
}


x86 assembly (clang, -O0):
<mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jg     113e <mergesort+0x1e>
jmp    119b <mergesort+0x7b>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <mergesort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <mergesort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%ecx
call   1030 <merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort>:
cmp    $0x1,%esi
jg     1126 <mergesort+0x6>
ret
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %esi,%ebp
shr    %ebp
sub    %ebp,%esi
movslq %esi,%r14
lea    (%rdi,%r14,4),%r15
mov    %r14d,%esi
call   1040 <mergesort@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <mergesort@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>

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

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