// File: /workspace/github_c_makefile_star2_O3/CarlosLunaMota[P]BinaryTrees/main.c
// Function: rb_tree_fast_sequential_test
int rb_tree_fast_sequential_test(int max_size) {

    int i;
    rb_tree *tree  = new_rb_tree(MyComp);
    MyData  *data  = NULL;
    MyData  *found = NULL;

    // It is a rb_tree:
    if (is_rb_tree(tree) == NO) { return FAIL; }

    // It is empty:
    if (rb_tree_is_empty(tree) == NO) { return FAIL; }

    // Insert elements sequentially in the tree:
    for (i=0; i<max_size; i++) {
        
        data = (MyData *) malloc(sizeof(MyData));
        data->key = i;
        found = rb_tree_insert_max(tree, data);

        // It was not already there:
        if (found != NULL) { return FAIL; }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO)        { return FAIL; }

        // It is not empty:
        if (rb_tree_is_empty(tree) == YES) { return FAIL; }

    }

    // Check if all elements are there:
    data = (MyData *) malloc(sizeof(MyData));
    for (i=0; i<max_size; i++) {
        data->key = i;
        found = rb_tree_search(tree, data);
        if (found == NULL)            { return FAIL; }
        if (MyComp(data, found) != 0) { return FAIL; }
    }
    free(data);

    // Check if everything is correctly sorted forward...
    found = rb_tree_min(tree);
    if (found == NULL)   { return FAIL; }
    if (found->key != 0) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = rb_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = rb_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = rb_tree_max(tree);
    if (found == NULL)            { return FAIL; }
    if (found->key != max_size-1) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = rb_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = rb_tree_min(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break; 
        }
    }

    // Now, clean everything!
    for (i=max_size; i>0; i--) {
        
        found = rb_tree_remove_max(tree);

        // Not enought elements:
        if (found == NULL) { return FAIL; }
        else               { free(found); }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO) { return FAIL; }
    }
    
    // It is a rb_tree:
    if (is_rb_tree(tree) == NO) { return FAIL; }

    // It is empty:
    if (rb_tree_is_empty(tree) == NO) { return FAIL; }

    // Insert elements sequentially in the tree:
    for (i=max_size; i>0; i--) {
        
        data = (MyData *) malloc(sizeof(MyData));
        data->key = i;
        found = rb_tree_insert_min(tree, data);

        // It was not already there:
        if (found != NULL) { return FAIL; }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO)        { return FAIL; }

        // It is not empty:
        if (rb_tree_is_empty(tree) == YES) { return FAIL; }

    }

    // Check if all elements are there:
    data = (MyData *) malloc(sizeof(MyData));
    for (i=max_size; i>0; i--) {
        data->key = i;
        found = rb_tree_search(tree, data);
        if (found == NULL)            { return FAIL; }
        if (MyComp(data, found) != 0) { return FAIL; }
    }
    free(data);

    // Check if everything is correctly sorted forward...
    found = rb_tree_min(tree);
    if (found == NULL)   { return FAIL; }
    if (found->key != 1) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = rb_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = rb_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = rb_tree_max(tree);
    if (found == NULL)          { return FAIL; }
    if (found->key != max_size) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = rb_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = rb_tree_min(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break; 
        }
    }

    // Now, clean everything!
    for (i=max_size; i>0; i--) {
        
        found = rb_tree_remove_min(tree);

        // Not enought elements:
        if (found == NULL) { return FAIL; }
        else               { free(found); }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO) { return FAIL; }
    }
    
    // It is a rb_tree:
    if (is_rb_tree(tree) == NO) { return FAIL; }

    // It is empty:
    if (rb_tree_is_empty(tree) == NO) { return FAIL; }

    // Insert elements sequentially in the tree:
    for (i=1; i<=max_size; i++) {
        
        data = (MyData *) malloc(sizeof(MyData));
        data->key = i;
        found = rb_tree_insert_max(tree, data);

        // It was not already there:
        if (found != NULL) { return FAIL; }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO)        { return FAIL; }

        // It is not empty:
        if (rb_tree_is_empty(tree) == YES) { return FAIL; }

        data = (MyData *) malloc(sizeof(MyData));
        data->key = -i;
        found = rb_tree_insert_min(tree, data);

        // It was not already there:
        if (found != NULL) { return FAIL; }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO)        { return FAIL; }

        // It is not empty:
        if (rb_tree_is_empty(tree) == YES) { return FAIL; }

    }

    // Check if all elements are there:
    data = (MyData *) malloc(sizeof(MyData));
    for (i=1; i<=max_size; i++) {
        data->key = i;
        found = rb_tree_search(tree, data);
        if (found == NULL)            { return FAIL; }
        if (MyComp(data, found) != 0) { return FAIL; }
        data->key = -i;
        found = rb_tree_search(tree, data);
        if (found == NULL)            { return FAIL; }
        if (MyComp(data, found) != 0) { return FAIL; }
    }
    free(data);

    // Check if everything is correctly sorted forward...
    found = rb_tree_min(tree);
    if (found == NULL)           { return FAIL; }
    if (found->key != -max_size) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = rb_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = rb_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = rb_tree_max(tree);
    if (found == NULL)          { return FAIL; }
    if (found->key != max_size) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = rb_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = rb_tree_min(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break; 
        }
    }

    // Now, clean everything!
    for (i=1; i<=max_size; i++) {
        
        found = rb_tree_remove_max(tree);

        // Not enought elements:
        if (found == NULL) { return FAIL; }
        else               { free(found); }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO) { return FAIL; }

        found = rb_tree_remove_min(tree);

        // Not enought elements:
        if (found == NULL) { return FAIL; }
        else               { free(found); }

        // It is a rb_tree:
        if (is_rb_tree(tree) == NO) { return FAIL; }
    }
    
    // It is a rb_tree:
    if (is_rb_tree(tree) == NO) { return FAIL; }

    // It is empty:
    if (rb_tree_is_empty(tree) == NO) { return FAIL; }

    free(tree);
    
    return PASS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %r15d
leaq -0x2632(%rip), %rdi     # 0x166c
callq 0x97c1
movq %rax, %r14
movq %rax, %rdi
callq 0xb64d
movl $0x1, %ebx
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0x9eb4
testl %eax, %eax
je 0x3d75
testl %r15d, %r15d
jle 0x3d4b
xorl %ebp, %ebp
movl $0x4, %edi
callq 0x10d0
movl %ebp, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x98f7
testq %rax, %rax
jne 0x3d75
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0x9eb4
cmpl $0x1, %eax
je 0x3d75
incl %ebp
cmpl %ebp, %r15d
jne 0x3cd2
movl $0x4, %edi
callq 0x10d0
movq %rax, %r12
testl %r15d, %r15d
jle 0x3d58
xorl %ebp, %ebp
movl %ebp, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x9ee3
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
incl %ebp
cmpl %ebp, %r15d
jne 0x3d26
jmp 0x3d58
movl $0x4, %edi
callq 0x10d0
movq %rax, %r12
movq %r12, %rdi
callq 0x1120
movq %r14, %rdi
callq 0x9f7a
testq %rax, %rax
je 0x3d75
movq %rax, %r12
cmpl $0x0, (%rax)
je 0x3d91
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jge 0x3d75
movq %r14, %rdi
movq %r12, %rsi
callq 0xa0c1
testq %rax, %rax
jne 0x3d86
movq %r14, %rdi
callq 0x9fbc
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
movq %r14, %rdi
callq 0x9fbc
testq %rax, %rax
je 0x3d75
movq %rax, %r12
leal -0x1(%r15), %eax
cmpl %eax, (%r12)
jne 0x3d75
movq %r14, %rdi
movq %r12, %rsi
callq 0x9ffe
testq %rax, %rax
je 0x3ded
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jg 0x3dd0
jmp 0x3d75
movq %r14, %rdi
callq 0x9f7a
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
testl %r15d, %r15d
jle 0x3e43
leal 0x1(%r15), %ebp
movq %r14, %rdi
callq 0xa732
testq %rax, %rax
je 0x3d75
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
decl %ebp
cmpl $0x2, %ebp
jge 0x3e13
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0x9eb4
testl %eax, %eax
je 0x3d75
testl %r15d, %r15d
jle 0x3f07
movl %r15d, %r12d
movl $0x4, %edi
callq 0x10d0
movl %r12d, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x9d53
testq %rax, %rax
jne 0x3d75
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0x9eb4
cmpl $0x1, %eax
je 0x3d75
leal -0x1(%r12), %eax
cmpl $0x2, %r12d
movl %eax, %r12d
jge 0x3e6f
movl $0x4, %edi
callq 0x10d0
movq %rax, %r12
testl %r15d, %r15d
jle 0x3f14
movl %r15d, %r13d
movl %r13d, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x9ee3
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
leal -0x1(%r13), %eax
cmpl $0x2, %r13d
movl %eax, %r13d
jge 0x3ed4
jmp 0x3f14
movl $0x4, %edi
callq 0x10d0
movq %rax, %r12
movq %r12, %rdi
callq 0x1120
movq %r14, %rdi
callq 0x9f7a
testq %rax, %rax
je 0x3d75
movq %rax, %r12
cmpl $0x1, (%rax)
jne 0x3d75
movq %r14, %rdi
movq %r12, %rsi
callq 0xa0c1
testq %rax, %rax
je 0x3f59
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jl 0x3f39
jmp 0x3d75
movq %r14, %rdi
callq 0x9fbc
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
movq %r14, %rdi
callq 0x9fbc
testq %rax, %rax
je 0x3d75
movq %rax, %r12
cmpl %r15d, (%rax)
jne 0x3d75
movq %r14, %rdi
movq %r12, %rsi
callq 0x9ffe
testq %rax, %rax
je 0x3fb3
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jg 0x3f93
jmp 0x3d75
movq %r14, %rdi
callq 0x9f7a
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
testl %r15d, %r15d
jle 0x4009
leal 0x1(%r15), %ebp
movq %r14, %rdi
callq 0xa571
testq %rax, %rax
je 0x3d75
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
decl %ebp
cmpl $0x2, %ebp
jge 0x3fd9
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0x9eb4
testl %eax, %eax
je 0x3d75
testl %r15d, %r15d
jle 0x415e
movl %r15d, %eax
negl %eax
movq %rax, (%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x1, %r12d
movl $0x4, %edi
callq 0x10d0
movl %r12d, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x98f7
testq %rax, %rax
jne 0x4154
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x4154
movq %r14, %rdi
callq 0x9eb4
cmpl $0x1, %eax
je 0x4154
movl $0x4, %edi
callq 0x10d0
movl %ebp, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x9d53
testq %rax, %rax
jne 0x4154
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x4154
movq %r14, %rdi
callq 0x9eb4
cmpl $0x1, %eax
je 0x4154
movq (%rsp), %rax
addl %r12d, %eax
incl %eax
movl %r12d, %ecx
incl %ecx
decl %ebp
movl %ecx, %r12d
cmpl $0x1, %eax
jne 0x4046
movl $0x4, %edi
callq 0x10d0
movq %rax, %r12
testl %r15d, %r15d
jle 0x416b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x1, %r13d
movl %r13d, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x9ee3
testq %rax, %rax
je 0x4154
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x4154
movl %ebp, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x9ee3
testq %rax, %rax
je 0x4154
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x4154
movq (%rsp), %rax
addl %r13d, %eax
incl %eax
movl %r13d, %ecx
incl %ecx
decl %ebp
movl %ecx, %r13d
cmpl $0x1, %eax
jne 0x4102
jmp 0x416b
movl $0x1, %ebx
jmp 0x3d75
movl $0x4, %edi
callq 0x10d0
movq %rax, %r12
movq %r12, %rdi
callq 0x1120
movq %r14, %rdi
callq 0x9f7a
testq %rax, %rax
je 0x3d75
movq %rax, %r12
movl (%rax), %eax
addl %r15d, %eax
jne 0x3d75
movq %r14, %rdi
movq %r12, %rsi
callq 0xa0c1
testq %rax, %rax
je 0x41b2
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jl 0x4192
jmp 0x3d75
movq %r14, %rdi
callq 0x9fbc
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
movq %r14, %rdi
callq 0x9fbc
testq %rax, %rax
je 0x3d75
movq %rax, %r12
cmpl %r15d, (%rax)
jne 0x3d75
movq %r14, %rdi
movq %r12, %rsi
callq 0x9ffe
testq %rax, %rax
je 0x420c
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jg 0x41ec
jmp 0x3d75
movq %r14, %rdi
callq 0x9f7a
testq %rax, %rax
je 0x3d75
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x3d75
testl %r15d, %r15d
jle 0x4285
movq %r14, %rdi
callq 0xa732
testq %rax, %rax
je 0x3d75
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0xa571
testq %rax, %rax
je 0x3d75
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
decl %r15d
jne 0x422e
movq %r14, %rdi
callq 0xb64d
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0x9eb4
testl %eax, %eax
je 0x3d75
movq %r14, %rdi
callq 0x1120
xorl %ebx, %ebx
jmp 0x3d75