// File: /workspace/github_cpp_makefile_star2_O2/vsklad[P]cgen/./bal/anf/anf.cpp
// Function: bal::Anf::append_equation_term(unsigned int const*, unsigned long)
void Anf::append_equation_term(const literalid_t* const symbols, const std::size_t symbols_size) {
        is_incomplete_last_equation_();
        const size_t equation_terms_size = terms_size_(equations_.size() - 1);
        
        // while 1, the term is valid even if becomes 1
        literalid_t constant = literal_t__constant(1);
        
        // validate the term itself
        // build sorted array of unique variable numbers
        // the rest is optimized out
        literalid_t validated_symbols[symbols_size];
        std::size_t validated_symbols_size = 0;
        std::size_t first_negation_index = symbols_size;
        
        for (auto i = 0; i < symbols_size && literal_t__is_constant_1(constant); i++) {
            if (literal_t__is_constant_0(symbols[i])) {
                constant = literal_t__constant(0);
                validated_symbols_size = 0;
                break;
            } else if (literal_t__is_constant_1(symbols[i])) {
                continue;
            } else {
                // adjust number of variables if necessary
                if (VariableGenerator::next() <= literal_t__variable_id(symbols[i])) {
                    VariableGenerator::reset(literal_t__variable_id(symbols[i]) + 1);
                };
                
                unsigned int j = 0;
                while (j < validated_symbols_size) {
                    if (literal_t__is_negation_of(symbols[i], validated_symbols[j])) {
                        // x & ~x == 0
                        constant = literal_t__constant(0);
                        validated_symbols_size = 0;
                        break;
                    } else if (symbols[i] == validated_symbols[j]) {
                        // x & x == x
                        break;
                    } else if (symbols[i] > validated_symbols[j]) {
                        // found the sorted insertion point
                        break;
                    };
                    j++;
                };
                if (j == validated_symbols_size || symbols[i] > validated_symbols[j]) {
                    if (j < validated_symbols_size) {
                        j++;
                        for (auto k = j; k < validated_symbols_size; k++) {
                            validated_symbols[k + 1] = validated_symbols[k];
                        };
                    };
                    validated_symbols[j] = symbols[i];
                    validated_symbols_size++;
                    
                    if (literal_t__is_negation(validated_symbols[j]) && first_negation_index > j) {
                        first_negation_index = j;
                    };
                };
            };
        };
        
        if (literal_t__is_constant_1(constant)) {
            if (validated_symbols_size > 0) {
                // handle negations
                // the first negation should be processed recursively replacing the negated variable with 1
                // then the second time unnegated
                if (first_negation_index < validated_symbols_size) {
                    literalid_t first_negated_literal = validated_symbols[first_negation_index];
                    validated_symbols[first_negation_index] = literal_t__constant(1);
                    append_equation_term(validated_symbols, validated_symbols_size); // recursive call
                    validated_symbols[first_negation_index] = literal_t__unnegated(first_negated_literal);
                    append_equation_term(validated_symbols, validated_symbols_size); // recursive call
                } else {
                    // now there is a sorted list of unique unnegated literals
                    // go through existing terms and check if there is a matching one
                    size_t term_index = terms_.size();
                    if (equation_terms_size > 1) {
                        const auto first_term_index = equations_[equations_.size() - 1] + 1; // skip the constant
                        for (auto i = first_term_index; i < first_term_index + equation_terms_size - 1; i++) {
                            const auto term_symbols_size = symbols_size_(i);
                            if (term_symbols_size == validated_symbols_size) {
                                term_index = i;
                                const auto first_symbol_index = terms_[i];
                                for (auto j = 0; j < validated_symbols_size; j++) {
                                    if (symbols_[first_symbol_index + j] != validated_symbols[j]) {
                                        term_index = terms_.size();
                                        break;
                                    };
                                };
                                if (term_index < terms_.size()) {
                                    break;
                                };
                            };
                        };
                    };
                    
                    if (term_index < terms_.size()) {
                        // term == terms_[term_index], i.e. <term> + <term>, remove the term_[term_index]
                        last_equation_remove_term_(term_index);
                    } else {
                        // append the new term
                        assert(symbols_.size() < UINT32_MAX);
                        terms_.push_back((uint32_t)symbols_.size());
                        for (auto i = 0; i < validated_symbols_size; i++) {
                            symbols_.push_back(validated_symbols[i]);
                        };
                    };
                };
            } else {
                // the term is the constant 1
                // find the first term of size 1 and attach to it
                auto term_index = equations_[equations_.size() - 1];
                const auto term_index_end = term_index + equation_terms_size;
                while (term_index < term_index_end && symbols_size_(term_index) > 1) {
                    term_index++;
                };
                _assert_level_1(term_index < term_index_end);
                literal_t__negate(symbols_[terms_[term_index]]);
            };
        };
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
callq 0xd8c4
movq 0xb0(%rbx), %rsi
subq 0xa8(%rbx), %rsi
sarq $0x2, %rsi
decq %rsi
movq %rbx, %rdi
callq 0xd994
movq %r14, %r10
movq %rbx, %r9
movq %rax, -0x38(%rbp)
movq %rsp, %r14
leaq 0xf(,%r10,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
pushq $0x1
popq %r11
xorl %ebx, %ebx
movq %r10, %r13
xorl %r15d, %r15d
movl %r11d, %esi
movq %r9, -0x30(%rbp)
cmpq %r10, %rbx
jae 0xcc80
cmpl $0x1, %esi
jne 0xcc80
movl (%r12,%rbx,4), %esi
cmpl $0x1, %esi
je 0xcc78
testl %esi, %esi
je 0xcd15
shrl %esi
leal -0x1(%rsi), %eax
cmpl %eax, 0x8(%r9)
ja 0xcbfc
movq %r9, %rdi
movq %r13, -0x40(%rbp)
movq %r10, %r13
callq 0xd9d6
pushq $0x1
popq %r11
movq %r13, %r10
movq -0x40(%rbp), %r13
movq -0x30(%rbp), %r9
pushq $0x2
popq %rax
movl %eax, %ecx
movl %r11d, %eax
leal -0x1(%rax), %edx
cmpq %rdx, %r15
jbe 0xcc2a
movl (%r12,%rbx,4), %esi
movl (%r14,%rdx,4), %edi
movl %edi, %r8d
xorl %esi, %r8d
cmpl $0x1, %r8d
je 0xcc2f
cmpl %edi, %esi
jae 0xcc2a
incl %eax
incl %ecx
jmp 0xcc04
movl %r11d, %esi
jmp 0xcc34
xorl %r15d, %r15d
xorl %esi, %esi
cmpq %rdx, %r15
je 0xcc43
movl (%r12,%rbx,4), %edi
cmpl (%r14,%rdx,4), %edi
jbe 0xcc78
cmpq %rdx, %r15
jbe 0xcc60
leal -0x1(%rcx), %edx
cmpq %rdx, %r15
jbe 0xcc5e
movl (%r14,%rdx,4), %edx
movl %ecx, %edi
movl %edx, (%r14,%rdi,4)
incl %ecx
jmp 0xcc48
movl %eax, %edx
movl (%r12,%rbx,4), %eax
movl %eax, (%r14,%rdx,4)
incq %r15
cmpq %rdx, %r13
cmovbq %r13, %rdx
testb $0x1, %al
cmoveq %rdx, %r13
incq %rbx
jmp 0xcbac
cmpl $0x1, %esi
jne 0xcd15
testq %r15, %r15
je 0xcccb
cmpq %r15, %r13
jae 0xcd24
movl (%r14,%r13,4), %ebx
movl $0x1, (%r14,%r13,4)
movq %r9, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r9, %r12
callq 0xcb3e
orl $0x1, %ebx
movl %ebx, (%r14,%r13,4)
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xcb3e
jmp 0xcd15
movq 0xb0(%r9), %rax
movl -0x4(%rax), %ecx
movq -0x38(%rbp), %rbx
addq %rcx, %rbx
movl %ecx, %r14d
cmpq %r14, %rbx
jbe 0xce52
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0xda06
leal 0x1(%r14), %ecx
cmpq $0x1, %rax
ja 0xccdc
movq -0x30(%rbp), %rcx
movq 0x78(%rcx), %rax
movq 0x90(%rcx), %rcx
movl (%rcx,%r14,4), %ecx
xorl $0x1, (%rax,%rcx,4)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rax
cmpq $0x2, %rax
jb 0xce00
movq %rax, %rcx
movq 0x98(%r9), %r13
movq 0xb0(%r9), %rax
subq 0x90(%r9), %r13
sarq $0x2, %r13
movl -0x4(%rax), %r12d
incl %r12d
leaq (%rcx,%r12), %rbx
decq %rbx
movl %r12d, %r12d
cmpq %r12, %rbx
jbe 0xcdd0
movq %r9, %rdi
movq %r12, %rsi
callq 0xda06
movq -0x30(%rbp), %r9
cmpq %r15, %rax
jne 0xcdcb
movq 0x78(%r9), %rcx
movq 0x90(%r9), %rax
movl (%rax,%r12,4), %edx
xorl %esi, %esi
cmpq %rsi, %r15
je 0xcdb1
leal (%rdx,%rsi), %edi
movl (%rcx,%rdi,4), %edi
leaq 0x1(%rsi), %r8
cmpl (%r14,%rsi,4), %edi
movq %r8, %rsi
je 0xcd89
movq 0x98(%r9), %r13
subq %rax, %r13
sarq $0x2, %r13
jmp 0xcdcb
movq 0x98(%r9), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movq %r12, %r13
cmpq %r12, %rcx
ja 0xce4d
incl %r12d
jmp 0xcd5c
movq 0x98(%r9), %rcx
subq 0x90(%r9), %rcx
sarq $0x2, %rcx
cmpq %rcx, %r13
jae 0xce00
movq %r9, %rdi
movq %r13, %rsi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xda44
movq 0x80(%r9), %rax
subq 0x78(%r9), %rax
sarq $0x2, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
jae 0xce71
leaq 0x90(%r9), %rdi
addq $0x78, %r9
movq %r9, %rbx
leaq -0x44(%rbp), %rsi
movl %eax, (%rsi)
callq 0xe0d2
subq $0x1, %r15
jb 0xcd15
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd89e
addq $0x4, %r14
jmp 0xce32
movq %r12, %r13
jmp 0xcde2
leaq 0x24267(%rip), %rdi     # 0x310c0
leaq 0x241bf(%rip), %rsi     # 0x3101f
leaq 0x24208(%rip), %rcx     # 0x3106f
movl $0xae, %edx
callq 0xc180
leaq 0x241da(%rip), %rdi     # 0x31052
leaq 0x241a0(%rip), %rsi     # 0x3101f
leaq 0x241e9(%rip), %rcx     # 0x3106f
movl $0x9f, %edx
callq 0xc180