#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*/ mergeRanges(int *, int, int, int);
scalar_t__ needsSorting(int);
void mergesortRange(int values[], int startIndex, int endIndex) {
  int rangeSize = endIndex - startIndex;
  if (needsSorting(rangeSize)) {
    int midPoint = (startIndex + endIndex) / 2;
    mergesortRange(values, startIndex, midPoint);
    mergesortRange(values, midPoint, endIndex);
    mergeRanges(values, startIndex, midPoint, endIndex);
  }
}


x86 assembly (clang, -O0):
<mergesortRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <needsSorting@plt>
cmp    $0x0,%rax
je     119e <mergesortRange+0x6e>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <mergesortRange@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <mergesortRange@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <mergeRanges@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesortRange>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebx
mov    %rdi,%r15
mov    %edx,%edi
sub    %esi,%edi
call   1040 <needsSorting@plt>
test   %rax,%rax
je     118c <mergesortRange+0x5c>
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <mergesortRange@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1050 <mergesortRange@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <mergeRanges@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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