// File: /workspace/github_c_makefile_star2_O2/CarlosLunaMota[P]BinaryTrees/BinaryTrees.c
// Function: is_rb_subtree
static int is_rb_subtree(const rb_tree *tree, const rb_node *node,
                         const void *min, const void *max) {

    int left_height  = 0;
    int right_height = 0;

    // Make sure that node is (strictly) between specified limits:
    if (min != NULL && (tree->comp)(min, node->data) >= 0) {
        fprintf(stderr, "ERROR: Symmetric order not satisfied in rb_tree\n");
        return -1;
    }
    if (max != NULL && (tree->comp)(node->data, max) >= 0) {
        fprintf(stderr, "ERROR: Symmetric order not satisfied in rb_tree\n");
        return -1;
    }

    // Check for RED violations:
    if (node->color == RED) {
        if (node->left  != NULL && node->left->color  == RED) {
            fprintf(stderr, "ERROR: Two RED nodes in a row in rb_tree\n");
            return -1;
        }
        if (node->right != NULL && node->right->color == RED) {
            fprintf(stderr, "ERROR: Two RED nodes in a row in rb_tree\n");
            return -1;
        }
    }

    // Check recursively the left subtree of node:
    if (node->left != NULL) {
        left_height = is_rb_subtree(tree, node->left, min, node->data);
        if (left_height == -1) { return -1; }
    }

    // Check recursively the right subtree of node:
    if (node->right != NULL) {
        right_height = is_rb_subtree(tree, node->right, node->data, max);
        if (right_height == -1) { return -1; }
    }

    // Check for BLACK violations:
    if (left_height != right_height) {
        fprintf(stderr, "ERROR: Different BLACK height in rb_tree\n");
        return -1;
    }
    
    // Return Black-Height of "node":
    if (node->color == RED){ return left_height; }
    return left_height+1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r15
testq %rdx, %rdx
je 0xae03
movq (%rbx), %rsi
movq %r12, %rdi
callq *0x8(%r15)
testl %eax, %eax
jns 0xae8d
testq %r14, %r14
je 0xae16
movq (%rbx), %rdi
movq %r14, %rsi
callq *0x8(%r15)
testl %eax, %eax
jns 0xae8d
cmpb $0x1, 0x18(%rbx)
movq 0x8(%rbx), %rsi
jne 0xae3a
testq %rsi, %rsi
je 0xae2b
cmpb $0x1, 0x18(%rsi)
je 0xaea2
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0xae3a
cmpb $0x1, 0x18(%rax)
je 0xaea2
xorl %r13d, %r13d
movl $0x0, %ebp
testq %rsi, %rsi
je 0xae5c
movq (%rbx), %rcx
movq %r15, %rdi
movq %r12, %rdx
callq 0xadd5
movl %eax, %ebp
cmpl $-0x1, %eax
je 0xaed1
movq 0x10(%rbx), %rsi
testq %rsi, %rsi
je 0xae7b
movq (%rbx), %rdx
movq %r15, %rdi
movq %r14, %rcx
callq 0xadd5
movl %eax, %r13d
cmpl $-0x1, %eax
je 0xaed1
cmpl %r13d, %ebp
jne 0xaeb5
xorl %eax, %eax
cmpb $0x1, 0x18(%rbx)
setne %al
addl %eax, %ebp
jmp 0xaed4
movq 0x6164(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x30d8(%rip), %rdi      # 0xdf76
pushq $0x30
jmp 0xaec8
movq 0x614f(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x30f4(%rip), %rdi      # 0xdfa7
jmp 0xaec6
movq 0x613c(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x310b(%rip), %rdi      # 0xdfd1
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x1100
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq