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

    int i;
    bs_tree *tree  = new_bs_tree(MyComp);
    MyData  *data  = NULL;
    MyData  *found = NULL;

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

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

    // Insert elements randomly in the tree:
    for (i=0; i<max_size*10; i++) {
        
        data = (MyData *) malloc(sizeof(MyData));
        data->key = rand() % max_size;

        // Insert it:
        found = bs_tree_insert(tree, data);

        // If it was already there:
        if (found != NULL) { free(found); }

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

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

    // Check if everything is correctly sorted forward...
    found = bs_tree_min(tree);
    if (found == NULL) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = bs_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = bs_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = bs_tree_max(tree);
    if (found == NULL) { return FAIL; }
    while (found != NULL) {
        data  = found;
        found = bs_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = bs_tree_min(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break; 
        }
    }

    // Remove elements randomly from the tree:
    for (i=0; i<max_size*5; i++) {
        
        data = (MyData *) malloc(sizeof(MyData));
        data->key = rand() % max_size;

        // Remove element
        found = bs_tree_remove(tree, data);

        // If it was there:
        if (found != NULL) { free(found); }

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

    // Check if everything is correctly sorted forward...
    found = bs_tree_min(tree);
    while (found != NULL) {
        data  = found;
        found = bs_tree_next(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) >= 0) { return FAIL; }
        } else { 
            found = bs_tree_max(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break;
        }
    }

    // ...and backwards.
    found = bs_tree_max(tree);
    while (found != NULL) {
        data  = found;
        found = bs_tree_prev(tree, data);
        if (found != NULL) {
            if (MyComp(data, found) <= 0) { return FAIL; }
        } else { 
            found = bs_tree_min(tree);
            if (found == NULL)            { return FAIL; }
            if (MyComp(data, found) != 0) { return FAIL; }
            break; 
        }
    }

    // Now, clean everything!
    bs_tree_remove_all(tree, free);

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

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

    free(tree);
    
    return PASS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
leaq -0x1592(%rip), %rdi     # 0x11e0
callq 0xc5c0
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0xf9c0
cmpl $0x0, %eax
jne 0x27a5
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x18(%rbp), %rdi
callq 0xccf0
cmpl $0x0, %eax
jne 0x27bf
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
imull $0xa, -0x8(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2857
movl $0x4, %edi
callq 0x10a0
movq %rax, -0x20(%rbp)
callq 0x10d0
cltd
idivl -0x8(%rbp)
movq -0x20(%rbp), %rax
movl %edx, (%rax)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xc880
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2813
movq -0x28(%rbp), %rdi
callq 0x10e0
movq -0x18(%rbp), %rdi
callq 0xf9c0
cmpl $0x0, %eax
jne 0x282d
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x18(%rbp), %rdi
callq 0xccf0
cmpl $0x1, %eax
jne 0x2847
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2849
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x27c6
movq -0x18(%rbp), %rdi
callq 0xce30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2877
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2879
cmpq $0x0, -0x28(%rbp)
je 0x2909
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xd080
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x28c4
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jl 0x28c2
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2904
movq -0x18(%rbp), %rdi
callq 0xcec0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x28e4
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x2902
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2909
jmp 0x2879
movq -0x18(%rbp), %rdi
callq 0xcec0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2929
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x292b
cmpq $0x0, -0x28(%rbp)
je 0x29bb
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xcf50
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2976
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jg 0x2974
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x29b6
movq -0x18(%rbp), %rdi
callq 0xce30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2996
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x29b4
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x29bb
jmp 0x292b
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
imull $0x5, -0x8(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2a32
movl $0x4, %edi
callq 0x10a0
movq %rax, -0x20(%rbp)
callq 0x10d0
cltd
idivl -0x8(%rbp)
movq -0x20(%rbp), %rax
movl %edx, (%rax)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xd1b0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2a0b
movq -0x28(%rbp), %rdi
callq 0x10e0
movq -0x18(%rbp), %rdi
callq 0xf9c0
cmpl $0x0, %eax
jne 0x2a25
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2a27
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x29c2
movq -0x18(%rbp), %rdi
callq 0xce30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2acf
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xd080
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2a8a
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jl 0x2a88
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2aca
movq -0x18(%rbp), %rdi
callq 0xcec0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2aaa
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x2ac8
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2acf
jmp 0x2a3f
movq -0x18(%rbp), %rdi
callq 0xcec0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2b62
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xcf50
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2b23
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jg 0x2b21
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2b5d
movq -0x18(%rbp), %rdi
callq 0xce30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2b40
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x2b5b
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
jmp 0x2b62
jmp 0x2adc
movq -0x18(%rbp), %rdi
movq 0x17453(%rip), %rsi     # 0x19fc0
callq 0xd550
movq -0x18(%rbp), %rdi
callq 0xf9c0
cmpl $0x0, %eax
jne 0x2b89
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x18(%rbp), %rdi
callq 0xccf0
cmpl $0x0, %eax
jne 0x2ba0
movl $0x1, -0x4(%rbp)
jmp 0x2bb0
movq -0x18(%rbp), %rdi
callq 0x10e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)