#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, int, int (*)(void const *, void const *));
int qksort(void *data, int size, int esize, int i, int k,
           int (*compare)(const void *, const void *)) {
  int j;
  while (i < k) {
    if ((j = partition(data, esize, i, k, compare)) < 0)
      return -1;
    if (qksort(data, size, esize, i, j, compare) < 0)
      return -1;
    i = j + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<qksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11b4 <qksort+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%r8
call   1030 <partition@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1177 <qksort+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <qksort+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9
call   1040 <qksort@plt>
cmp    $0x0,%eax
jge    11a6 <qksort+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <qksort+0x9b>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <qksort+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qksort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    %r8d,%ecx
jge    11c3 <qksort+0xa3>
mov    %r9,%r12
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %esi,%r15d
mov    %rdi,%rbp
mov    %r8d,0xc(%rsp)
mov    %esi,0x8(%rsp)
mov    %rdi,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %r8d,%ecx
mov    %r12,%r8
call   1030 <partition@plt>
movl   $0xffffffff,0x4(%rsp)
ff
test   %eax,%eax
js     11cb <qksort+0xab>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r13d,%r15d
mov    %r13d,%edx
mov    %r14d,%ecx
mov    %eax,%r8d
mov    %r12,%r13
mov    %r12,%r9
call   1040 <qksort@plt>
test   %eax,%eax
js     11cb <qksort+0xab>
add    $0x1,%ebx
mov    %ebx,%r14d
mov    0xc(%rsp),%r8d
cmp    %r8d,%ebx
mov    %r13,%r12
mov    %r15d,%r13d
mov    0x8(%rsp),%r15d
mov    0x10(%rsp),%rbp
jl     1160 <qksort+0x40>
movl   $0x0,0x4(%rsp)
mov    0x4(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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