#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 */
scalar_t__ comp(void *, int, int, int (*)(void const *, void const *, void *),
                void *, int, int);
int /*<<< orphan*/ insertion_sort(void *, int, int,
                                  int (*)(void const *, void const *, void *),
                                  void *);
int /*<<< orphan*/ merge(void *, int, int,
                         int (*)(void const *, void const *, void *), void *,
                         void *, int, int, int);
int sort(void *base, ssize_t nmemb, ssize_t size,
         int (*compare)(const void *a, const void *b, void *context),
         void *context, void *aux, ssize_t lo, ssize_t hi) {
  ssize_t mid;
  if (hi <= lo + 7 - 1) {
    insertion_sort(base, nmemb, size, compare, context);
    return 0;
  }
  mid = lo + (hi - lo) / 2;
  sort(base, nmemb, size, compare, context, aux, lo, mid);
  sort(base, nmemb, size, compare, context, aux, mid + 1, hi);
  if (comp(base, nmemb, size, compare, context, mid + 1, mid) >= 0) {
    return 0;
  }
  merge(base, nmemb, size, compare, context, aux, lo, mid, hi);
  return 0;
}


x86 assembly (clang, -O0):
<sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x18(%rbp),%eax
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    %r9,-0x30(%rbp)
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%ecx
add    $0x7,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     119b <sort+0x5b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1060 <insertion_sort@plt>
movl   $0x0,-0x4(%rbp)
jmp    1286 <sort+0x146>
mov    0x10(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x18(%rbp),%eax
sub    0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%r10d
mov    -0x34(%rbp),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%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),%r9
mov    -0x34(%rbp),%r10d
add    $0x1,%r10d
mov    0x18(%rbp),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%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    -0x34(%rbp),%r9d
add    $0x1,%r9d
mov    -0x34(%rbp),%eax
mov    %eax,(%rsp)
call   1030 <comp@plt>
cmp    $0x0,%rax
jl     124c <sort+0x10c>
movl   $0x0,-0x4(%rbp)
jmp    1286 <sort+0x146>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    0x10(%rbp),%r11d
mov    -0x34(%rbp),%r10d
mov    0x18(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <merge@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x68(%rsp),%ebx
mov    0x60(%rsp),%ebp
lea    0x6(%rbp),%eax
cmp    %ebx,%eax
jge    1231 <sort+0xf1>
mov    %ebx,%eax
sub    %ebp,%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
lea    (%rbx,%rbp,1),%eax
mov    %rax,0x20(%rsp)
mov    %rcx,%r13
mov    %r8,%r12
mov    %edx,0x4(%rsp)
mov    %r9,%r15
push   %rax
push   %rbp
mov    %esi,0x10(%rsp)
mov    %rdi,%r14
call   1040 <sort@plt>
add    $0x10,%rsp
add    %ebx,%ebp
add    $0x1,%ebp
mov    %r14,%rdi
mov    (%rsp),%ebx
mov    %ebx,%esi
mov    0x4(%rsp),%edx
mov    %r13,%rcx
mov    %r12,%r8
mov    %r15,0x10(%rsp)
mov    %r15,%r9
mov    0x68(%rsp),%r15d
mov    %r15,%rax
mov    0x4(%rsp),%r15d
push   %rax
push   %rbp
call   1040 <sort@plt>
add    $0x8,%rsp
mov    %r14,0x10(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r13,0x20(%rsp)
mov    %r13,%rcx
mov    %r12,%r14
mov    %r12,%r8
mov    0x28(%rsp),%rbx
mov    %ebp,%r9d
push   %rbx
call   1030 <comp@plt>
add    $0x10,%rsp
test   %rax,%rax
jns    1236 <sort+0xf6>
sub    $0x8,%rsp
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%esi
mov    %r15d,%edx
mov    0x20(%rsp),%rcx
mov    %r14,%r8
mov    0x18(%rsp),%r9
mov    0x70(%rsp),%eax
push   %rax
push   %rbx
mov    0x78(%rsp),%eax
push   %rax
call   1050 <merge@plt>
add    $0x20,%rsp
jmp    1236 <sort+0xf6>
call   1060 <insertion_sort@plt>
xor    %eax,%eax
add    $0x28,%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, i8* %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32 (i8*, i8*, i8*)*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %10
store i32 %1, i32* %11
store i32 %2, i32* %12
store i32 (i8*, i8*, i8*)* %3, i32 (i8*, i8*, i8*)** %13
store i8* %4, i8** %14
store i8* %5, i8** %15
store i32 %6, i32* %16
store i32 %7, i32* %17
%19 = load i32, i32* %17
%20 = load i32, i32* %16
%21 = add nsw i32 %20, 7
%22 = sub nsw i32 %21, 1
%23 = icmp sle i32 %19, %22
br i1 %23, label %24, label %31
24: ; preds = %8
%25 = load i8*, i8** %10
%26 = load i32, i32* %11
%27 = load i32, i32* %12
%28 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %13
%29 = load i8*, i8** %14
%30 = call i32 @insertion_sort(i8* %25, i32 %26, i32 %27, i32 (i8*, i8*, i8*)* %28, i8* %29)
store i32 0, i32* %9
br label %79
31: ; preds = %8
%32 = load i32, i32* %16
%33 = load i32, i32* %17
%34 = load i32, i32* %16
%35 = sub nsw i32 %33, %34
%36 = sdiv i32 %35, 2
%37 = add nsw i32 %32, %36
store i32 %37, i32* %18
%38 = load i8*, i8** %10
%39 = load i32, i32* %11
%40 = load i32, i32* %12
%41 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %13
%42 = load i8*, i8** %14
%43 = load i8*, i8** %15
%44 = load i32, i32* %16
%45 = load i32, i32* %18
%46 = call i32 @sort(i8* %38, i32 %39, i32 %40, i32 (i8*, i8*, i8*)* %41, i8* %42, i8* %43, i32 %44, i32 %45)
%47 = load i8*, i8** %10
%48 = load i32, i32* %11
%49 = load i32, i32* %12
%50 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %13
%51 = load i8*, i8** %14
%52 = load i8*, i8** %15
%53 = load i32, i32* %18
%54 = add nsw i32 %53, 1
%55 = load i32, i32* %17
%56 = call i32 @sort(i8* %47, i32 %48, i32 %49, i32 (i8*, i8*, i8*)* %50, i8* %51, i8* %52, i32 %54, i32 %55)
%57 = load i8*, i8** %10
%58 = load i32, i32* %11
%59 = load i32, i32* %12
%60 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %13
%61 = load i8*, i8** %14
%62 = load i32, i32* %18
%63 = add nsw i32 %62, 1
%64 = load i32, i32* %18
%65 = call i64 @comp(i8* %57, i32 %58, i32 %59, i32 (i8*, i8*, i8*)* %60, i8* %61, i32 %63, i32 %64)
%66 = icmp sge i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %31
store i32 0, i32* %9
br label %79
68: ; preds = %31
%69 = load i8*, i8** %10
%70 = load i32, i32* %11
%71 = load i32, i32* %12
%72 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %13
%73 = load i8*, i8** %14
%74 = load i8*, i8** %15
%75 = load i32, i32* %16
%76 = load i32, i32* %18
%77 = load i32, i32* %17
%78 = call i32 @merge(i8* %69, i32 %70, i32 %71, i32 (i8*, i8*, i8*)* %72, i8* %73, i8* %74, i32 %75, i32 %76, i32 %77)
store i32 0, i32* %9
br label %79
79: ; preds = %68, %67, %24
%80 = load i32, i32* %9
ret i32 %80
}

LLVM IR (-O2):
define i32 @sort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i8* %5, i32 %6, i32 %7) {
%9 = add nsw i32 %6, 6
%10 = icmp slt i32 %9, %7
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @insertion_sort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*, i8*)* %3, i8* %4)
br label %24
13: ; preds = %8
%14 = sub nsw i32 %7, %6
%15 = sdiv i32 %14, 2
%16 = add nsw i32 %15, %6
%17 = tail call i32 @sort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i8* %5, i32 %6, i32 %16)
%18 = add nsw i32 %16, 1
%19 = tail call i32 @sort(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i8* %5, i32 %18, i32 %7)
%20 = tail call i64 @comp(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i32 %18, i32 %16)
%21 = icmp sgt i64 %20, -1
br i1 %21, label %24, label %22
22: ; preds = %13
%23 = tail call i32 @merge(i8* %0, i32 %1, i32 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i8* %5, i32 %6, i32 %16, i32 %7)
br label %24
24: ; preds = %13, %22, %11
ret i32 0
}