#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 TreeNode {
  int dummy;
};
struct Tree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
struct Tree *tree_create(struct TreeNode *);
int /*<<< orphan*/ tree_delete(struct Tree *);
int tree_evaluate(struct Tree *, int *);
struct TreeNode *tree_node_from_operator(char, struct TreeNode *,
                                         struct TreeNode *);
struct TreeNode *tree_node_from_value(int);
int /*<<< orphan*/ tree_print(struct Tree *);
int test_tree() {
  int value, error;
  struct TreeNode *valueNode1 = tree_node_from_value(6);
  struct TreeNode *valueNode2 = tree_node_from_value(10);
  struct TreeNode *operatorNode =
      tree_node_from_operator('+', valueNode1, valueNode2);
  struct Tree *tree = tree_create(operatorNode);
  tree_print(tree);
  value = tree_evaluate(tree, &error);
  if (error != 0) {
    printf("An error occurred while evaluting the example tree\n");
    tree_delete(tree);
    return 0;
  }
  if (value != 16) {
    printf("Error while evaluating value of example tree: got %d but expected "
           "16\n",
           value);
    tree_delete(tree);
    return 0;
  }
  tree_delete(tree);
  return 1;
}


x86 assembly (clang, -O0):
<test_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x6,%edi
call   1050 <tree_node_from_value@plt>
mov    %rax,-0x18(%rbp)
mov    $0xa,%edi
call   1050 <tree_node_from_value@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x2b,%edi
call   1060 <tree_node_from_operator@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <tree_create@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <tree_print@plt>
mov    -0x30(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <tree_evaluate@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11fd <test_tree+0x8d>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <tree_delete@plt>
movl   $0x0,-0x4(%rbp)
jmp    123d <test_tree+0xcd>
cmpl   $0x10,-0x8(%rbp)
je     122d <test_tree+0xbd>
mov    -0x8(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <tree_delete@plt>
movl   $0x0,-0x4(%rbp)
jmp    123d <test_tree+0xcd>
mov    -0x30(%rbp),%rdi
call   1040 <tree_delete@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_tree>:
push   %rbp
push   %rbx
push   %rax
mov    $0x6,%edi
call   1060 <tree_node_from_value@plt>
mov    %rax,%rbx
mov    $0xa,%edi
call   1060 <tree_node_from_value@plt>
mov    $0x2b,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1070 <tree_node_from_operator@plt>
mov    %rax,%rdi
call   1030 <tree_create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <tree_print@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <tree_evaluate@plt>
cmpl   $0x0,0x4(%rsp)
je     11e1 <test_tree+0x61>
lea    0xe6e(%rip),%rdi
call   1050 <puts@plt>
xor    %ebp,%ebp
jmp    11fd <test_tree+0x7d>
mov    $0x1,%ebp
cmp    $0x10,%eax
je     11fd <test_tree+0x7d>
lea    0xe0e(%rip),%rdi
xor    %ebp,%ebp
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1040 <tree_delete@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
%struct.Tree = type { i32 }
@.str = [52 x i8] c"An error occurred while evaluting the example tree\0A\00"
@.str.1 = [70 x i8] c"Error while evaluating value of example tree: got %d but expected 16\0A\00"
define i32 @test_tree() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.TreeNode*
%5 = alloca %struct.TreeNode*
%6 = alloca %struct.TreeNode*
%7 = alloca %struct.Tree*
%8 = call %struct.TreeNode* @tree_node_from_value(i32 6)
store %struct.TreeNode* %8, %struct.TreeNode** %4
%9 = call %struct.TreeNode* @tree_node_from_value(i32 10)
store %struct.TreeNode* %9, %struct.TreeNode** %5
%10 = load %struct.TreeNode*, %struct.TreeNode** %4
%11 = load %struct.TreeNode*, %struct.TreeNode** %5
%12 = call %struct.TreeNode* @tree_node_from_operator(i8 signext 43, %struct.TreeNode* %10, %struct.TreeNode* %11)
store %struct.TreeNode* %12, %struct.TreeNode** %6
%13 = load %struct.TreeNode*, %struct.TreeNode** %6
%14 = call %struct.Tree* @tree_create(%struct.TreeNode* %13)
store %struct.Tree* %14, %struct.Tree** %7
%15 = load %struct.Tree*, %struct.Tree** %7
%16 = call i32 @tree_print(%struct.Tree* %15)
%17 = load %struct.Tree*, %struct.Tree** %7
%18 = call i32 @tree_evaluate(%struct.Tree* %17, i32* %3)
store i32 %18, i32* %2
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%23 = load %struct.Tree*, %struct.Tree** %7
%24 = call i32 @tree_delete(%struct.Tree* %23)
store i32 0, i32* %1
br label %36
25: ; preds = %0
%26 = load i32, i32* %2
%27 = icmp ne i32 %26, 16
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load %struct.Tree*, %struct.Tree** %7
%32 = call i32 @tree_delete(%struct.Tree* %31)
store i32 0, i32* %1
br label %36
33: ; preds = %25
%34 = load %struct.Tree*, %struct.Tree** %7
%35 = call i32 @tree_delete(%struct.Tree* %34)
store i32 1, i32* %1
br label %36
36: ; preds = %33, %28, %21
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
%struct.Tree = type { i32 }
@.str.1 = [70 x i8] c"Error while evaluating value of example tree: got %d but expected 16\0A\00"
@str = [51 x i8] c"An error occurred while evaluting the example tree\00"
define i32 @test_tree() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call %struct.TreeNode* @tree_node_from_value(i32 6)
%4 = tail call %struct.TreeNode* @tree_node_from_value(i32 10)
%5 = tail call %struct.TreeNode* @tree_node_from_operator(i8 signext 43, %struct.TreeNode* %3, %struct.TreeNode* %4)
%6 = tail call %struct.Tree* @tree_create(%struct.TreeNode* %5)
%7 = tail call i32 @tree_print(%struct.Tree* %6)
%8 = call i32 @tree_evaluate(%struct.Tree* %6, i32* %1)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %17
13: ; preds = %0
%14 = icmp eq i32 %8, 16
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %17
17: ; preds = %13, %15, %11
%18 = phi i32 [ 0, %11 ], [ 0, %15 ], [ 1, %13 ]
%19 = call i32 @tree_delete(%struct.Tree* %6)
ret i32 %18
}