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

/* Variables and functions */
int height(struct node *);
int /*<<< orphan*/ printGivenLevel(struct node *, int);
int /*<<< orphan*/ printf(char *);
void printLevelOrder(struct node *root) {
  int h = height(root);
  int i, j;
  for (i = 1; i <= h; i++) {
    for (j = h; j > h / 2; j--)
      printf(" ");
    printGivenLevel(root, i);
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<printLevelOrder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <height@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11bf <printLevelOrder+0x8f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jle    1199 <printLevelOrder+0x69>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <printLevelOrder+0x31>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <printGivenLevel@plt>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114f <printLevelOrder+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printLevelOrder>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1050 <height@plt>
test   %eax,%eax
jle    11a3 <printLevelOrder+0x73>
mov    %eax,%r15d
mov    %eax,%ebp
shr    %ebp
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
cmp    %ebp,%ebx
jg     1170 <printLevelOrder+0x40>
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <printGivenLevel@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%r12),%eax
cmp    %r15d,%r12d
mov    %eax,%r12d
jne    1160 <printLevelOrder+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @printLevelOrder(%struct.node* %0) {
%2 = alloca %struct.node*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store %struct.node* %0, %struct.node** %2
%6 = load %struct.node*, %struct.node** %2
%7 = call i32 @height(%struct.node* %6)
store i32 %7, i32* %3
store i32 1, i32* %4
br label %8
8: ; preds = %29, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = icmp sle i32 %9, %10
br i1 %11, label %12, label %32
12: ; preds = %8
%13 = load i32, i32* %3
store i32 %13, i32* %5
br label %14
14: ; preds = %21, %12
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
%18 = icmp sgt i32 %15, %17
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19
%22 = load i32, i32* %5
%23 = add nsw i32 %22, -1
store i32 %23, i32* %5
br label %14
24: ; preds = %14
%25 = load %struct.node*, %struct.node** %2
%26 = load i32, i32* %4
%27 = call i32 @printGivenLevel(%struct.node* %25, i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %24
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %8
32: ; preds = %8
ret void
}

LLVM IR (-O2):
%struct.node = type { i32 }
define void @printLevelOrder(%struct.node* %0) {
%2 = tail call i32 @height(%struct.node* %0)
%3 = icmp slt i32 %2, 1
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = lshr i32 %2, 1
br label %6
6: ; preds = %4, %13
%7 = phi i32 [ 1, %4 ], [ %16, %13 ]
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ %11, %8 ], [ %2, %6 ]
%10 = tail call i32 @putchar(i32 32)
%11 = add nsw i32 %9, -1
%12 = icmp sgt i32 %11, %5
br i1 %12, label %8, label %13
13: ; preds = %8
%14 = tail call i32 @printGivenLevel(%struct.node* %0, i32 %7)
%15 = tail call i32 @putchar(i32 10)
%16 = add nuw i32 %7, 1
%17 = icmp eq i32 %7, %2
br i1 %17, label %18, label %6
18: ; preds = %13, %1
ret void
}