#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*/ build_heap(float **, long);
int /*<<< orphan*/ xor_swap(float *, float *, int);
void heapsort(float **heap, long heapsize) {
  long index = heapsize;
  build_heap(heap, index);
  while (index > 2) {
    xor_swap(&(*heap)[1], &(*heap)[index - 1], sizeof(float));
    build_heap(heap, index - 1);
    index--;
  }
}


x86 assembly (clang, -O0):
<heapsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <build_heap@plt>
cmpq   $0x2,-0x18(%rbp)
jle    119d <heapsort+0x7d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x4,%edx
call   1040 <xor_swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
call   1030 <build_heap@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1145 <heapsort+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapsort>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <build_heap@plt>
cmp    $0x3,%rbx
jl     1181 <heapsort+0x61>
lea    -0x4(,%rbx,4),%r12
ff
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14),%rsi
lea    0x4(%rsi),%rdi
lea    -0x2(%rbx),%r15
add    %r12,%rsi
mov    $0x4,%edx
call   1040 <xor_swap@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <build_heap@plt>
add    $0xffffffffffffffff,%rbx
add    $0xfffffffffffffffc,%r12
cmp    $0x3,%rbx
ja     1150 <heapsort+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @heapsort(float** %0, i64 %1) {
%3 = alloca float**
%4 = alloca i64
%5 = alloca i64
store float** %0, float*** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
store i64 %6, i64* %5
%7 = load float**, float*** %3
%8 = load i64, i64* %5
%9 = call i32 @build_heap(float** %7, i64 %8)
br label %10
10: ; preds = %13, %2
%11 = load i64, i64* %5
%12 = icmp sgt i64 %11, 2
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load float**, float*** %3
%15 = load float*, float** %14
%16 = getelementptr inbounds float, float* %15, i64 1
%17 = load float**, float*** %3
%18 = load float*, float** %17
%19 = load i64, i64* %5
%20 = sub nsw i64 %19, 1
%21 = getelementptr inbounds float, float* %18, i64 %20
%22 = call i32 @xor_swap(float* %16, float* %21, i32 4)
%23 = load float**, float*** %3
%24 = load i64, i64* %5
%25 = sub nsw i64 %24, 1
%26 = call i32 @build_heap(float** %23, i64 %25)
%27 = load i64, i64* %5
%28 = add nsw i64 %27, -1
store i64 %28, i64* %5
br label %10
29: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @heapsort(float** %0, i64 %1) {
%3 = tail call i32 @build_heap(float** %0, i64 %1)
%4 = icmp sgt i64 %1, 2
br i1 %4, label %5, label %14
5: ; preds = %2, %5
%6 = phi i64 [ %9, %5 ], [ %1, %2 ]
%7 = load float*, float** %0
%8 = getelementptr inbounds float, float* %7, i64 1
%9 = add nsw i64 %6, -1
%10 = getelementptr inbounds float, float* %7, i64 %9
%11 = tail call i32 @xor_swap(float* %8, float* %10, i32 4)
%12 = tail call i32 @build_heap(float** %0, i64 %9)
%13 = icmp ugt i64 %6, 3
br i1 %13, label %5, label %14
14: ; preds = %5, %2
ret void
}