#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 */
struct node *build();
int count_red(struct node *, int);
int count_red_children(struct node *, int);
int /*<<< orphan*/ delete_tree(struct node *);
int /*<<< orphan*/ display_tree(struct node *);
int /*<<< orphan*/ printf(char *, ...);
struct node *rand_insert(struct node *, int);
int test_me(int);
int test_me_2(int);
int main(int argc, char *argv[]) {
  struct node *head;
  int i, count = 0;
  if (argc != 2) {
    printf("Syntax Error : tree numb_of_elements");
    return 1;
  }
  head = build();
  display_tree(head);
  printf("\n");
  for (i = 0; i < 10; i++)
    head = rand_insert(head, i);
  display_tree(head);
  printf("\n");
  count = count_red(head, 1);
  printf("Count RED : %d \n", count);
  count = count_red_children(head, 1);
  printf("Count of red nodes with non red children: %d \n", count);
  delete_tree(head);
  printf("Val 1 = %d", test_me(1));
  printf("Val 2 = %d", test_me_2(1));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d1 <main+0x41>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c1 <main+0x131>
mov    $0x0,%al
call   1060 <build@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <display_tree@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    1222 <main+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <rand_insert@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fa <main+0x6a>
mov    -0x18(%rbp),%rdi
call   1080 <display_tree@plt>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <count_red@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1050 <count_red_children@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <delete_tree@plt>
mov    $0x1,%edi
call   1090 <test_me@plt>
mov    %eax,%esi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10a0 <test_me_2@plt>
mov    %eax,%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    12d6 <main+0x136>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <build@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <display_tree@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x2,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x3,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x4,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x5,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x6,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x7,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x8,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rdi
mov    $0x9,%esi
call   1030 <rand_insert@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <display_tree@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <count_red@plt>
lea    0xdb3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <count_red_children@plt>
lea    0xda7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   10c0 <delete_tree@plt>
mov    $0x1,%edi
call   10a0 <test_me@plt>
lea    0xdb4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10b0 <test_me_2@plt>
lea    0xda5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12e9 <main+0x149>
lea    0xd23(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [37 x i8] c"Syntax Error : tree numb_of_elements\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [17 x i8] c"Count RED : %d \0A\00"
@.str.3 = [47 x i8] c"Count of red nodes with non red children: %d \0A\00"
@.str.4 = [11 x i8] c"Val 1 = %d\00"
@.str.5 = [11 x i8] c"Val 2 = %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.node*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %46
13: ; preds = %2
%14 = call %struct.node* (...) @build()
store %struct.node* %14, %struct.node** %6
%15 = load %struct.node*, %struct.node** %6
%16 = call i32 @display_tree(%struct.node* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %18
18: ; preds = %25, %13
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load %struct.node*, %struct.node** %6
%23 = load i32, i32* %7
%24 = call %struct.node* @rand_insert(%struct.node* %22, i32 %23)
store %struct.node* %24, %struct.node** %6
br label %25
25: ; preds = %21
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %18
28: ; preds = %18
%29 = load %struct.node*, %struct.node** %6
%30 = call i32 @display_tree(%struct.node* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = load %struct.node*, %struct.node** %6
%33 = call i32 @count_red(%struct.node* %32, i32 1)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load %struct.node*, %struct.node** %6
%37 = call i32 @count_red_children(%struct.node* %36, i32 1)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load %struct.node*, %struct.node** %6
%41 = call i32 @delete_tree(%struct.node* %40)
%42 = call i32 @test_me(i32 1)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = call i32 @test_me_2(i32 1)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %44)
store i32 0, i32* %3
br label %46
46: ; preds = %28, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [37 x i8] c"Syntax Error : tree numb_of_elements\00"
@.str.2 = [17 x i8] c"Count RED : %d \0A\00"
@.str.3 = [47 x i8] c"Count of red nodes with non red children: %d \0A\00"
@.str.4 = [11 x i8] c"Val 1 = %d\00"
@.str.5 = [11 x i8] c"Val 2 = %d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %31
6: ; preds = %2
%7 = tail call %struct.node* (...) @build()
%8 = tail call i32 @display_tree(%struct.node* %7)
%9 = tail call i32 @putchar(i32 10)
%10 = tail call %struct.node* @rand_insert(%struct.node* %7, i32 0)
%11 = tail call %struct.node* @rand_insert(%struct.node* %10, i32 1)
%12 = tail call %struct.node* @rand_insert(%struct.node* %11, i32 2)
%13 = tail call %struct.node* @rand_insert(%struct.node* %12, i32 3)
%14 = tail call %struct.node* @rand_insert(%struct.node* %13, i32 4)
%15 = tail call %struct.node* @rand_insert(%struct.node* %14, i32 5)
%16 = tail call %struct.node* @rand_insert(%struct.node* %15, i32 6)
%17 = tail call %struct.node* @rand_insert(%struct.node* %16, i32 7)
%18 = tail call %struct.node* @rand_insert(%struct.node* %17, i32 8)
%19 = tail call %struct.node* @rand_insert(%struct.node* %18, i32 9)
%20 = tail call i32 @display_tree(%struct.node* %19)
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 @count_red(%struct.node* %19, i32 1)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = tail call i32 @count_red_children(%struct.node* %19, i32 1)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = tail call i32 @delete_tree(%struct.node* %19)
%27 = tail call i32 @test_me(i32 1)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = tail call i32 @test_me_2(i32 1)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %6, %4
%32 = phi i32 [ 1, %4 ], [ 0, %6 ]
ret i32 %32
}