// File: /workspace/github_c_makefile_star2_O0/CarlosLunaMota[P]BinaryTrees/main.c
// Function: rb_tree_random_test
int rb_tree_random_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 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 = rb_tree_insert(tree, data);

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

        // 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 everything is correctly sorted forward...
    found = rb_tree_min(tree);
    if (found == NULL) { 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; }
    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; 
        }
    }

    // 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 = rb_tree_remove(tree, data);

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

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

    // Check if everything is correctly sorted forward...
    found = rb_tree_min(tree);
    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);
    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!
    rb_tree_remove_all(tree, free);

    // 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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
leaq -0x5092(%rip), %rdi     # 0x11e0
callq 0xfe40
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x13b90
cmpl $0x0, %eax
jne 0x62a5
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x18(%rbp), %rdi
callq 0x10ae0
cmpl $0x0, %eax
jne 0x62bf
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
imull $0xa, -0x8(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6357
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 0x10330
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6313
movq -0x28(%rbp), %rdi
callq 0x10e0
movq -0x18(%rbp), %rdi
callq 0x13b90
cmpl $0x0, %eax
jne 0x632d
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x18(%rbp), %rdi
callq 0x10ae0
cmpl $0x1, %eax
jne 0x6347
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x6349
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x62c6
movq -0x18(%rbp), %rdi
callq 0x10c20
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6377
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x6379
cmpq $0x0, -0x28(%rbp)
je 0x6409
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10e70
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x63c4
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jl 0x63c2
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x6404
movq -0x18(%rbp), %rdi
callq 0x10cb0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x63e4
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x6402
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x6409
jmp 0x6379
movq -0x18(%rbp), %rdi
callq 0x10cb0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6429
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x642b
cmpq $0x0, -0x28(%rbp)
je 0x64bb
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10d40
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6476
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jg 0x6474
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x64b6
movq -0x18(%rbp), %rdi
callq 0x10c20
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6496
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x64b4
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x64bb
jmp 0x642b
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
imull $0x5, -0x8(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6532
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 0x10fa0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x650b
movq -0x28(%rbp), %rdi
callq 0x10e0
movq -0x18(%rbp), %rdi
callq 0x13b90
cmpl $0x0, %eax
jne 0x6525
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x6527
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x64c2
movq -0x18(%rbp), %rdi
callq 0x10c20
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x65cf
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10e70
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x658a
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jl 0x6588
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x65ca
movq -0x18(%rbp), %rdi
callq 0x10cb0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x65aa
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x65c8
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x65cf
jmp 0x653f
movq -0x18(%rbp), %rdi
callq 0x10cb0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6662
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10d40
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6623
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
jg 0x6621
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x665d
movq -0x18(%rbp), %rdi
callq 0x10c20
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6640
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x11e0
cmpl $0x0, %eax
je 0x665b
movl $0x1, -0x4(%rbp)
jmp 0x66b0
jmp 0x6662
jmp 0x65dc
movq -0x18(%rbp), %rdi
movq 0x13953(%rip), %rsi     # 0x19fc0
callq 0x11fb0
movq -0x18(%rbp), %rdi
callq 0x13b90
cmpl $0x0, %eax
jne 0x6689
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x18(%rbp), %rdi
callq 0x10ae0
cmpl $0x0, %eax
jne 0x66a0
movl $0x1, -0x4(%rbp)
jmp 0x66b0
movq -0x18(%rbp), %rdi
callq 0x10e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)