#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(void *, void *, int, int, int, size_t,
                         int (*)(void const *, void const *));
void mergesort_rec(void *base, void *helper, int left, int right, size_t size,
                   int (*compare)(const void *, const void *)) {
  int mid;
  if (right > left) {
    mid = (right + left) / 2;
    mergesort_rec(base, helper, left, mid, size, compare);
    mergesort_rec(base, helper, (mid + 1), right, size, compare);
    merge(base, helper, left, mid, right, size, compare);
  }
}


x86 assembly (clang, -O0):
<mergesort_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11b7 <mergesort_rec+0x97>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1040 <mergesort_rec@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1040 <mergesort_rec@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <merge@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort_rec>:
cmp    %edx,%ecx
jle    11a3 <mergesort_rec+0x83>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,%ebx
lea    (%r12,%rbx,1),%eax
mov    %eax,%r14d
shr    $0x1f,%r14d
add    %eax,%r14d
sar    %r14d
mov    %rdi,%r15
mov    %rsi,%rbp
mov    %r14d,%ecx
mov    %r8,0x10(%rsp)
mov    %r9,%r13
call   1040 <mergesort_rec@plt>
lea    0x1(%r14),%edx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r12d,%ecx
mov    0x10(%rsp),%r8
mov    %r13,%r9
call   1040 <mergesort_rec@plt>
mov    %r13,(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %r12d,%r8d
mov    0x10(%rsp),%r9
call   1030 <merge@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
ret

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

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