#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*/ buildHeap(void **, int (*)(void const *, void const *), int);
int /*<<< orphan*/ heapify(void **, int (*)(void const *, void const *),
                           int /*<<< orphan*/, int);
void sortPointers(void **ar, int n, int (*cmp)(const void *, const void *)) {
  int i;
  buildHeap(ar, cmp, n);
  for (i = n - 1; i >= 1; i--) {
    void *tmp;
    tmp = ar[0];
    ar[0] = ar[i];
    ar[i] = tmp;
    heapify(ar, cmp, 0, i);
  }
}


x86 assembly (clang, -O0):
<sortPointers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <buildHeap@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jl     11a4 <sortPointers+0x84>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
call   1040 <heapify@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <sortPointers+0x2c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortPointers>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    %rdx,%rsi
mov    %ebp,%edx
call   1030 <buildHeap@plt>
cmp    $0x2,%ebp
jl     116c <sortPointers+0x4c>
mov    %ebp,%ebp
lea    -0x1(%rbp),%rbx
mov    (%r15),%rax
mov    %ebx,%ecx
mov    (%r15,%rcx,8),%rdx
mov    %rdx,(%r15)
mov    %rax,(%r15,%rcx,8)
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %ebx,%ecx
call   1040 <heapify@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1140 <sortPointers+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sortPointers(i8** %0, i32 %1, i32 (i8*, i8*)* %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32 (i8*, i8*)*
%7 = alloca i32
%8 = alloca i8*
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 (i8*, i8*)* %2, i32 (i8*, i8*)** %6
%9 = load i8**, i8*** %4
%10 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%11 = load i32, i32* %5
%12 = call i32 @buildHeap(i8** %9, i32 (i8*, i8*)* %10, i32 %11)
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %7
br label %15
15: ; preds = %38, %3
%16 = load i32, i32* %7
%17 = icmp sge i32 %16, 1
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
store i8* %21, i8** %8
%22 = load i8**, i8*** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 0
store i8* %26, i8** %28
%29 = load i8*, i8** %8
%30 = load i8**, i8*** %4
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
store i8* %29, i8** %33
%34 = load i8**, i8*** %4
%35 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %6
%36 = load i32, i32* %7
%37 = call i32 @heapify(i8** %34, i32 (i8*, i8*)* %35, i32 0, i32 %36)
br label %38
38: ; preds = %18
%39 = load i32, i32* %7
%40 = add nsw i32 %39, -1
store i32 %40, i32* %7
br label %15
41: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @sortPointers(i8** %0, i32 %1, i32 (i8*, i8*)* %2) {
%4 = tail call i32 @buildHeap(i8** %0, i32 (i8*, i8*)* %2, i32 %1)
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %10, %8 ]
%10 = add nsw i64 %9, -1
%11 = trunc i64 %10 to i32
%12 = load i8*, i8** %0
%13 = and i64 %10, 4294967295
%14 = getelementptr inbounds i8*, i8** %0, i64 %13
%15 = load i8*, i8** %14
store i8* %15, i8** %0
store i8* %12, i8** %14
%16 = tail call i32 @heapify(i8** %0, i32 (i8*, i8*)* %2, i32 0, i32 %11)
%17 = icmp ugt i64 %9, 2
br i1 %17, label %8, label %18
18: ; preds = %8, %3
ret void
}