// File: /workspace/github_cpp_makefile_star2_O1/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), %r10
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r10, %r10
je 0x1829a
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq (%rdi), %rsi
movq 0x8(%rsi), %rcx
movq 0x48(%rdi), %rdx
movq 0x18(%rdx), %r8
movl 0x40(%rdi), %edx
movq (%r8), %r9
testb $-0x80, 0xd(%r9,%rdx,4)
jne 0x18128
movq %r10, %rdx
jmp 0x181fe
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl 0x8(%r10), %r11d
movl 0xc(%r10), %edx
movl (%rcx,%rdx,8), %edx
movl %edx, 0xc(%r10)
cmpq %r9, %r11
je 0x18148
leaq (%rcx,%r11,8), %r11
jmp 0x18154
movl 0x4(%r10), %r11d
shlq $0x2, %r11
addq 0x30(%rsi), %r11
movl %edx, (%r11)
movl 0xc(%r10), %r11d
cmpl $-0x1, %r11d
je 0x18198
movq 0x10(%r10), %rdx
testq %rdx, %rdx
je 0x18193
cmpl %r11d, 0xc(%rdx)
jae 0x18193
movq %rdx, 0x38(%rdi)
movq %rdx, %r14
movq %r14, %rbx
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x18189
cmpl %r11d, 0xc(%r14)
jb 0x18177
movq %r14, 0x10(%r10)
movq %r10, 0x10(%rbx)
jmp 0x181c3
movq %r10, %rdx
jmp 0x181c3
movl 0x8(%r10), %edx
cmpl $-0x1, %edx
je 0x181af
movq 0x60(%rsi), %r11
movl 0x4(%r10), %ebx
cmpl %edx, (%r11,%rbx,4)
jbe 0x181bb
movq 0x60(%rsi), %r11
movl 0x4(%r10), %ebx
movl %edx, (%r11,%rbx,4)
movq 0x10(%r10), %rdx
movq %rdx, 0x38(%rdi)
testq %rdx, %rdx
je 0x18296
movl 0x40(%rdi), %r11d
movl 0xc(%rdx), %r10d
movl 0x4(%rcx,%r10,8), %ebx
movl %ebx, 0x40(%rdi)
movq %rdx, %r10
cmpl %ebx, %r11d
je 0x1812e
movl 0x40(%rdi), %r10d
movq (%r8), %r11
testb $-0x80, 0xd(%r11,%r10,4)
movq %rdx, %r10
jne 0x1812e
movl (%rdx), %esi
movl %esi, 0x44(%rdi)
movl 0x40(%rdi), %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl 0xc(%rdx), %r10d
movl %r10d, 0x8(%rdx)
movl (%rcx,%r10,8), %r10d
movl %r10d, 0xc(%rdx)
movq 0x10(%rdx), %r11
cmpq %r9, %r10
je 0x18254
testq %r11, %r11
je 0x1825b
cmpl %r10d, 0xc(%r11)
ja 0x1828b
movq %r11, 0x38(%rdi)
movq %r11, %r14
movq %r14, %rbx
movq 0x10(%r14), %r14
testq %r14, %r14
je 0x1824a
cmpl %r10d, 0xc(%r14)
jb 0x18238
movq %r14, 0x10(%rdx)
movq %rdx, 0x10(%rbx)
jmp 0x18258
movq %r11, 0x38(%rdi)
movq %r11, %rdx
testq %rdx, %rdx
je 0x18286
movl 0xc(%rdx), %r10d
movl 0x4(%rcx,%r10,8), %r10d
movl %r10d, 0x40(%rdi)
cmpl %r10d, %r8d
jne 0x18279
orl (%rdx), %esi
movl %esi, 0x44(%rdi)
jmp 0x1827c
movl %r8d, %eax
cmpl %r10d, %r8d
movl %r10d, %r8d
je 0x1820d
jmp 0x18296
movl %r8d, %eax
jmp 0x18296
movl 0x40(%rdi), %eax
movl 0x4(%rcx,%r10,8), %ecx
movl %ecx, 0x40(%rdi)
popq %rbx
popq %r14
popq %rbp
retq
nop