// File: /workspace/github_cpp_makefile_star2_O3/vsklad[P]cgen/./bal/bal/linkedlistindex.hpp
// Function: bal::SimpleLinkedListsIndexMergedFilteredOptimizingInstanceOffsetIterator<unsigned int, 2u, bal::CnfProcessor, &bal::CnfProcessor::is_clause_included(unsigned int) const>::next()
inline container_offset_t next() {
            list_index_item_t* const index_data = index_.data_;
            state_t* p_state = p_current_state_;
            
            // if data_offset_ is included, iterate and return
            // otherwise, exclude it and repeat
            while (p_state != nullptr) {
                _assert_level_4(data_offset_ != CONTAINER_END);
                if ((filter_.*IS_INCLUDED)(data_offset_)) {
                    instance_bits_ = p_state->instance_bit;
                    while (true) {
                        // 1. move p_current_state_ index instance to the next item;
                        //    p_current_state_ corresponds to the cached data_offset_
                        // 2. choose new minimal p_current_state_ instance
                        p_state->index_offset_prev = p_state->index_offset;
                        p_state->index_offset = index_data[p_state->index_offset].next_offset;
                        if (p_state->index_offset != CONTAINER_END) {
                            if (p_state->p_next != nullptr) {
                                if (p_state->p_next->index_offset > p_state->index_offset) {
                                    // the index item of the next instance is higher than
                                    // the next item of the p_state instance
                                    // data offset must be different as well respectively
                                    // terminate and return data_offset_
                                    const container_offset_t data_offset = data_offset_;
                                    data_offset_ = index_data[p_state->index_offset].container_offset;
                                    _assert_level_4(data_offset != data_offset_);
                                    return data_offset;
                                } else {
                                    // the index item of the next instance is lower than
                                    // the next item of the p_state instance (equal not possible)
                                    // update the p_state list and repeat for the new p_current_state_
                                    // if the data offset is the same; otherwise break
                                    _assert_level_4(p_state->p_next->index_offset != p_state->index_offset);
                                    state_t* p_sorted = p_current_state_ = p_state->p_next;
                                    while (p_sorted->p_next != nullptr && p_sorted->p_next->index_offset < p_state->index_offset) {
                                        p_sorted = p_sorted->p_next;
                                    };
                                    p_state->p_next = p_sorted->p_next;
                                    p_sorted->p_next = p_state;
                                    p_state = p_current_state_;
                                }
                            }
                        } else {
                            p_current_state_ = p_state = p_state->p_next;
                        };
                        if (p_state != nullptr) {
                            // next instance; if data offset is different, terminate
                            const container_offset_t data_offset = data_offset_;
                            data_offset_ = index_.data_[p_state->index_offset].container_offset;
                            if (data_offset != data_offset_) {
                                return data_offset;
                            } else {
                                instance_bits_ |= p_state->instance_bit;
                            };
                        } else {
                            return data_offset_; // iterator's end
                        };
                    }
                } else {
                    // exclude (possibly several) index-offset(s)
                    // which have the same excluded data_offset
                    // start with p_state
                    // then repeat with new data_offset_ if available
                    // can break but cannot return within the cycle
                    while (true) {
                        // 1. exclude p_state->index_offset; index can only grow
                        // 2. update the sorted state list if necessary
                        p_state->index_offset = index_data[p_state->index_offset].next_offset;
                        if (p_state->index_offset_prev == CONTAINER_END) {
                            index_.instances_.data_[p_state->instance_offset] = p_state->index_offset;
                        } else {
                            index_data[p_state->index_offset_prev].next_offset = p_state->index_offset;
                        };
                        // if CONTAINER_END, exclude p_state and update instances_last_
                        // otherwise, reposition p_state within the sorted list
                        // break if the new data_offset is different
                        if (p_state->index_offset != CONTAINER_END) {
                            // last index element is the same or greater than the first one
                            _assert_level_4(index_.instances_.data_[p_state->instance_offset] <= index_.instances_last_.data_[p_state->instance_offset]);
                            if (p_state->p_next != nullptr) {
                                if (p_state->p_next->index_offset < p_state->index_offset) {
                                    state_t* p_sorted = p_current_state_ = p_state->p_next;
                                    while (p_sorted->p_next != nullptr && p_sorted->p_next->index_offset < p_state->index_offset) {
                                        p_sorted = p_sorted->p_next;
                                    };
                                    p_state->p_next = p_sorted->p_next;
                                    p_sorted->p_next = p_state;
                                    p_state = p_current_state_;
                                }
                            }
                        } else {
                            // if the last element becomes lower than p_state->index_offset_prev
                            // this means the lst element has been updated concurrently
                            // keep the lower value; normally, the last element can only grow
                            if (p_state->index_offset_prev == CONTAINER_END ||
                                index_.instances_last_.data_[p_state->instance_offset] > p_state->index_offset_prev) {
                                index_.instances_last_.data_[p_state->instance_offset] = p_state->index_offset_prev;
                            };
                            // last index element is the same or greater than the first one
                            _assert_level_4(index_.instances_.data_[p_state->instance_offset] <= index_.instances_last_.data_[p_state->instance_offset]);
                            p_current_state_ = p_state = p_state->p_next;
                        };
                        
                        if (p_state != nullptr) {
                            // next instance; if data offset is different, break
                            // otherwise continue excluding
                            const container_offset_t data_offset = data_offset_;
                            data_offset_ = index_.data_[p_state->index_offset].container_offset;
                            if (data_offset != data_offset_) {
                                break;
                            };
                        } else {
                            break; // iterator's end
                        };
                    };
                };
            };
            return CONTAINER_END;
        }

// Assembly:
movq 0x38(%rdi), %rdx
testq %rdx, %rdx
je 0x16c4f
pushq %rbp
movq %rsp, %rbp
pushq %rbx
movq (%rdi), %rsi
movq 0x8(%rsi), %rcx
movq 0x48(%rdi), %rax
movq 0x18(%rax), %r8
movl 0x40(%rdi), %eax
movq (%r8), %r9
testb $-0x80, 0xd(%r9,%rax,4)
jne 0x16c55
movl (%rdx), %esi
movl 0xc(%rdx), %r9d
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %r9d, 0x8(%rdx)
movl %r9d, %r9d
movl (%rcx,%r9,8), %r9d
movl %r9d, 0xc(%rdx)
movq 0x10(%rdx), %r10
cmpq %r8, %r9
je 0x16c1f
testq %r10, %r10
je 0x16c32
cmpl %r9d, 0xc(%r10)
ja 0x16d26
movq %r10, 0x38(%rdi)
movq %r10, %rbx
movq %rbx, %r11
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
je 0x16c15
cmpl %r9d, 0xc(%rbx)
jb 0x16c03
movq %rbx, 0x10(%rdx)
movq %rdx, 0x10(%r11)
jmp 0x16c23
movq %r10, 0x38(%rdi)
testq %r10, %r10
je 0x16d20
movl 0xc(%r10), %r9d
jmp 0x16c35
movq %rdx, %r10
movl %r9d, %edx
movl 0x4(%rcx,%rdx,8), %edx
movl %edx, 0x40(%rdi)
cmpl %edx, %eax
jne 0x16d20
orl (%r10), %esi
movq %r10, %rdx
jmp 0x16bd5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
retq
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl 0xc(%rdx), %eax
movl %eax, %eax
movl (%rcx,%rax,8), %eax
movl %eax, 0xc(%rdx)
movl 0x8(%rdx), %r10d
cmpq %r9, %r10
je 0x16c75
movl %eax, (%rcx,%r10,8)
jmp 0x16c84
movq 0x30(%rsi), %r10
movl 0x4(%rdx), %r11d
movl %eax, (%r10,%r11,4)
movl 0xc(%rdx), %eax
cmpl $-0x1, %eax
je 0x16cba
movq 0x10(%rdx), %r10
testq %r10, %r10
je 0x16ce9
cmpl %eax, 0xc(%r10)
jae 0x16ce9
movq %r10, 0x38(%rdi)
movq %r10, %rbx
movq %rbx, %r11
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
je 0x16cb0
cmpl %eax, 0xc(%rbx)
jb 0x16c9f
movq %rbx, 0x10(%rdx)
movq %rdx, 0x10(%r11)
jmp 0x16cdd
movl 0x4(%rdx), %eax
movl 0x8(%rdx), %r10d
movq 0x60(%rsi), %r11
cmpl $-0x1, %r10d
je 0x16cd1
cmpl %r10d, (%r11,%rax,4)
jbe 0x16cd5
movl %r10d, (%r11,%rax,4)
movq 0x10(%rdx), %r10
movq %r10, 0x38(%rdi)
testq %r10, %r10
je 0x16d19
movl 0xc(%r10), %eax
movq %r10, %rdx
movl 0x40(%rdi), %r10d
movl %eax, %r11d
movl 0x4(%rcx,%r11,8), %r11d
movl %r11d, 0x40(%rdi)
cmpl %r11d, %r10d
je 0x16c5e
movl 0x40(%rdi), %eax
movq (%r8), %r10
testb $-0x80, 0xd(%r10,%rax,4)
jne 0x16c5b
jmp 0x16bc9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x16d23
movl %esi, 0x44(%rdi)
popq %rbx
popq %rbp
retq
movl %esi, 0x44(%rdi)
movl 0x4(%rcx,%r9,8), %ecx
movl %ecx, 0x40(%rdi)
jmp 0x16d23
nop