#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 bit_floor_log2(int);
int /*<<< orphan*/ printf(char *, ...);
void heap_print(int keys[], unsigned n) {
  int k, level = 0;
  for (k = 1; k <= n; k++) {
    if (level != bit_floor_log2(k)) {
      level = bit_floor_log2(k);
      printf("\n");
    }
    printf("%d ", keys[k]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<heap_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     11a4 <heap_print+0x84>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <bit_floor_log2@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
je     117d <heap_print+0x5d>
mov    -0x10(%rbp),%edi
call   1040 <bit_floor_log2@plt>
mov    %eax,-0x14(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <heap_print+0x1d>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heap_print>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     1197 <heap_print+0x67>
mov    %esi,%r15d
mov    %rdi,%r14
add    $0x1,%r15d
mov    $0x1,%ebx
lea    0xeae(%rip),%r12
xor    %ebp,%ebp
jmp    1177 <heap_print+0x47>
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     1197 <heap_print+0x67>
mov    %ebx,%edi
call   1050 <bit_floor_log2@plt>
cmp    %eax,%ebp
je     1160 <heap_print+0x30>
mov    %ebx,%edi
call   1050 <bit_floor_log2@plt>
mov    %eax,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <heap_print+0x30>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c"%d \00"
define void @heap_print(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
store i32 0, i32* %6
store i32 1, i32* %5
br label %7
7: ; preds = %27, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp ule i32 %8, %9
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = load i32, i32* %6
%13 = load i32, i32* %5
%14 = call i32 @bit_floor_log2(i32 %13)
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* %5
%18 = call i32 @bit_floor_log2(i32 %17)
store i32 %18, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %16, %11
%21 = load i32*, i32** %3
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %20
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %7
30: ; preds = %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d \00"
define void @heap_print(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = add i32 %1, 1
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %4, %16
%8 = phi i64 [ 1, %4 ], [ %21, %16 ]
%9 = phi i32 [ 0, %4 ], [ %17, %16 ]
%10 = trunc i64 %8 to i32
%11 = tail call i32 @bit_floor_log2(i32 %10)
%12 = icmp eq i32 %9, %11
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = tail call i32 @bit_floor_log2(i32 %10)
%15 = tail call i32 @putchar(i32 10)
br label %16
16: ; preds = %13, %7
%17 = phi i32 [ %14, %13 ], [ %9, %7 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %8
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %8, 1
%22 = icmp eq i64 %21, %6
br i1 %22, label %23, label %7
23: ; preds = %16, %2
%24 = tail call i32 @putchar(i32 10)
ret void
}