#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 /*<<< orphan*/ putchar(char);
int scanf(char *, int *);
struct Node *tree_add(struct Node *, int);
int /*<<< orphan*/ tree_destroy(struct Node *);
int /*<<< orphan*/ tree_print(struct Node *, int /*<<< orphan*/, int);
int main() {
  struct Node *tree = NULL;
  int x;
  while ((scanf("%d", &x) == 1) && (x != 0)) {
    tree = tree_add(tree, x);
  }
  int height;
  scanf("%d", &height);
  tree_print(tree, 0, height);
  putchar('\n');
  tree_destroy(tree);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe92(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x19(%rbp)
jne    1191 <main+0x41>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a1 <main+0x51>
jmp    11b6 <main+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <tree_add@plt>
mov    %rax,-0x10(%rbp)
jmp    1167 <main+0x17>
lea    0xe43(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1040 <tree_print@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rdi
call   1060 <tree_destroy@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea0(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
jne    11b3 <main+0x63>
mov    0x8(%rsp),%esi
test   %esi,%esi
je     11b3 <main+0x63>
xor    %ebx,%ebx
lea    0xe7e(%rip),%r14
lea    0x8(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <tree_add@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11b3 <main+0x63>
mov    0x8(%rsp),%esi
test   %esi,%esi
jne    1190 <main+0x40>
lea    0xe46(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <tree_print@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <tree_destroy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Node = type { i32 }
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.Node*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store %struct.Node* null, %struct.Node** %2
br label %5
5: ; preds = %13, %0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ false, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = load %struct.Node*, %struct.Node** %2
%15 = load i32, i32* %3
%16 = call %struct.Node* @tree_add(%struct.Node* %14, i32 %15)
store %struct.Node* %16, %struct.Node** %2
br label %5
17: ; preds = %11
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%19 = load %struct.Node*, %struct.Node** %2
%20 = load i32, i32* %4
%21 = call i32 @tree_print(%struct.Node* %19, i32 0, i32 %20)
%22 = call i32 @putchar(i8 signext 10)
%23 = load %struct.Node*, %struct.Node** %2
%24 = call i32 @tree_destroy(%struct.Node* %23)
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.Node = type { i32 }
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 1
%6 = load i32, i32* %1
%7 = icmp ne i32 %6, 0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %18
9: ; preds = %0, %9
%10 = phi i32 [ %15, %9 ], [ %6, %0 ]
%11 = phi %struct.Node* [ %12, %9 ], [ null, %0 ]
%12 = call %struct.Node* @tree_add(%struct.Node* %11, i32 %10)
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%14 = icmp eq i32 %13, 1
%15 = load i32, i32* %1
%16 = icmp ne i32 %15, 0
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %9, label %18
18: ; preds = %9, %0
%19 = phi %struct.Node* [ null, %0 ], [ %12, %9 ]
%20 = bitcast i32* %2 to i8*
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%22 = load i32, i32* %2
%23 = call i32 @tree_print(%struct.Node* %19, i32 0, i32 %22)
%24 = call i32 @putchar(i8 signext 10)
%25 = call i32 @tree_destroy(%struct.Node* %19)
ret i32 0
}