#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 */
void *quicksort_partition(void *p, void *r, void *(*prevfunc)(void *node),
                          void *(*nextfunc)(void *node),
                          void (*swapfunc)(void *a, void *b),
                          int (*comparefunc)(void *a, void *b)) {
  void *x = p;
  void *i = NULL;
  void *j = NULL;
  unsigned char done = 0;
  while (1) {
    do {
      if (j == NULL)
        j = r;
      else
        j = prevfunc(j);
      if (i == j)
        done = 1;
    } while (comparefunc(j, x) > 0);
    do {
      if (i == NULL)
        i = p;
      else
        i = nextfunc(i);
      if (i == j)
        done = 1;
    } while (comparefunc(i, x) < 0);
    if (done)
      return j;
    swapfunc(i, j);
  }
}


x86 assembly (clang, -O0):
<quicksort_partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movb   $0x0,-0x49(%rbp)
jmp    1141 <quicksort_partition+0x41>
cmpq   $0x0,-0x48(%rbp)
jne    1159 <quicksort_partition+0x59>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1167 <quicksort_partition+0x67>
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rdi
call   *%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    1179 <quicksort_partition+0x79>
movb   $0x1,-0x49(%rbp)
jmp    117e <quicksort_partition+0x7e>
mov    -0x30(%rbp),%rax
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jg     1141 <quicksort_partition+0x41>
jmp    119a <quicksort_partition+0x9a>
cmpq   $0x0,-0x40(%rbp)
jne    11b2 <quicksort_partition+0xb2>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11c0 <quicksort_partition+0xc0>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rdi
call   *%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    11d2 <quicksort_partition+0xd2>
movb   $0x1,-0x49(%rbp)
jmp    11d7 <quicksort_partition+0xd7>
mov    -0x30(%rbp),%rax
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   *%rax
cmp    $0x0,%eax
jl     119a <quicksort_partition+0x9a>
cmpb   $0x0,-0x49(%rbp)
je     1202 <quicksort_partition+0x102>
mov    -0x48(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   *%rax
jmp    113c <quicksort_partition+0x3c>

x86 assembly (clang, -O2):
<quicksort_partition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %r8,0x10(%rsp)
mov    %rcx,0x18(%rsp)
mov    %rdx,%r15
mov    %rsi,0x20(%rsp)
mov    %rdi,%rbp
xor    %r12d,%r12d
xor    %r13d,%r13d
mov    %rdx,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %r14d,%r14d
mov    %r13,%rdi
jmp    116f <quicksort_partition+0x6f>
nopl   0x0(%rax,%rax,1)
cmp    %r13,%r12
movzbl %r14b,%r14d
mov    $0x1,%eax
cmove  %eax,%r14d
mov    %r13,%rdi
mov    %rbp,%rsi
call   *%rbx
mov    %r13,%rdi
test   %eax,%eax
jle    11af <quicksort_partition+0xaf>
mov    0x20(%rsp),%r13
test   %rdi,%rdi
je     1150 <quicksort_partition+0x50>
call   *%r15
mov    %rax,%r13
jmp    1150 <quicksort_partition+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %r13,%r15
movzbl %r14b,%r14d
mov    $0x1,%eax
cmove  %eax,%r14d
mov    %r15,%rdi
mov    %rbp,%rsi
call   *%rbx
mov    %r15,%r12
test   %eax,%eax
jns    11d0 <quicksort_partition+0xd0>
mov    %rbp,%r15
test   %r12,%r12
je     1190 <quicksort_partition+0x90>
mov    %r12,%rdi
call   *0x18(%rsp)
mov    %rax,%r15
jmp    1190 <quicksort_partition+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %r14b,%r14b
jne    11ec <quicksort_partition+0xec>
mov    %r15,%rdi
mov    %r13,%rsi
call   *0x10(%rsp)
mov    %r15,%r12
mov    0x8(%rsp),%r15
jmp    1140 <quicksort_partition+0x40>
mov    %r13,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @quicksort_partition(i8* %0, i8* %1, i8* (i8*)* %2, i8* (i8*)* %3, void (i8*, i8*)* %4, i32 (i8*, i8*)* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8* (i8*)*
%10 = alloca i8* (i8*)*
%11 = alloca void (i8*, i8*)*
%12 = alloca i32 (i8*, i8*)*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* (i8*)* %2, i8* (i8*)** %9
store i8* (i8*)* %3, i8* (i8*)** %10
store void (i8*, i8*)* %4, void (i8*, i8*)** %11
store i32 (i8*, i8*)* %5, i32 (i8*, i8*)** %12
%17 = load i8*, i8** %7
store i8* %17, i8** %13
store i8* null, i8** %14
store i8* null, i8** %15
store i8 0, i8* %16
br label %18
18: ; preds = %6, %67
br label %19
19: ; preds = %34, %18
%20 = load i8*, i8** %15
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i8*, i8** %8
store i8* %23, i8** %15
br label %28
24: ; preds = %19
%25 = load i8* (i8*)*, i8* (i8*)** %9
%26 = load i8*, i8** %15
%27 = call i8* %25(i8* %26)
store i8* %27, i8** %15
br label %28
28: ; preds = %24, %22
%29 = load i8*, i8** %14
%30 = load i8*, i8** %15
%31 = icmp eq i8* %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28
store i8 1, i8* %16
br label %33
33: ; preds = %32, %28
br label %34
34: ; preds = %33
%35 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %12
%36 = load i8*, i8** %15
%37 = load i8*, i8** %13
%38 = call i32 %35(i8* %36, i8* %37)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %19, label %40
40: ; preds = %34
br label %41
41: ; preds = %56, %40
%42 = load i8*, i8** %14
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = load i8*, i8** %7
store i8* %45, i8** %14
br label %50
46: ; preds = %41
%47 = load i8* (i8*)*, i8* (i8*)** %10
%48 = load i8*, i8** %14
%49 = call i8* %47(i8* %48)
store i8* %49, i8** %14
br label %50
50: ; preds = %46, %44
%51 = load i8*, i8** %14
%52 = load i8*, i8** %15
%53 = icmp eq i8* %51, %52
br i1 %53, label %54, label %55
54: ; preds = %50
store i8 1, i8* %16
br label %55
55: ; preds = %54, %50
br label %56
56: ; preds = %55
%57 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %12
%58 = load i8*, i8** %14
%59 = load i8*, i8** %13
%60 = call i32 %57(i8* %58, i8* %59)
%61 = icmp slt i32 %60, 0
br i1 %61, label %41, label %62
62: ; preds = %56
%63 = load i8, i8* %16
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = load i8*, i8** %15
ret i8* %66
67: ; preds = %62
%68 = load void (i8*, i8*)*, void (i8*, i8*)** %11
%69 = load i8*, i8** %14
%70 = load i8*, i8** %15
br label %18
}

LLVM IR (-O2):
define i8* @quicksort_partition(i8* %0, i8* %1, i8* (i8*)* nocapture %2, i8* (i8*)* nocapture %3, void (i8*, i8*)* nocapture %4, i32 (i8*, i8*)* nocapture %5) {
br label %7
7: ; preds = %37, %6
%8 = phi i8* [ null, %6 ], [ %29, %37 ]
%9 = phi i8* [ null, %6 ], [ %17, %37 ]
br label %10
10: ; preds = %16, %7
%11 = phi i8* [ %9, %7 ], [ %17, %16 ]
%12 = phi i8 [ 0, %7 ], [ %19, %16 ]
%13 = icmp eq i8* %11, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i8* %2(i8* %11)
br label %16
16: ; preds = %10, %14
%17 = phi i8* [ %15, %14 ], [ %1, %10 ]
%18 = icmp eq i8* %8, %17
%19 = select i1 %18, i8 1, i8 %12
%20 = tail call i32 %5(i8* %17, i8* %0)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %10, label %22
22: ; preds = %16, %28
%23 = phi i8* [ %29, %28 ], [ %8, %16 ]
%24 = phi i8 [ %31, %28 ], [ %19, %16 ]
%25 = icmp eq i8* %23, null
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i8* %3(i8* %23)
br label %28
28: ; preds = %22, %26
%29 = phi i8* [ %27, %26 ], [ %0, %22 ]
%30 = icmp eq i8* %29, %17
%31 = select i1 %30, i8 1, i8 %24
%32 = tail call i32 %5(i8* %29, i8* %0)
%33 = icmp slt i32 %32, 0
br i1 %33, label %22, label %34
34: ; preds = %28
%35 = icmp eq i8 %31, 0
br i1 %35, label %37, label %36
36: ; preds = %34
ret i8* %17
37: ; preds = %34
tail call void %4(i8* %29, i8* %17)
br label %7
}