#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 *, int, int, int, size_t,
                         int (*)(void *, void *));
void mergesort(void *v, int l, int r, size_t size,
               int (*compare)(void *a, void *b)) {
  int q = (l + r) / 2;
  if (r <= l)
    return;
  mergesort(v, l, q, size, compare);
  mergesort(v, q + 1, r, size, compare);
  merge(v, l, q, r, size, compare);
}


x86 assembly (clang, -O0):
<mergesort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     115c <mergesort+0x3c>
jmp    11a7 <mergesort+0x87>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <mergesort@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
call   1030 <merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort>:
cmp    %esi,%edx
jle    1188 <mergesort+0x68>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r13
lea    (%r12,%rbx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebp,%edx
call   1040 <mergesort@plt>
lea    0x1(%rbp),%esi
mov    %r13,%rdi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <mergesort@plt>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %r15,%r8
mov    %r14,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <merge@plt>
ret

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

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