int heapSort(int arry[], int len) {
  int iRet = 0;
  int treeIdx = 0;
  int i = 0;
  int tmp = 0;
  printf("[F:%s, L:%d]\n", __FUNCTION__, 48);
  for (treeIdx = len / 2; treeIdx >= 1; treeIdx--) {
    heap_adjust(arry, treeIdx, len);
  }
  for (i = 0; i < len; i++) {
    printf("heapSort construct init heap: arry[%d]=%d\n", i, arry[i]);
  }
  printf("[F:%s, L:%d]\n", __FUNCTION__, 57);
  for (i = len; i > 1; i--) {
    tmp = arry[0];
    arry[0] = arry[i - 1];
    arry[i - 1] = tmp;
    printf("[F:%s, L:%d]\n", __FUNCTION__, 65);
    heap_adjust(arry, 1, i - 1);
  }
  return iRet;
}


x86 assembly (clang, -O0):
<heapSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeae(%rip),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x30,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     119c <heapSort+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1040 <heap_adjust@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <heapSort+0x53>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <heapSort+0xb9>
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a3 <heapSort+0x83>
lea    0xe20(%rip),%rdi
lea    0xe27(%rip),%rsi
mov    $0x39,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    1273 <heapSort+0x153>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
lea    0xdc4(%rip),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x41,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
mov    $0x1,%esi
mov    $0x0,%al
call   1040 <heap_adjust@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11f9 <heapSort+0xd9>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
lea    0xecb(%rip),%rdi
lea    0xed2(%rip),%rsi
mov    $0x30,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%r14d
jl     1179 <heapSort+0x59>
mov    %r14d,%ebp
shr    %ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <heap_adjust@plt>
lea    -0x1(%rbp),%eax
cmp    $0x1,%ebp
mov    %eax,%ebp
ja     1160 <heapSort+0x40>
mov    %r14d,%ebx
test   %r14d,%r14d
jle    11a9 <heapSort+0x89>
lea    0xe8f(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbp,4),%edx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1190 <heapSort+0x70>
lea    0xe50(%rip),%rdi
lea    0xe57(%rip),%rsi
mov    $0x39,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%r14d
jl     1222 <heapSort+0x102>
lea    0xe30(%rip),%r14
lea    0xe37(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r12),%eax
lea    -0x1(%rbx),%rbp
mov    %ebp,%ecx
mov    (%r12,%rcx,4),%edx
mov    %edx,(%r12)
mov    %eax,(%r12,%rcx,4)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x41,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <heap_adjust@plt>
cmp    $0x2,%rbx
mov    %rbp,%rbx
ja     11e0 <heapSort+0xc0>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"[F:%s, L:%d]\0A\00"
@__FUNCTION__.heapSort = [9 x i8] c"heapSort\00"
@.str.1 = [43 x i8] c"heapSort construct init heap: arry[%d]=%d\0A\00"
define i32 @heapSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.heapSort, i64 0, i64 0), i32 48)
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 2
store i32 %11, i32* %6
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %6
%14 = icmp sge i32 %13, 1
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @heap_adjust to i32 (i32*, i32, i32, ...)*)(i32* %16, i32 %17, i32 %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %6
%22 = add nsw i32 %21, -1
store i32 %22, i32* %6
br label %12
23: ; preds = %12
store i32 0, i32* %7
br label %24
24: ; preds = %36, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i32, i32* %7
%30 = load i32*, i32** %3
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %34)
br label %36
36: ; preds = %28
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %24
39: ; preds = %24
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.heapSort, i64 0, i64 0), i32 57)
%41 = load i32, i32* %4
store i32 %41, i32* %7
br label %42
42: ; preds = %68, %39
%43 = load i32, i32* %7
%44 = icmp sgt i32 %43, 1
br i1 %44, label %45, label %71
45: ; preds = %42
%46 = load i32*, i32** %3
%47 = getelementptr inbounds i32, i32* %46, i64 0
%48 = load i32, i32* %47
store i32 %48, i32* %8
%49 = load i32*, i32** %3
%50 = load i32, i32* %7
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %49, i64 %52
%54 = load i32, i32* %53
%55 = load i32*, i32** %3
%56 = getelementptr inbounds i32, i32* %55, i64 0
store i32 %54, i32* %56
%57 = load i32, i32* %8
%58 = load i32*, i32** %3
%59 = load i32, i32* %7
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %58, i64 %61
store i32 %57, i32* %62
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.heapSort, i64 0, i64 0), i32 65)
%64 = load i32*, i32** %3
%65 = load i32, i32* %7
%66 = sub nsw i32 %65, 1
%67 = call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @heap_adjust to i32 (i32*, i32, i32, ...)*)(i32* %64, i32 1, i32 %66)
br label %68
68: ; preds = %45
%69 = load i32, i32* %7
%70 = add nsw i32 %69, -1
store i32 %70, i32* %7
br label %42
71: ; preds = %42
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
@.str = [14 x i8] c"[F:%s, L:%d]\0A\00"
@__FUNCTION__.heapSort = [9 x i8] c"heapSort\00"
@.str.1 = [43 x i8] c"heapSort construct init heap: arry[%d]=%d\0A\00"
define i32 @heapSort(i32* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.heapSort, i64 0, i64 0), i32 48)
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = lshr i32 %1, 1
br label %11
7: ; preds = %11, %2
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %24
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %16
11: ; preds = %5, %11
%12 = phi i32 [ %14, %11 ], [ %6, %5 ]
%13 = tail call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @heap_adjust to i32 (i32*, i32, i32, ...)*)(i32* %0, i32 %12, i32 %1)
%14 = add nsw i32 %12, -1
%15 = icmp ugt i32 %12, 1
br i1 %15, label %11, label %7
16: ; preds = %9, %16
%17 = phi i64 [ 0, %9 ], [ %22, %16 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = trunc i64 %17 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %19)
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %10
br i1 %23, label %24, label %16
24: ; preds = %16, %7
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.heapSort, i64 0, i64 0), i32 57)
br i1 %4, label %26, label %39
26: ; preds = %24
%27 = zext i32 %1 to i64
br label %28
28: ; preds = %26, %28
%29 = phi i64 [ %27, %26 ], [ %31, %28 ]
%30 = load i32, i32* %0
%31 = add nsw i64 %29, -1
%32 = trunc i64 %31 to i32
%33 = and i64 %31, 4294967295
%34 = getelementptr inbounds i32, i32* %0, i64 %33
%35 = load i32, i32* %34
store i32 %35, i32* %0
store i32 %30, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__FUNCTION__.heapSort, i64 0, i64 0), i32 65)
%37 = tail call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @heap_adjust to i32 (i32*, i32, i32, ...)*)(i32* %0, i32 1, i32 %32)
%38 = icmp ugt i64 %29, 2
br i1 %38, label %28, label %39
39: ; preds = %28, %24
ret i32 0
}