#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 int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ insertion_sort(void *, int, int,
                                  int (*)(void const *, void const *, void *),
                                  void *);
int partition(void *, int, int, int (*)(void const *, void const *, void *),
              void *, int, int);
int sort(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 j;
  if (hi <= lo + 10 - 1) {
    insertion_sort(base, nmemb, size, compare, context);
    return 0;
  }
  j = partition(base, nmemb, size, compare, context, lo, hi);
  sort(base, nmemb, size, compare, context, lo, j - 1);
  sort(base, nmemb, size, compare, context, j + 1, hi);
  return 0;
}


x86 assembly (clang, -O0):
<sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x10(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    $0xa,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1188 <sort+0x58>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1050 <insertion_sort@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fc <sort+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <partition@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
mov    %eax,(%rsp)
call   1040 <sort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9d
add    $0x1,%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1040 <sort@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r15
mov    %rcx,%r12
mov    %edx,%r13d
mov    %esi,%ebp
mov    0x50(%rsp),%ebx
lea    0x9(%r9),%eax
cmp    %ebx,%eax
jge    11b3 <sort+0x83>
mov    %rdi,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %ebx,(%rsp)
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r12,%rcx
mov    %r15,%r8
mov    %r9,0x10(%rsp)
call   1030 <partition@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%eax
mov    %eax,(%rsp)
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r12,%rcx
mov    %r15,%r8
mov    0x10(%rsp),%r9
call   1040 <sort@plt>
mov    0x8(%rsp),%rdi
lea    0x1(%r14),%r9d
add    $0xa,%r14d
cmp    %ebx,%r14d
jl     1160 <sort+0x30>
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r12,%rcx
mov    %r15,%r8
call   1050 <insertion_sort@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32 (i8*, i8*, i8*)*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 (i8*, i8*, i8*)* %3, i32 (i8*, i8*, i8*)** %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%17 = load i32, i32* %15
%18 = load i32, i32* %14
%19 = add nsw i32 %18, 10
%20 = sub nsw i32 %19, 1
%21 = icmp sle i32 %17, %20
br i1 %21, label %22, label %29
22: ; preds = %7
%23 = load i8*, i8** %9
%24 = load i32, i32* %10
%25 = load i32, i32* %11
%26 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %12
%27 = load i8*, i8** %13
%28 = call i32 @insertion_sort(i8* %23, i32 %24, i32 %25, i32 (i8*, i8*, i8*)* %26, i8* %27)
store i32 0, i32* %8
br label %56
29: ; preds = %7
%30 = load i8*, i8** %9
%31 = load i32, i32* %10
%32 = load i32, i32* %11
%33 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %12
%34 = load i8*, i8** %13
%35 = load i32, i32* %14
%36 = load i32, i32* %15
%37 = call i32 @partition(i8* %30, i32 %31, i32 %32, i32 (i8*, i8*, i8*)* %33, i8* %34, i32 %35, i32 %36)
store i32 %37, i32* %16
%38 = load i8*, i8** %9
%39 = load i32, i32* %10
%40 = load i32, i32* %11
%41 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %12
%42 = load i8*, i8** %13
%43 = load i32, i32* %14
%44 = load i32, i32* %16
%45 = sub nsw i32 %44, 1
%46 = call i32 @sort(i8* %38, i32 %39, i32 %40, i32 (i8*, i8*, i8*)* %41, i8* %42, i32 %43, i32 %45)
%47 = load i8*, i8** %9
%48 = load i32, i32* %10
%49 = load i32, i32* %11
%50 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %12
%51 = load i8*, i8** %13
%52 = load i32, i32* %16
%53 = add nsw i32 %52, 1
%54 = load i32, i32* %15
%55 = call i32 @sort(i8* %47, i32 %48, i32 %49, i32 (i8*, i8*, i8*)* %50, i8* %51, i32 %53, i32 %54)
store i32 0, i32* %8
br label %56
56: ; preds = %29, %22
%57 = load i32, i32* %8
ret i32 %57
}

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