#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*/ mergeSortMerge(double *, int *, int *, int, int, int);
void mergeSortWithinBounds(double *array, int *sorted, int *tosort, int p,
                           int q) {
  int r;
  if (p < q) {
    r = (p + q) / 2;
    mergeSortWithinBounds(array, sorted, tosort, p, r);
    mergeSortWithinBounds(array, sorted, tosort, r + 1, q);
    mergeSortMerge(array, sorted, tosort, p, r + 1, q);
  }
}


x86 assembly (clang, -O0):
<mergeSortWithinBounds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11ab <mergeSortWithinBounds+0x8b>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1040 <mergeSortWithinBounds@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%r8d
call   1040 <mergeSortWithinBounds@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%r8d
add    $0x1,%r8d
mov    -0x20(%rbp),%r9d
call   1030 <mergeSortMerge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergeSortWithinBounds>:
cmp    %r8d,%ecx
jge    118d <mergeSortWithinBounds+0x6d>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    (%r14,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%r8d
call   1040 <mergeSortWithinBounds@plt>
add    $0x1,%ebp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1040 <mergeSortWithinBounds@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <mergeSortMerge@plt>
ret

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

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