#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_leafs(struct Node *);
int main() {
  struct Node *tree = NULL;
  int x;
  while ((scanf("%d", &x) == 1) && (x != 0)) {
    tree = tree_add(tree, x);
  }
  tree_print_leafs(tree);
  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   1040 <scanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x15(%rbp)
jne    1191 <main+0x41>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%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>
mov    -0x10(%rbp),%rdi
call   1050 <tree_print_leafs@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    0xc(%rsp),%rsi
call   1040 <scanf@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
jne    11b3 <main+0x63>
mov    0xc(%rsp),%esi
test   %esi,%esi
je     11b3 <main+0x63>
xor    %ebx,%ebx
lea    0xe7e(%rip),%r14
lea    0xc(%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   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11b3 <main+0x63>
mov    0xc(%rsp),%esi
test   %esi,%esi
jne    1190 <main+0x40>
mov    %rbx,%rdi
call   1050 <tree_print_leafs@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
store i32 0, i32* %1
store %struct.Node* null, %struct.Node** %2
br label %4
4: ; preds = %12, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br label %10
10: ; preds = %7, %4
%11 = phi i1 [ false, %4 ], [ %9, %7 ]
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = load %struct.Node*, %struct.Node** %2
%14 = load i32, i32* %3
%15 = call %struct.Node* @tree_add(%struct.Node* %13, i32 %14)
store %struct.Node* %15, %struct.Node** %2
br label %4
16: ; preds = %10
%17 = load %struct.Node*, %struct.Node** %2
%18 = call i32 @tree_print_leafs(%struct.Node* %17)
%19 = call i32 @putchar(i8 signext 10)
%20 = load %struct.Node*, %struct.Node** %2
%21 = call i32 @tree_destroy(%struct.Node* %20)
%22 = load i32, i32* %1
ret i32 %22
}

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