#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*/ quicksort_internal(void *, void *, void *(*)(void *),
                                      void *(*)(void *),
                                      void (*)(void *, void *),
                                      int (*)(void *, void *));
void quicksort(void *data, void *(*prevfunc)(void *node),
               void *(*nextfunc)(void *node),
               void (*swapfunc)(void *a, void *b),
               int (*comparefunc)(void *a, void *b)) {
  void *tail = data;
  void *next = NULL;
  if (tail == NULL)
    return;
  while ((next = nextfunc(tail)) != NULL)
    tail = next;
  quicksort_internal(data, tail, prevfunc, nextfunc, swapfunc, comparefunc);
}


x86 assembly (clang, -O0):
<quicksort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    114c <quicksort+0x3c>
jmp    1193 <quicksort+0x83>
jmp    1151 <quicksort+0x41>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rdi
call   *%rax
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1176 <quicksort+0x66>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1151 <quicksort+0x41>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
call   1030 <quicksort_internal@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicksort>:
test   %rdi,%rdi
je     1172 <quicksort+0x62>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rdi,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rbp
mov    %rax,%rdi
call   *%rbx
test   %rax,%rax
jne    1140 <quicksort+0x30>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
mov    %r14,%r9
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <quicksort_internal@plt>
ret

LLVM IR (-O0):
define void @quicksort(i8* %0, i8* (i8*)* %1, i8* (i8*)* %2, void (i8*, i8*)* %3, i32 (i8*, i8*)* %4) {
%6 = alloca i8*
%7 = alloca i8* (i8*)*
%8 = alloca i8* (i8*)*
%9 = alloca void (i8*, i8*)*
%10 = alloca i32 (i8*, i8*)*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %6
store i8* (i8*)* %1, i8* (i8*)** %7
store i8* (i8*)* %2, i8* (i8*)** %8
store void (i8*, i8*)* %3, void (i8*, i8*)** %9
store i32 (i8*, i8*)* %4, i32 (i8*, i8*)** %10
%13 = load i8*, i8** %6
store i8* %13, i8** %11
store i8* null, i8** %12
%14 = load i8*, i8** %11
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %5
br label %33
17: ; preds = %5
br label %18
18: ; preds = %23, %17
%19 = load i8* (i8*)*, i8* (i8*)** %8
%20 = load i8*, i8** %11
%21 = call i8* %19(i8* %20)
store i8* %21, i8** %12
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i8*, i8** %12
store i8* %24, i8** %11
br label %18
25: ; preds = %18
%26 = load i8*, i8** %6
%27 = load i8*, i8** %11
%28 = load i8* (i8*)*, i8* (i8*)** %7
%29 = load i8* (i8*)*, i8* (i8*)** %8
%30 = load void (i8*, i8*)*, void (i8*, i8*)** %9
%31 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%32 = call i32 @quicksort_internal(i8* %26, i8* %27, i8* (i8*)* %28, i8* (i8*)* %29, void (i8*, i8*)* %30, i32 (i8*, i8*)* %31)
br label %33
33: ; preds = %25, %16
ret void
}

LLVM IR (-O2):
define void @quicksort(i8* %0, i8* (i8*)* %1, i8* (i8*)* %2, void (i8*, i8*)* %3, i32 (i8*, i8*)* %4) {
%6 = icmp eq i8* %0, null
br i1 %6, label %13, label %7
7: ; preds = %5, %7
%8 = phi i8* [ %9, %7 ], [ %0, %5 ]
%9 = tail call i8* %2(i8* %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %7
11: ; preds = %7
%12 = tail call i32 @quicksort_internal(i8* %0, i8* %8, i8* (i8*)* %1, i8* (i8*)* %2, void (i8*, i8*)* %3, i32 (i8*, i8*)* %4)
br label %13
13: ; preds = %5, %11
ret void
}