#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*/ printf(char *, char *);
int scanf(char *, int *);
struct Node *tree_add(struct Node *, int);
int /*<<< orphan*/ tree_destroy(struct Node *);
scalar_t__ tree_get_height_and_check_balance(struct Node *, int /*<<< orphan*/);
int main() {
  struct Node *tree = NULL;
  int x;
  while ((scanf("%d", &x) == 1) && (x != 0)) {
    tree = tree_add(tree, x);
  }
  printf("%s\n", tree_get_height_and_check_balance(tree, 0) ? "YES" : "NO");
  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
xor    %esi,%esi
call   1060 <tree_get_height_and_check_balance@plt>
mov    %rax,%rcx
lea    0xe40(%rip),%rsi
lea    0xe35(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <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
xor    %esi,%esi
call   1060 <tree_get_height_and_check_balance@plt>
test   %rax,%rax
lea    0xe44(%rip),%rax
lea    0xe39(%rip),%rsi
cmove  %rax,%rsi
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <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"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [4 x i8] c"YES\00"
@.str.3 = [3 x i8] c"NO\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 i64 @tree_get_height_and_check_balance(%struct.Node* %17, i32 0)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%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"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [4 x i8] c"YES\00"
@.str.3 = [3 x i8] c"NO\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 i64 @tree_get_height_and_check_balance(%struct.Node* %18, i32 0)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @tree_destroy(%struct.Node* %18)
ret i32 0
}