#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 */
struct TreeNode {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SiftHeap(struct TreeNode **, int, unsigned int);
void SortTrees(struct TreeNode **trees, unsigned int num) {
  struct TreeNode *temp;
  unsigned int x;
  for (x = num >> 1; x > 1; x--) {
    SiftHeap(trees, x, num);
  }
  for (x = num; x > 1; x--) {
    SiftHeap(trees, 1, x);
    temp = trees[1 - 1];
    trees[1 - 1] = trees[x - 1];
    trees[x - 1] = temp;
  }
}


x86 assembly (clang, -O0):
<SortTrees>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jbe    114f <SortTrees+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <SiftHeap@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1128 <SortTrees+0x18>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jbe    11b4 <SortTrees+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0x1,%esi
call   1030 <SiftHeap@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <SortTrees+0x45>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SortTrees>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
cmp    $0x4,%esi
jb     1145 <SortTrees+0x35>
mov    %r14d,%ebp
shr    %ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <SiftHeap@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1130 <SortTrees+0x20>
cmp    $0x2,%r14d
jb     117c <SortTrees+0x6c>
mov    %r14d,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1030 <SiftHeap@plt>
mov    (%rbx),%rax
mov    -0x8(%rbx,%rbp,8),%rcx
mov    %rcx,(%rbx)
mov    %rax,-0x8(%rbx,%rbp,8)
lea    -0x1(%rbp),%rax
mov    %rax,%rbp
cmp    $0x1,%rax
ja     1150 <SortTrees+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
define void @SortTrees(%struct.TreeNode** %0, i32 %1) {
%3 = alloca %struct.TreeNode**
%4 = alloca i32
%5 = alloca %struct.TreeNode*
%6 = alloca i32
store %struct.TreeNode** %0, %struct.TreeNode*** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = lshr i32 %7, 1
store i32 %8, i32* %6
br label %9
9: ; preds = %17, %2
%10 = load i32, i32* %6
%11 = icmp ugt i32 %10, 1
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load %struct.TreeNode**, %struct.TreeNode*** %3
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = call i32 @SiftHeap(%struct.TreeNode** %13, i32 %14, i32 %15)
br label %17
17: ; preds = %12
%18 = load i32, i32* %6
%19 = add i32 %18, -1
store i32 %19, i32* %6
br label %9
20: ; preds = %9
%21 = load i32, i32* %4
store i32 %21, i32* %6
br label %22
22: ; preds = %46, %20
%23 = load i32, i32* %6
%24 = icmp ugt i32 %23, 1
br i1 %24, label %25, label %49
25: ; preds = %22
%26 = load %struct.TreeNode**, %struct.TreeNode*** %3
%27 = load i32, i32* %6
%28 = call i32 @SiftHeap(%struct.TreeNode** %26, i32 1, i32 %27)
%29 = load %struct.TreeNode**, %struct.TreeNode*** %3
%30 = getelementptr inbounds %struct.TreeNode*, %struct.TreeNode** %29, i64 0
%31 = load %struct.TreeNode*, %struct.TreeNode** %30
store %struct.TreeNode* %31, %struct.TreeNode** %5
%32 = load %struct.TreeNode**, %struct.TreeNode*** %3
%33 = load i32, i32* %6
%34 = sub i32 %33, 1
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds %struct.TreeNode*, %struct.TreeNode** %32, i64 %35
%37 = load %struct.TreeNode*, %struct.TreeNode** %36
%38 = load %struct.TreeNode**, %struct.TreeNode*** %3
%39 = getelementptr inbounds %struct.TreeNode*, %struct.TreeNode** %38, i64 0
store %struct.TreeNode* %37, %struct.TreeNode** %39
%40 = load %struct.TreeNode*, %struct.TreeNode** %5
%41 = load %struct.TreeNode**, %struct.TreeNode*** %3
%42 = load i32, i32* %6
%43 = sub i32 %42, 1
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds %struct.TreeNode*, %struct.TreeNode** %41, i64 %44
store %struct.TreeNode* %40, %struct.TreeNode** %45
br label %46
46: ; preds = %25
%47 = load i32, i32* %6
%48 = add i32 %47, -1
store i32 %48, i32* %6
br label %22
49: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define void @SortTrees(%struct.TreeNode** %0, i32 %1) {
%3 = icmp ugt i32 %1, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = lshr i32 %1, 1
br label %10
6: ; preds = %10, %2
%7 = icmp ugt i32 %1, 1
br i1 %7, label %8, label %24
8: ; preds = %6
%9 = zext i32 %1 to i64
br label %15
10: ; preds = %4, %10
%11 = phi i32 [ %13, %10 ], [ %5, %4 ]
%12 = tail call i32 @SiftHeap(%struct.TreeNode** %0, i32 %11, i32 %1)
%13 = add i32 %11, -1
%14 = icmp ugt i32 %13, 1
br i1 %14, label %10, label %6
15: ; preds = %8, %15
%16 = phi i64 [ %9, %8 ], [ %20, %15 ]
%17 = trunc i64 %16 to i32
%18 = tail call i32 @SiftHeap(%struct.TreeNode** %0, i32 1, i32 %17)
%19 = load %struct.TreeNode*, %struct.TreeNode** %0
%20 = add nsw i64 %16, -1
%21 = getelementptr inbounds %struct.TreeNode*, %struct.TreeNode** %0, i64 %20
%22 = load %struct.TreeNode*, %struct.TreeNode** %21
store %struct.TreeNode* %22, %struct.TreeNode** %0
store %struct.TreeNode* %19, %struct.TreeNode** %21
%23 = icmp ugt i64 %20, 1
br i1 %23, label %15, label %24
24: ; preds = %15, %6
ret void
}