#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 mergesort(int arr[], int low, int high) {
  if (low < high) {
    int mid = low + (high - low) / 2;
    mergesort(arr, low, mid);
    mergesort(arr, mid + 1, high);
    merge(arr, low, mid + 1, high);
  }
}


x86 assembly (clang, -O0):
<mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1192 <mergesort+0x72>
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    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <mergesort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1040 <mergesort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1030 <merge@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort>:
mov    %edx,%eax
sub    %esi,%eax
jle    1175 <mergesort+0x55>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r14
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    (%rbx,%rbp,1),%edx
call   1040 <mergesort@plt>
lea    (%rbx,%rbp,1),%r15d
add    $0x1,%r15d
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   1040 <mergesort@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r12d,%ecx
call   1030 <merge@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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