#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*/ pushDown(int, int *, int);
int /*<<< orphan*/ troca(int *, int *);
void desmontaHeap(int *heap, int tam) {
  int i;
  int n = tam;
  for (i = 1; i <= n; i++) {
    troca(&heap[1], &heap[tam]);
    tam--;
    pushDown(1, heap, tam);
  }
}


x86 assembly (clang, -O0):
<desmontaHeap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     118c <desmontaHeap+0x6c>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <troca@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
call   1030 <pushDown@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113c <desmontaHeap+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<desmontaHeap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1163 <desmontaHeap+0x43>
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x4(%rdi),%r15
mov    %esi,%eax
lea    (%rdi,%rax,4),%rbx
add    $0xffffffff,%ebp
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <troca@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <pushDown@plt>
add    $0xfffffffffffffffc,%rbx
add    $0xffffffff,%ebp
jb     1140 <desmontaHeap+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @desmontaHeap(i32* %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %4, %7
%8 = phi i64 [ %6, %4 ], [ %12, %7 ]
%9 = phi i32 [ 1, %4 ], [ %15, %7 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %8
%11 = tail call i32 @troca(i32* %5, i32* %10)
%12 = add nsw i64 %8, -1
%13 = trunc i64 %12 to i32
%14 = tail call i32 @pushDown(i32 1, i32* %0, i32 %13)
%15 = add nuw i32 %9, 1
%16 = icmp eq i32 %9, %1
br i1 %16, label %17, label %7
17: ; preds = %7, %2
ret void
}