#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 _mergesort(int *l, int *tmp, int left, int right) {
  if (right > left) {
    int center = left + ((right - left) / 2);
    _mergesort(l, tmp, left, center);
    _mergesort(l, tmp, center + 1, right);
    merge(l, tmp, left, center, right);
  }
}


x86 assembly (clang, -O0):
<_mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11a0 <_mergesort+0x80>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <_mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1040 <_mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <merge@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mergesort>:
mov    %ecx,%eax
sub    %edx,%eax
jle    1186 <_mergesort+0x66>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    (%rbx,%rbp,1),%r12d
mov    %r12d,%ecx
call   1040 <_mergesort@plt>
lea    (%rbx,%rbp,1),%edx
add    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13d,%ecx
call   1040 <_mergesort@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>
ret

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

LLVM IR (-O2):
define void @_mergesort(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, %2
br i1 %5, label %7, label %6
6: ; preds = %4, %7
ret void
7: ; preds = %4
%8 = sub nsw i32 %3, %2
%9 = sdiv i32 %8, 2
%10 = add nsw i32 %9, %2
tail call void @_mergesort(i32* %0, i32* %1, i32 %2, i32 %10)
%11 = add nsw i32 %10, 1
tail call void @_mergesort(i32* %0, i32* %1, i32 %11, i32 %3)
%12 = tail call i32 @merge(i32* %0, i32* %1, i32 %2, i32 %10, i32 %3)
br label %6
}