// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rsi, %r13
movq %rdi, %r14
callq 0xf4fc
movq 0xa8(%r14), %rdx
movq 0xb0(%r14), %rsi
subq %rdx, %rsi
sarq $0x2, %rsi
xorl %eax, %eax
testb %al, %al
movq %r14, -0x30(%rbp)
je 0xe3ff
movl (%rdx,%rsi,4), %ecx
jmp 0xe411
movq 0x98(%r14), %rcx
subq 0x90(%r14), %rcx
sarq $0x2, %rcx
movq %rdx, -0x50(%rbp)
movq %rsi, -0x48(%rbp)
movl -0x4(%rdx,%rsi,4), %eax
movq %rax, -0x38(%rbp)
movq %rsp, %r14
leaq 0xf(,%rbx,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
testq %rbx, %rbx
je 0xe540
movq -0x30(%rbp), %rax
movl 0x8(%rax), %r8d
xorl %esi, %esi
xorl %r15d, %r15d
movq %rbx, %r12
movl (%r13,%rsi,4), %r9d
cmpq $0x1, %r9
je 0xe524
testl %r9d, %r9d
je 0xe54b
movl %r9d, %eax
shrl %eax
leal -0x1(%rax), %edx
cmpl %edx, %r8d
ja 0xe488
cmpl $-0x4, %r9d
jae 0xe7b1
movq -0x30(%rbp), %rdx
movl %eax, 0x8(%rdx)
movl %eax, %r8d
movl $0x1, %r9d
testq %r15, %r15
je 0xe4bf
movl (%r13,%rsi,4), %eax
xorl %r11d, %r11d
xorl %r10d, %r10d
movl (%r14,%r11,4), %edi
movl %edi, %edx
xorl %eax, %edx
cmpl $0x1, %edx
je 0xe4c7
cmpl %edi, %eax
jae 0xe4cd
incl %r10d
movq %r10, %r11
cmpq %r10, %r15
ja 0xe49e
movq %r10, %r11
jmp 0xe4cd
xorl %r10d, %r10d
xorl %r11d, %r11d
jmp 0xe4cd
xorl %r15d, %r15d
xorl %r9d, %r9d
cmpq %r11, %r15
je 0xe4dd
movl (%r13,%rsi,4), %eax
cmpl (%r14,%r11,4), %eax
jbe 0xe524
cmpq %r11, %r15
jbe 0xe508
leal 0x1(%r10), %eax
cmpq %rax, %r15
jbe 0xe505
addl $0x2, %r10d
movq %rax, %r11
movl (%r14,%r11,4), %edx
movl %r10d, %r11d
movl %edx, (%r14,%r11,4)
incl %r10d
cmpq %r11, %r15
ja 0xe4f2
movl %eax, %r10d
movl (%r13,%rsi,4), %eax
movl %r10d, %edx
movl %eax, (%r14,%rdx,4)
incq %r15
cmpq %rdx, %r12
cmovbq %r12, %rdx
testb $0x1, %al
cmoveq %rdx, %r12
incq %rsi
cmpl $0x1, %r9d
sete %r10b
cmpq %rbx, %rsi
jae 0xe551
cmpl $0x1, %r9d
je 0xe44f
jmp 0xe551
movb $0x1, %r10b
xorl %r15d, %r15d
movq %rbx, %r12
jmp 0xe551
xorl %r10d, %r10d
movq %r9, %r15
testb %r10b, %r10b
movq -0x30(%rbp), %r13
je 0xe7a2
subq -0x38(%rbp), %rcx
testq %r15, %r15
je 0xe5a4
cmpq %r15, %r12
jae 0xe633
movl (%r14,%r12,4), %ebx
movl $0x1, (%r14,%r12,4)
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xe3bc
orl $0x1, %ebx
movl %ebx, (%r14,%r12,4)
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xe3bc
jmp 0xe7a2
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movl -0x4(%rax,%rdx,4), %eax
addq %rax, %rcx
cmpq %rax, %rcx
jbe 0xe607
movq 0x98(%r13), %rdx
movq 0x80(%r13), %rsi
movq 0x90(%r13), %rdi
subq %rdi, %rdx
sarq $0x2, %rdx
decq %rdx
subq 0x78(%r13), %rsi
sarq $0x2, %rsi
leal 0x1(%rax), %r8d
movq %rsi, %r9
cmpq %rax, %rdx
je 0xe5f0
movl 0x4(%rdi,%rax,4), %r9d
movl (%rdi,%rax,4), %eax
subq %rax, %r9
cmpq $0x1, %r9
jbe 0xe626
movl %r8d, %eax
incl %r8d
cmpq %rax, %rcx
ja 0xe5e3
leaq 0x32ab2(%rip), %rdi     # 0x410c0
leaq 0x32a0a(%rip), %rsi     # 0x4101f
leaq 0x32a53(%rip), %rcx     # 0x4106f
movl $0xae, %edx
callq 0xc180
movq 0x78(%r13), %rcx
xorl $0x1, (%rcx,%rax,4)
jmp 0xe7a2
movq 0x90(%r13), %r9
movq 0x98(%r13), %r8
movq %r8, -0x38(%rbp)
subq %r9, %r8
sarq $0x2, %r8
movq %r8, %rax
cmpq $0x2, %rcx
jb 0xe6f1
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rdx
movl -0x4(%rax,%rdx,4), %edi
incl %edi
leaq (%rcx,%rdi), %rsi
decq %rsi
movq %r8, %rax
cmpq %rdi, %rsi
jbe 0xe6f1
movq -0x30(%rbp), %rax
movq 0x98(%rax), %rdx
subq %r9, %rdx
sarq $0x2, %rdx
decq %rdx
movq 0x78(%rax), %r10
movq 0x80(%rax), %r11
subq %r10, %r11
sarq $0x2, %r11
movl %edi, %ebx
movq %r8, %rax
movq %r11, %r13
cmpq %rdi, %rdx
je 0xe6af
movl 0x4(%r9,%rdi,4), %r13d
movl (%r9,%rdi,4), %r12d
subq %r12, %r13
movb $0x1, %cl
cmpq %r15, %r13
jne 0xe6e3
xorl %eax, %eax
leal (%r12,%rax), %ecx
movl (%r10,%rcx,4), %ecx
cmpl (%r14,%rax,4), %ecx
jne 0xe6d7
incq %rax
cmpq %rax, %r15
jne 0xe6bf
jmp 0xe6da
movq %r8, %rdi
cmpq %r8, %rdi
setae %cl
movq %rdi, %rax
testb %cl, %cl
je 0xe6f1
incl %ebx
movq %rbx, %rdi
cmpq %rbx, %rsi
ja 0xe6a2
cmpq %r8, %rax
jae 0xe710
movq -0x30(%rbp), %rdi
movq %rax, %rsi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf60a
movq -0x30(%rbp), %rbx
movq 0x80(%rbx), %rax
subq 0x78(%rbx), %rax
sarq $0x2, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
jae 0xe7d0
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rsi
cmpq 0xa0(%rbx), %rsi
je 0xe750
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x98(%rbx)
jmp 0xe760
leaq 0x90(%rbx), %rdi
leaq -0x3c(%rbp), %rdx
callq 0xfb44
leaq 0x78(%rbx), %r12
cmpq $0x1, %r15
adcq $0x0, %r15
movq 0x80(%rbx), %rsi
cmpq 0x88(%rbx), %rsi
je 0xe78e
movl (%r14), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x80(%rbx)
jmp 0xe799
movq %r12, %rdi
movq %r14, %rdx
callq 0xfc7c
addq $0x4, %r14
decq %r15
jne 0xe76c
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x32e53(%rip), %rdi     # 0x4160b
leaq 0x32e69(%rip), %rsi     # 0x41628
leaq 0x32e7a(%rip), %rcx     # 0x41640
movl $0x9b, %edx
callq 0xc180
leaq 0x3287b(%rip), %rdi     # 0x41052
leaq 0x32841(%rip), %rsi     # 0x4101f
leaq 0x3288a(%rip), %rcx     # 0x4106f
movl $0x9f, %edx
callq 0xc180
nop