#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 */
size_t partition(void *, size_t, int (*)(void const *, void const *), size_t,
                 size_t);
void qsort_r(void *base, size_t size, int (*compar)(const void *, const void *),
             size_t low, size_t high) {
  size_t pivot;
  if (high > low) {
    pivot = partition(base, size, compar, low, high);
    if (pivot > 0)
      qsort_r(base, size, compar, low, pivot - 1);
    qsort_r(base, size, compar, pivot + 1, high);
  }
}


x86 assembly (clang, -O0):
<qsort_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11ac <qsort_r+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1030 <partition@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jbe    118f <qsort_r+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%r8
sub    $0x1,%r8
call   1040 <qsort_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%r8
call   1040 <qsort_r@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qsort_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %rcx,%r8
jbe    118f <qsort_r+0x6f>
mov    %r8,%r13
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
jmp    115c <qsort_r+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbp,%rbx
cmp    %r13,%rbp
jae    118f <qsort_r+0x6f>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r13,%r8
call   1030 <partition@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1150 <qsort_r+0x30>
lea    -0x1(%rbp),%r8
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <qsort_r@plt>
jmp    1150 <qsort_r+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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