// File: vsklad[P]cgen/./bal/bal/binarytreeindex.hpp
// Function: void bal::AvlTreesIndex<unsigned int, true, &int bal::compare_clauses<false>(unsigned int const*, unsigned int const*), &unsigned int bal::clause_index_variable_id<false>(unsigned int const*)>::_merge_or_swap_child<true, true, false>(unsigned int)
inline void _merge_or_swap_child(const container_offset_t offset) {
            container_offset_t* const p_item = _bti_item(this->data_, offset);
            container_offset_t child_offset = b_with_left ? _bti_item_left_offset(p_item) : _bti_item_right_offset(p_item);
            _assert_level_1(child_offset != CONTAINER_END);
            container_offset_t* p_child = _bti_item(this->data_, child_offset);
            const container_offset_t other_child_offset = (b_with_left ? _bti_item_right_offset(p_item) : _bti_item_left_offset(p_item));
            
            if (b_merge) {
                _bti_item_left_offset(p_item) = _bti_item_left_offset(p_child);
                if (_bti_item_left_offset(p_item) != CONTAINER_END) {
                    _assert_level_2(_bti_parent_offset(this->data_, _bti_item_left_offset(p_item)) == child_offset);
                    _bti_parent_offset(this->data_, _bti_item_left_offset(p_item)) = offset;
                };
                _bti_item_right_offset(p_item) = _bti_item_right_offset(p_child);
                if (_bti_item_right_offset(p_item) != CONTAINER_END) {
                    _assert_level_2(_bti_parent_offset(this->data_, _bti_item_right_offset(p_item)) == child_offset);
                    _bti_parent_offset(this->data_, _bti_item_right_offset(p_item)) = offset;
                };
                p_child = p_item;
                child_offset = offset;
            } else { // swap
                _assert_level_1((b_become_left || _bti_item_right_offset(p_child) == CONTAINER_END) &&
                                (!b_become_left || _bti_item_left_offset(p_child) == CONTAINER_END));
                (b_become_left ? _bti_item_left_offset(p_child) : _bti_item_right_offset(p_child)) = _bti_item_parent_offset(p_child);
                _update_parent(offset, child_offset);
                _bti_item_parent_offset(p_item) = child_offset;
                _bti_item_left_offset(p_item) = CONTAINER_END;
                _bti_item_right_offset(p_item) = CONTAINER_END;
            };
            
            if (other_child_offset != CONTAINER_END) {
                // the other child becomes the rightmost or leftmost furtherst leaf respectively
                while ((b_with_left ? _bti_item_right_offset(p_child) : _bti_item_left_offset(p_child)) != CONTAINER_END) {
                    child_offset = (b_with_left ? _bti_item_right_offset(p_child) : _bti_item_left_offset(p_child));
                    p_child = this->data_ + child_offset;
                };
                
                (b_with_left ? _bti_item_right_offset(p_child) : _bti_item_left_offset(p_child)) = other_child_offset;
                _bti_parent_offset(this->data_, other_child_offset) = child_offset;
            };
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x8(%rax), %rax
movl -0xc(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
je 0x1e8ab
jmp 0x1e8ca
leaq 0x412aa(%rip), %rdi     # 0x5fb5c
leaq 0x3ee95(%rip), %rsi     # 0x5d74e
movl $0xd2, %edx
leaq 0x412b5(%rip), %rcx     # 0x5fb7a
callq 0xd1c0
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
je 0x1e94f
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
jne 0x1e91b
jmp 0x1e93a
leaq 0x413bf(%rip), %rdi     # 0x5fce1
leaq 0x3ee25(%rip), %rsi     # 0x5d74e
movl $0xd9, %edx
leaq 0x41245(%rip), %rcx     # 0x5fb7a
callq 0xd1c0
movq -0x38(%rbp), %rax
movl -0xc(%rbp), %edx
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
je 0x1e9b4
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x1c(%rbp), %eax
jne 0x1e980
jmp 0x1e99f
leaq 0x41395(%rip), %rdi     # 0x5fd1c
leaq 0x3edc0(%rip), %rsi     # 0x5d74e
movl $0xde, %edx
leaq 0x411e0(%rip), %rcx     # 0x5fb7a
callq 0xd1c0
movq -0x38(%rbp), %rax
movl -0xc(%rbp), %edx
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
je 0x1ea11
jmp 0x1e9ca
movq -0x28(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
je 0x1e9f6
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x4(%rcx), %ecx
movl %ecx, -0x1c(%rbp)
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x1e9ca
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %edx
movq -0x28(%rbp), %rcx
movl %edx, 0x4(%rcx)
movl -0x1c(%rbp), %edx
movq 0x8(%rax), %rax
movl -0x2c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)