#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);
  }
  return 0;
}


x86 assembly (clang, -O0):
<mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1192 <mergesort+0x72>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%ecx
call   1030 <merge@plt>
xor    %eax,%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
xor    %eax,%eax
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
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %33
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
%16 = sdiv i32 %15, 2
%17 = add nsw i32 %12, %16
store i32 %17, i32* %7
%18 = load i32*, i32** %4
%19 = load i32, i32* %5
%20 = load i32, i32* %7
%21 = call i32 @mergesort(i32* %18, i32 %19, i32 %20)
%22 = load i32*, i32** %4
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %6
%26 = call i32 @mergesort(i32* %22, i32 %24, i32 %25)
%27 = load i32*, i32** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %6
%32 = call i32 @merge(i32* %27, i32 %28, i32 %30, i32 %31)
br label %33
33: ; preds = %11, %3
ret i32 0
}

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 0
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
}