#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 partition(void *, int, int, size_t, int,
              int (*)(void const *, void const *));
void quicksort_rec(void *base, int begin, int end, size_t size,
                   int (*compare)(const void *, const void *)) {
  int pivot, pivotIndex;
  if (begin < end) {
    pivotIndex = (begin + end) / 2;
    pivot = partition(base, begin, end, size, pivotIndex, compare);
    quicksort_rec(base, begin, pivot - 1, size, compare);
    quicksort_rec(base, pivot + 1, end, size, compare);
  }
}


x86 assembly (clang, -O0):
<quicksort_rec>:
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
cmp    -0x10(%rbp),%eax
jge    11a9 <quicksort_rec+0x89>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8d
mov    -0x20(%rbp),%r9
call   1030 <partition@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1040 <quicksort_rec@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 <quicksort_rec@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort_rec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%esi
jge    1183 <quicksort_rec+0x63>
mov    %r8,%r14
mov    %rcx,%r15
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%r12
nopl   (%rax)
lea    (%rbx,%r13,1),%eax
mov    %eax,%r8d
shr    $0x1f,%r8d
add    %eax,%r8d
sar    %r8d
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
mov    %r15,%rcx
mov    %r14,%r9
call   1030 <partition@plt>
mov    %eax,%ebp
lea    -0x1(%rbp),%edx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <quicksort_rec@plt>
add    $0x1,%ebp
mov    %ebp,%ebx
cmp    %r13d,%ebp
jl     1140 <quicksort_rec+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @quicksort_rec(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
%12 = 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
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %40
16: ; preds = %5
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = add nsw i32 %17, %18
%20 = sdiv i32 %19, 2
store i32 %20, i32* %12
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = load i64, i64* %9
%25 = load i32, i32* %12
%26 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%27 = call i32 @partition(i8* %21, i32 %22, i32 %23, i64 %24, i32 %25, i32 (i8*, i8*)* %26)
store i32 %27, i32* %11
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = load i32, i32* %11
%31 = sub nsw i32 %30, 1
%32 = load i64, i64* %9
%33 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%34 = load i8*, i8** %6
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %8
%38 = load i64, i64* %9
%39 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
br label %40
40: ; preds = %16, %5
ret void
}

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