#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ comp(void *, scalar_t__, scalar_t__,
                int (*)(void const *, void const *, void *), void *, scalar_t__,
                scalar_t__);
int /*<<< orphan*/ exch(void *, scalar_t__, scalar_t__, scalar_t__, scalar_t__);
int partition(void *base, ssize_t nmemb, ssize_t size,
              int (*compare)(const void *a, const void *b, void *context),
              void *context, ssize_t lo, ssize_t hi) {
  ssize_t i;
  ssize_t j;
  i = lo;
  j = hi + 1;
  while (1) {
    while (comp(base, nmemb, size, compare, context, ++i, lo) < 0) {
      if (i == hi) {
        break;
      }
    }
    while (comp(base, nmemb, size, compare, context, lo, --j) < 0) {
      if (j == lo) {
        break;
      }
    }
    if (i >= j) {
      break;
    }
    exch(base, nmemb, size, i, j);
  }
  exch(base, nmemb, size, lo, j);
  return j;
}


x86 assembly (clang, -O0):
<partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
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    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    115d <partition+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x38(%rbp),%r9
add    $0x1,%r9
mov    %r9,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <comp@plt>
cmp    $0x0,%rax
jge    11ac <partition+0x8c>
mov    -0x38(%rbp),%rax
cmp    0x10(%rbp),%rax
jne    11a7 <partition+0x87>
jmp    11ac <partition+0x8c>
jmp    115d <partition+0x3d>
jmp    11b1 <partition+0x91>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
mov    %rax,(%rsp)
call   1040 <comp@plt>
cmp    $0x0,%rax
jge    1200 <partition+0xe0>
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    11fb <partition+0xdb>
jmp    1200 <partition+0xe0>
jmp    11b1 <partition+0x91>
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jl     1213 <partition+0xf3>
jmp    1231 <partition+0x111>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
call   1030 <exch@plt>
jmp    1158 <partition+0x38>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x40(%rbp),%r8
call   1030 <exch@plt>
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r14
mov    %r8,0x28(%rsp)
mov    %rcx,0x20(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbp
mov    0x70(%rsp),%r15
lea    0x1(%r15),%r12
add    $0xffffffffffffffff,%r15
lea    0x1(%r9),%rax
mov    %rax,0x30(%rsp)
mov    %r9,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x1(%rbx),%r14
mov    %r13,(%rsp)
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    0x20(%rsp),%rcx
mov    0x28(%rsp),%r8
mov    %r14,%r9
call   1040 <comp@plt>
test   %rax,%rax
jns    11b4 <partition+0x94>
cmp    %rbx,%r15
mov    %r14,%rbx
jne    1180 <partition+0x60>
mov    %r15,%rbx
nopw   0x0(%rax,%rax,1)
lea    -0x1(%r12),%r15
mov    %r15,(%rsp)
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    0x20(%rsp),%rcx
mov    0x28(%rsp),%r8
mov    %r13,%r9
call   1040 <comp@plt>
test   %rax,%rax
jns    11f7 <partition+0xd7>
cmp    %r12,0x30(%rsp)
mov    %r15,%r12
jne    11c0 <partition+0xa0>
cmp    %r15,%r14
jge    121f <partition+0xff>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1030 <exch@plt>
mov    %r15,%r12
mov    %rbx,%r15
jmp    1170 <partition+0x50>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    %r13,%rcx
mov    %r15,%r8
call   1030 <exch@plt>
mov    %r15d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @partition(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i64 %5, i64 %6) {
%8 = add nsw i64 %6, 1
br label %9
9: ; preds = %28, %7
%10 = phi i64 [ %5, %7 ], [ %14, %28 ]
%11 = phi i64 [ %8, %7 ], [ %21, %28 ]
br label %12
12: ; preds = %12, %9
%13 = phi i64 [ %10, %9 ], [ %14, %12 ]
%14 = add nsw i64 %13, 1
%15 = tail call i64 @comp(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i64 %14, i64 %5)
%16 = icmp sgt i64 %15, -1
%17 = icmp eq i64 %14, %6
%18 = or i1 %16, %17
br i1 %18, label %19, label %12
19: ; preds = %12, %19
%20 = phi i64 [ %21, %19 ], [ %11, %12 ]
%21 = add nsw i64 %20, -1
%22 = tail call i64 @comp(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i64 %5, i64 %21)
%23 = icmp sgt i64 %22, -1
%24 = icmp eq i64 %21, %5
%25 = or i1 %23, %24
br i1 %25, label %26, label %19
26: ; preds = %19
%27 = icmp slt i64 %14, %21
br i1 %27, label %28, label %30
28: ; preds = %26
%29 = tail call i32 @exch(i8* %0, i64 %1, i64 %2, i64 %14, i64 %21)
br label %9
30: ; preds = %26
%31 = tail call i32 @exch(i8* %0, i64 %1, i64 %2, i64 %5, i64 %21)
%32 = trunc i64 %21 to i32
ret i32 %32
}