// File: /workspace/github_c_makefile_star2_O0/OhYee[P]computer_application_programming_experiment/hash_search/array_search/../../utils/blanced_binary_tree/tree_node.c
// Function: avl_tn_add
avl_tree_node *avl_tn_add(avl_tree_node *avl_tn, void *value, int size,
                          compare_function compare) {
    if (avl_tn == NULL) {
        return avl_tn_init(value, size);
    }
    int res = compare(avl_tn->value, value);
    if (res > 0) {
        avl_tn->left = avl_tn_add(avl_tn->left, value, size, compare);
        // avl_tn->left->parent = avl_tn;
    } else if (res < 0) {
        avl_tn->right = avl_tn_add(avl_tn->right, value, size, compare);
        // avl_tn->right->parent = avl_tn;
    } else {
        // same value do nothing
        return avl_tn;
    }

    int l = avl_tn->left ? avl_tn->left->deep : 0;
    int r = avl_tn->right ? avl_tn->right->deep : 0;
    if (abs(l - r) <= 1) {
        avl_tn->deep = (l > r ? l : r) + 1;
    } else {
        if (l - r > 1) {
            return avl_tn_right(avl_tn);
        } else {
            return avl_tn_left(avl_tn);
        }
    }

    return avl_tn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x2033
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x1ea0
movq %rax, -0x8(%rbp)
jmp 0x2164
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdi
movq -0x18(%rbp), %rsi
callq *%rax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x2072
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x2000
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x20ac
cmpl $0x0, -0x2c(%rbp)
jge 0x209d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x2000
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x20aa
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x2164
jmp 0x20ac
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x20c7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x20ce
xorl %eax, %eax
movl %eax, -0x38(%rbp)
jmp 0x20ce
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x20ef
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x18(%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0x20f6
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0x20f6
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x1, %eax
jg 0x2133
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x211e
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x2124
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0x215c
movl -0x30(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl $0x1, %eax
jle 0x214d
movq -0x10(%rbp), %rdi
callq 0x2170
movq %rax, -0x8(%rbp)
jmp 0x2164
movq -0x10(%rbp), %rdi
callq 0x21f0
movq %rax, -0x8(%rbp)
jmp 0x2164
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop