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

    int i;
    sp_tree *tree  = new_sp_tree(MyComp);
    MyData  *data  = NULL;
    MyData  *found = NULL;

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

    // It is empty:
    if (sp_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 = sp_tree_insert_max(tree, data);

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

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

        // It is not empty:
        if (sp_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 = sp_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 = sp_tree_min(tree);
    if (found == NULL)   { return FAIL; }
    if (found->key != 0) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = sp_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = sp_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = sp_tree_max(tree);
    if (found == NULL)            { return FAIL; }
    if (found->key != max_size-1) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = sp_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = sp_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 = sp_tree_remove_max(tree);

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

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

    // It is empty:
    if (sp_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 = sp_tree_insert_min(tree, data);

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

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

        // It is not empty:
        if (sp_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 = sp_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 = sp_tree_min(tree);
    if (found == NULL)   { return FAIL; }
    if (found->key != 1) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = sp_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = sp_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = sp_tree_max(tree);
    if (found == NULL)          { return FAIL; }
    if (found->key != max_size) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = sp_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = sp_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 = sp_tree_remove_min(tree);

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

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

    // It is empty:
    if (sp_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 = sp_tree_insert_max(tree, data);

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

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

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

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

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

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

        // It is not empty:
        if (sp_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 = sp_tree_search(tree, data);
        if (found == NULL)            { return FAIL; }
        if (MyComp(data, found) != 0) { return FAIL; }
        data->key = -i;
        found = sp_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 = sp_tree_min(tree);
    if (found == NULL)           { return FAIL; }
    if (found->key != -max_size) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = sp_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = sp_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = sp_tree_max(tree);
    if (found == NULL)          { return FAIL; }
    if (found->key != max_size) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = sp_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = sp_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 = sp_tree_remove_max(tree);

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

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

        found = sp_tree_remove_min(tree);

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

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

    // It is empty:
    if (sp_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 -0x4524(%rip), %rdi     # 0x121c
callq 0xb14a
movq %rax, %r14
movq %rax, %rdi
callq 0xbfba
pushq $0x1
popq %rbx
testl %eax, %eax
je 0x57e0
movq %r14, %rdi
callq 0xb772
testl %eax, %eax
je 0x57e0
xorl %ebx, %ebx
testl %r15d, %r15d
movl $0x0, %ebp
cmovgl %r15d, %ebp
pushq $0x4
popq %r12
movq %r12, %rdi
callq 0x10d0
movq %rax, %r13
cmpl %ebx, %ebp
je 0x57b9
movl %ebx, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xb261
testq %rax, %rax
jne 0x57dd
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
je 0x57dd
movq %r14, %rdi
callq 0xb772
incl %ebx
cmpl $0x1, %eax
jne 0x5779
jmp 0x57dd
xorl %ebx, %ebx
cmpl %ebx, %ebp
je 0x57f1
movl %ebx, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xb7a1
testq %rax, %rax
je 0x57dd
movl (%r13), %ecx
incl %ebx
cmpl (%rax), %ecx
je 0x57bb
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xb21f
testq %rax, %rax
pushq $0x1
popq %rbx
je 0x57e0
movq %rax, %r12
cmpl $0x0, (%rax)
jne 0x57e0
jmp 0x581e
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jge 0x57e0
movq %r14, %rdi
movq %r12, %rsi
callq 0xb322
testq %rax, %rax
jne 0x5813
movq %r14, %rdi
callq 0xb826
testq %rax, %rax
je 0x57e0
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x57e0
movq %r14, %rdi
callq 0xb826
testq %rax, %rax
je 0x57e0
movq %rax, %r12
leal -0x1(%r15), %eax
cmpl %eax, (%r12)
jne 0x57e0
movq %r14, %rdi
movq %r12, %rsi
callq 0xb868
testq %rax, %rax
je 0x587d
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jg 0x585d
jmp 0x57e0
movq %r14, %rdi
callq 0xb21f
testq %rax, %rax
je 0x57e0
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x57e0
leal 0x1(%r15), %ebx
decl %ebx
movq %r14, %rdi
testl %ebx, %ebx
jle 0x58ce
callq 0xba27
testq %rax, %rax
je 0x57dd
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
jne 0x589e
jmp 0x57dd
callq 0xbfba
testl %eax, %eax
je 0x57dd
movq %r14, %rdi
callq 0xb772
testl %eax, %eax
je 0x57dd
pushq $0x4
popq %r12
movl %r15d, %ebx
movq %r12, %rdi
callq 0x10d0
movq %rax, %r13
testl %ebx, %ebx
jle 0x593d
movl %ebx, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xb5fb
testq %rax, %rax
jne 0x57dd
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
je 0x57dd
movq %r14, %rdi
callq 0xb772
decl %ebx
cmpl $0x1, %eax
jne 0x58f2
jmp 0x57dd
movl %r15d, %ebx
testl %ebx, %ebx
jle 0x596b
movl %ebx, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xb7a1
testq %rax, %rax
je 0x57dd
movl (%r13), %ecx
decl %ebx
cmpl (%rax), %ecx
je 0x5940
jmp 0x57dd
movq %r13, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xb21f
testq %rax, %rax
je 0x57dd
movq %rax, %r12
cmpl $0x1, (%rax)
jne 0x57dd
movq %r14, %rdi
movq %r12, %rsi
callq 0xb322
testq %rax, %rax
je 0x59b0
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jl 0x5990
jmp 0x57dd
movq %r14, %rdi
callq 0xb826
testq %rax, %rax
je 0x57dd
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x57dd
movq %r14, %rdi
callq 0xb826
testq %rax, %rax
je 0x57dd
movq %rax, %r12
cmpl %r15d, (%rax)
jne 0x57dd
movq %r14, %rdi
movq %r12, %rsi
callq 0xb868
testq %rax, %rax
je 0x5a0a
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jg 0x59ea
jmp 0x57dd
movq %r14, %rdi
callq 0xb21f
testq %rax, %rax
je 0x57dd
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x57dd
leal 0x1(%r15), %ebx
decl %ebx
movq %r14, %rdi
testl %ebx, %ebx
jle 0x5a5b
callq 0xb9cc
testq %rax, %rax
je 0x57dd
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
jne 0x5a2b
jmp 0x57dd
callq 0xbfba
testl %eax, %eax
je 0x57dd
movq %r14, %rdi
callq 0xb772
testl %eax, %eax
pushq $0x1
popq %rbx
je 0x57e0
leal 0x1(%rbp), %eax
movl %eax, 0x4(%rsp)
negl %ebp
pushq $0x1
popq %rax
pushq $-0x1
popq %rcx
movl %ecx, (%rsp)
movl %eax, %r12d
leal (%r12,%rbp), %ebx
pushq $0x4
popq %rdi
callq 0x10d0
movq %rax, %r13
cmpl $0x1, %ebx
je 0x5b2e
movl %r12d, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xb261
testq %rax, %rax
jne 0x57dd
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
je 0x57dd
movq %r14, %rdi
callq 0xb772
cmpl $0x1, %eax
je 0x57dd
pushq $0x4
popq %rdi
callq 0x10d0
movl (%rsp), %ecx
movl %ecx, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0xb5fb
testq %rax, %rax
jne 0x57dd
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
je 0x57dd
movq %r14, %rdi
callq 0xb772
incl %r12d
decl (%rsp)
cmpl $0x1, %eax
jne 0x5a90
jmp 0x57dd
pushq $0x1
popq %rax
pushq $-0x1
popq %rcx
movl %ecx, (%rsp)
movl %eax, %ebx
movl %eax, %r12d
leal (%r12,%rbp), %eax
cmpl $0x1, %eax
je 0x5b97
movl %r12d, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xb7a1
testq %rax, %rax
je 0x57e0
movl (%r13), %ecx
cmpl (%rax), %ecx
jne 0x57e0
movl (%rsp), %eax
movl %eax, (%r13)
movq %r14, %rdi
movq %r13, %rsi
callq 0xb7a1
testq %rax, %rax
je 0x57e0
movl (%r13), %ecx
incl %r12d
decl (%rsp)
cmpl (%rax), %ecx
je 0x5b3c
jmp 0x57e0
movq %r13, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xb21f
testq %rax, %rax
je 0x57e0
movq %rax, %r12
movl (%rax), %eax
addl %r15d, %eax
jne 0x57e0
movq %r14, %rdi
movq %r12, %rsi
callq 0xb322
testq %rax, %rax
je 0x5bde
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jl 0x5bbe
jmp 0x57e0
movq %r14, %rdi
callq 0xb826
testq %rax, %rax
je 0x57e0
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x57e0
movq %r14, %rdi
callq 0xb826
testq %rax, %rax
je 0x57e0
movq %rax, %r12
cmpl %r15d, (%rax)
jne 0x57e0
movq %r14, %rdi
movq %r12, %rsi
callq 0xb868
testq %rax, %rax
je 0x5c38
movl (%r12), %ecx
movq %rax, %r12
cmpl (%rax), %ecx
jg 0x5c18
jmp 0x57e0
movq %r14, %rdi
callq 0xb21f
testq %rax, %rax
je 0x57e0
movl (%r12), %ecx
cmpl (%rax), %ecx
jne 0x57e0
decl 0x4(%rsp)
je 0x5cae
movq %r14, %rdi
callq 0xba27
testq %rax, %rax
je 0x57e0
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
je 0x57e0
movq %r14, %rdi
callq 0xb9cc
testq %rax, %rax
je 0x57e0
movq %rax, %rdi
callq 0x1120
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
jne 0x5c55
jmp 0x57e0
movq %r14, %rdi
callq 0xbfba
testl %eax, %eax
je 0x57e0
movq %r14, %rdi
callq 0xb772
testl %eax, %eax
je 0x57e0
movq %r14, %rdi
callq 0x1120
xorl %ebx, %ebx
jmp 0x57e0