#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 heap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ DESCRIBE(char *);
int /*<<< orphan*/ THEN(char *);
int /*<<< orphan*/ WHEN(char *);
struct heap *heap_create(int);
int /*<<< orphan*/ heap_destroy(struct heap *);
int /*<<< orphan*/ heap_heapify(struct heap *, int /*<<< orphan*/);
int /*<<< orphan*/ heap_insert(struct heap *, int);
int /*<<< orphan*/ heap_isempty(struct heap *);
int /*<<< orphan*/ heap_minimum_delete(struct heap *);
int /*<<< orphan*/ heap_parent(struct heap *, int);
int /*<<< orphan*/ isEqual(int /*<<< orphan*/, int);
test_heapify() {
  int i, val;
  struct heap *p = heap_create(128);
  DESCRIBE("HEAPIFY");
  WHEN("Eu insiro elementos e chamo heapify");
  int valores[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  for (i = 1; i <= 10; i++) {
    heap_insert(p, i);
    heap_heapify(p, heap_parent(p, i));
  }
  for (i = 1; i <= 10; i++) {
    THEN("Deve ter cabeça igual a i");
    isEqual(heap_minimum_delete(p), i);
  }
  THEN("Deve ser vazia");
  isEqual(heap_isempty(p), 1);
  heap_destroy(p);
}


x86 assembly (clang, -O0):
<test_heapify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0x80,%edi
call   1070 <heap_create@plt>
mov    %rax,-0x18(%rbp)
lea    0xe23(%rip),%rdi
call   1090 <DESCRIBE@plt>
lea    0xe1f(%rip),%rdi
call   10e0 <WHEN@plt>
lea    -0x40(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x28,%edx
call   1080 <memcpy@plt>
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     124d <test_heapify+0x8d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <heap_insert@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10a0 <heap_parent@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    120a <test_heapify+0x4a>
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jg     128b <test_heapify+0xcb>
lea    0xdc7(%rip),%rdi
call   1040 <THEN@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%esi
call   10d0 <isEqual@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1254 <test_heapify+0x94>
lea    0xdb5(%rip),%rdi
call   1040 <THEN@plt>
mov    -0x18(%rbp),%rdi
call   1060 <heap_isempty@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10d0 <isEqual@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <heap_destroy@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_heapify>:
push   %r14
push   %rbx
push   %rax
mov    $0x80,%edi
call   1070 <heap_create@plt>
mov    %rax,%rbx
lea    0xe38(%rip),%rdi
call   1080 <DESCRIBE@plt>
lea    0xe34(%rip),%rdi
call   10d0 <WHEN@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <heap_insert@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1090 <heap_parent@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <heap_heapify@plt>
lea    0xce4(%rip),%r14
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x3,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x4,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x5,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x6,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x7,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x8,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0x9,%esi
call   10c0 <isEqual@plt>
mov    %r14,%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   10b0 <heap_minimum_delete@plt>
mov    %eax,%edi
mov    $0xa,%esi
call   10c0 <isEqual@plt>
lea    0xbe0(%rip),%rdi
call   1040 <THEN@plt>
mov    %rbx,%rdi
call   1060 <heap_isempty@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10c0 <isEqual@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <heap_destroy@plt>

LLVM IR (-O0):
%struct.heap = type { i32 }
@.str = [8 x i8] c"HEAPIFY\00"
@.str.1 = [36 x i8] c"Eu insiro elementos e chamo heapify\00"
@__const.test_heapify.valores = [10 x i32] [i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1]
@.str.2 = [27 x i8] c"Deve ter cabe\C3\A7a igual a i\00"
@.str.3 = [15 x i8] c"Deve ser vazia\00"
define i32 @test_heapify() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.heap*
%5 = alloca [10 x i32]
%6 = call %struct.heap* @heap_create(i32 128)
store %struct.heap* %6, %struct.heap** %4
%7 = call i32 @DESCRIBE(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @WHEN(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%9 = bitcast [10 x i32]* %5 to i8*
store i32 1, i32* %2
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 10
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load %struct.heap*, %struct.heap** %4
%15 = load i32, i32* %2
%16 = call i32 @heap_insert(%struct.heap* %14, i32 %15)
%17 = load %struct.heap*, %struct.heap** %4
%18 = load %struct.heap*, %struct.heap** %4
%19 = load i32, i32* %2
%20 = call i32 @heap_parent(%struct.heap* %18, i32 %19)
%21 = call i32 @heap_heapify(%struct.heap* %17, i32 %20)
br label %22
22: ; preds = %13
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %10
25: ; preds = %10
store i32 1, i32* %2
br label %26
26: ; preds = %35, %25
%27 = load i32, i32* %2
%28 = icmp sle i32 %27, 10
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%31 = load %struct.heap*, %struct.heap** %4
%32 = call i32 @heap_minimum_delete(%struct.heap* %31)
%33 = load i32, i32* %2
%34 = call i32 @isEqual(i32 %32, i32 %33)
br label %35
35: ; preds = %29
%36 = load i32, i32* %2
%37 = add nsw i32 %36, 1
store i32 %37, i32* %2
br label %26
38: ; preds = %26
%39 = call i32 @THEN(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%40 = load %struct.heap*, %struct.heap** %4
%41 = call i32 @heap_isempty(%struct.heap* %40)
%42 = call i32 @isEqual(i32 %41, i32 1)
%43 = load %struct.heap*, %struct.heap** %4
%44 = call i32 @heap_destroy(%struct.heap* %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
%struct.heap = type { i32 }
@.str = [8 x i8] c"HEAPIFY\00"
@.str.1 = [36 x i8] c"Eu insiro elementos e chamo heapify\00"
@.str.2 = [27 x i8] c"Deve ter cabe\C3\A7a igual a i\00"
@.str.3 = [15 x i8] c"Deve ser vazia\00"
define i32 @test_heapify() {
%1 = tail call %struct.heap* @heap_create(i32 128)
%2 = tail call i32 @DESCRIBE(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @WHEN(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @heap_insert(%struct.heap* %1, i32 1)
%5 = tail call i32 @heap_parent(%struct.heap* %1, i32 1)
%6 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %5)
%7 = tail call i32 @heap_insert(%struct.heap* %1, i32 2)
%8 = tail call i32 @heap_parent(%struct.heap* %1, i32 2)
%9 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %8)
%10 = tail call i32 @heap_insert(%struct.heap* %1, i32 3)
%11 = tail call i32 @heap_parent(%struct.heap* %1, i32 3)
%12 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %11)
%13 = tail call i32 @heap_insert(%struct.heap* %1, i32 4)
%14 = tail call i32 @heap_parent(%struct.heap* %1, i32 4)
%15 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %14)
%16 = tail call i32 @heap_insert(%struct.heap* %1, i32 5)
%17 = tail call i32 @heap_parent(%struct.heap* %1, i32 5)
%18 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %17)
%19 = tail call i32 @heap_insert(%struct.heap* %1, i32 6)
%20 = tail call i32 @heap_parent(%struct.heap* %1, i32 6)
%21 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %20)
%22 = tail call i32 @heap_insert(%struct.heap* %1, i32 7)
%23 = tail call i32 @heap_parent(%struct.heap* %1, i32 7)
%24 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %23)
%25 = tail call i32 @heap_insert(%struct.heap* %1, i32 8)
%26 = tail call i32 @heap_parent(%struct.heap* %1, i32 8)
%27 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %26)
%28 = tail call i32 @heap_insert(%struct.heap* %1, i32 9)
%29 = tail call i32 @heap_parent(%struct.heap* %1, i32 9)
%30 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %29)
%31 = tail call i32 @heap_insert(%struct.heap* %1, i32 10)
%32 = tail call i32 @heap_parent(%struct.heap* %1, i32 10)
%33 = tail call i32 @heap_heapify(%struct.heap* %1, i32 %32)
%34 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%36 = tail call i32 @isEqual(i32 %35, i32 1)
%37 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%39 = tail call i32 @isEqual(i32 %38, i32 2)
%40 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%41 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%42 = tail call i32 @isEqual(i32 %41, i32 3)
%43 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%44 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%45 = tail call i32 @isEqual(i32 %44, i32 4)
%46 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%47 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%48 = tail call i32 @isEqual(i32 %47, i32 5)
%49 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%50 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%51 = tail call i32 @isEqual(i32 %50, i32 6)
%52 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%53 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%54 = tail call i32 @isEqual(i32 %53, i32 7)
%55 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%56 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%57 = tail call i32 @isEqual(i32 %56, i32 8)
%58 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%59 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%60 = tail call i32 @isEqual(i32 %59, i32 9)
%61 = tail call i32 @THEN(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%62 = tail call i32 @heap_minimum_delete(%struct.heap* %1)
%63 = tail call i32 @isEqual(i32 %62, i32 10)
%64 = tail call i32 @THEN(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%65 = tail call i32 @heap_isempty(%struct.heap* %1)
%66 = tail call i32 @isEqual(i32 %65, i32 1)
%67 = tail call i32 @heap_destroy(%struct.heap* %1)
ret i32 undef
}