// File: /workspace/github_cpp_makefile_star2_O1/vsklad[P]cgen/./bal/anf/anf.cpp
// Function: bal::Anf::complete_equation(unsigned int, bool)
literalid_t Anf::complete_equation(const literalid_t r, const bool optimize_negation) {
        is_incomplete_last_equation_();
        
        const size_t equation_terms_size = terms_size_(equations_.size() - 1);
        const size_t const_term_index = equations_[equations_.size() - 1];
        
        literalid_t result = symbols_[terms_[const_term_index]];
        _assert_level_1(literal_t__is_constant(result));
        
        if (equation_terms_size == 1) {
            _assert_level_1(literal_t__is_unassigned(r));
            remove_last_equation_();
        } else if (optimize_negation && equation_terms_size == 2 && symbols_size_(const_term_index + 1) == 1) {
            // one term one one variable
            // negated because 1 means + 1 which means "1 negated"
            _assert_level_1(literal_t__is_unassigned(r));
            result = literal_t__substitute_literal(literal_t__negated(result), symbols_[terms_[const_term_index + 1]]);
            remove_last_equation_();
        } else if (literal_t__is_constant(r) && equation_terms_size == 2 && symbols_size_(const_term_index + 1) == 1) {
            // one term one one variable
            // unit clause
            _assert_level_1(!optimize_negation);
            _assert_level_1(literal_t__is_variable(symbols_[terms_[const_term_index + 1]]));
            result = symbols_[terms_[const_term_index + 1]];
            result = literal_t__substitute_literal(literal_t__negated(r), result);
            result = literal_t__substitute_literal(literal_t__negated(symbols_[terms_[const_term_index]]), result);
            last_equation_remove_term_(const_term_index + 1);
            symbols_[terms_[const_term_index]] = result;
            // variable value, negation because the equation (result == 0)
            result = literal_t__is_negation(result) ? 0b1 : 0b0;
        } else {
            // multiple terms
            literalid_t last_literal;
            if (literal_t__is_variable(r) || literal_t__is_constant(r)) {
                _assert_level_1(!optimize_negation);
                last_literal = r;
                if (literal_t__is_constant(last_literal)) {
                    // try to find a single variable term and merge with it
                    for (auto i = const_term_index + 1; i < const_term_index + equation_terms_size - 1; i++) {
                        if (symbols_size_(i) == 1) {
                            _assert_level_1(literal_t__is_variable(symbols_[terms_[i]]));
                            last_literal = literal_t__substitute_literal(literal_t__negated(r), symbols_[terms_[i]]);
                            last_equation_remove_term_(i);
                            break;
                        };
                    };
                };
            } else {
                _assert_level_1(literal_t__is_unassigned(r));
                last_literal = VariableGenerator::new_variable_literal();
            };
            
            // 1 + x = ~x, therefore apply negated sign to the last_literal
            result = literal_t__substitute_literal(literal_t__negated(result), last_literal);
            
            if (optimize_negation) {
                // negation is within the result, the equation should include the same unnegated
                symbols_[terms_[const_term_index]] = last_literal;
            } else {
                symbols_[terms_[const_term_index]] = result;
                result = last_literal;
            };
        };
        
        return result;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %rbx
callq 0xf4fc
movq 0xa8(%rbx), %rcx
movq 0xb0(%rbx), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
xorl %eax, %eax
testb %al, %al
je 0xe872
movl (%rcx,%rdx,4), %eax
jmp 0xe884
movq 0x98(%rbx), %rax
subq 0x90(%rbx), %rax
sarq $0x2, %rax
movl -0x4(%rcx,%rdx,4), %r13d
movq 0x78(%rbx), %rcx
movq 0x90(%rbx), %rdx
movl (%rdx,%r13,4), %esi
movl (%rcx,%rsi,4), %r14d
cmpl $0x2, %r14d
jae 0xeae8
movq %rax, %rsi
subq %r13, %rsi
cmpq $0x1, %rsi
jne 0xe925
cmpl $-0x1, %r15d
jne 0xeb07
movq %rbx, %rdi
callq 0xf4fc
movq 0xb0(%rbx), %rsi
movq 0x90(%rbx), %rax
movl -0x4(%rsi), %ecx
leaq (%rax,%rcx,4), %rax
movl (%rax), %ecx
shlq $0x2, %rcx
addq 0x78(%rbx), %rcx
cmpq 0x80(%rbx), %rcx
je 0xe8f3
movq %rcx, 0x80(%rbx)
cmpq 0x98(%rbx), %rax
je 0xe903
movq %rax, 0x98(%rbx)
movb $0x1, %al
testb %al, %al
jne 0xe918
leaq -0x4(%rsi), %rdi
movq %rsi, %rdx
subq %rsi, %rdx
callq 0xc450
addq $-0x4, 0xb0(%rbx)
jmp 0xead6
cmpq $0x2, %rsi
setne %dil
movl %r12d, %r8d
xorb $0x1, %r8b
orb %dil, %r8b
jne 0xe986
movq 0x98(%rbx), %rdi
subq %rdx, %rdi
sarq $0x2, %rdi
leaq 0x2(%r13), %r8
cmpq %r8, %rdi
jne 0xe960
movq 0x80(%rbx), %rdi
subq %rcx, %rdi
sarq $0x2, %rdi
jmp 0xe965
movl 0x8(%rdx,%r13,4), %edi
movl 0x4(%rdx,%r13,4), %r8d
subq %r8, %rdi
cmpq $0x1, %rdi
jne 0xe986
cmpl $-0x1, %r15d
jne 0xeb83
xorl (%rcx,%r8,4), %r14d
jmp 0xe8bc
cmpl $0x1, %r15d
ja 0xea20
cmpq $0x2, %rsi
jne 0xea20
movq 0x98(%rbx), %rsi
subq %rdx, %rsi
sarq $0x2, %rsi
leaq 0x2(%r13), %rdi
cmpq %rdi, %rsi
jne 0xe9c1
movq 0x80(%rbx), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
jmp 0xe9c6
movl 0x8(%rdx,%r13,4), %esi
movl 0x4(%rdx,%r13,4), %edi
subq %rdi, %rsi
cmpq $0x1, %rsi
jne 0xea20
testb %r12b, %r12b
jne 0xeba2
movl (%rcx,%rdi,4), %eax
leal 0x1(%rax), %ecx
cmpl $0x2, %ecx
jbe 0xeb26
leaq 0x1(%r13), %rsi
xorl %r15d, %r14d
xorl %eax, %r14d
movl %r14d, %r15d
notl %r15d
movq %rbx, %rdi
callq 0xf60a
movq 0x78(%rbx), %rax
movq 0x90(%rbx), %rcx
movl (%rcx,%r13,4), %ecx
movl %r14d, (%rax,%rcx,4)
andl $0x1, %r15d
jmp 0xead3
cmpl $-0x1, %r15d
je 0xeaa2
testb %r12b, %r12b
jne 0xeb45
cmpl $0x1, %r15d
ja 0xeab2
decq %rax
movq 0x80(%rbx), %rdi
movq 0x98(%rbx), %r8
subq %rdx, %r8
sarq $0x2, %r8
subq %rcx, %rdi
sarq $0x2, %rdi
addq $-0x2, %r8
movq %r13, %r9
leaq 0x1(%r9), %rsi
cmpq %rax, %rsi
jae 0xeab2
movq %rdi, %r10
cmpq %r9, %r8
je 0xea71
movl 0x8(%rdx,%r9,4), %r10d
movl 0x4(%rdx,%r9,4), %r11d
subq %r11, %r10
movq %rsi, %r9
cmpq $0x1, %r10
jne 0xea5b
movl (%rcx,%r11,4), %ecx
leal 0x1(%rcx), %eax
cmpl $0x2, %eax
jbe 0xeb64
xorl %r15d, %ecx
movq %rbx, %rdi
movq %rcx, %r15
callq 0xf60a
jmp 0xeab2
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
leal 0x3(,%rax,2), %r15d
xorl %r15d, %r14d
movq 0x78(%rbx), %rax
movq 0x90(%rbx), %rcx
movl (%rcx,%r13,4), %ecx
testb %r12b, %r12b
je 0xeacf
movl %r15d, (%rax,%rcx,4)
jmp 0xead6
movl %r14d, (%rax,%rcx,4)
movl %r15d, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x325ed(%rip), %rdi     # 0x410dc
leaq 0x32529(%rip), %rsi     # 0x4101f
leaq 0x32608(%rip), %rcx     # 0x41105
movl $0xc5, %edx
callq 0xc180
leaq 0x32f27(%rip), %rdi     # 0x41a35
leaq 0x3250a(%rip), %rsi     # 0x4101f
leaq 0x325e9(%rip), %rcx     # 0x41105
movl $0xc8, %edx
callq 0xc180
leaq 0x32632(%rip), %rdi     # 0x4115f
leaq 0x324eb(%rip), %rsi     # 0x4101f
leaq 0x325ca(%rip), %rcx     # 0x41105
movl $0xd4, %edx
callq 0xc180
leaq 0x32600(%rip), %rdi     # 0x4114c
leaq 0x324cc(%rip), %rsi     # 0x4101f
leaq 0x325ab(%rip), %rcx     # 0x41105
movl $0xe0, %edx
callq 0xc180
leaq 0x3267e(%rip), %rdi     # 0x411e9
leaq 0x324ad(%rip), %rsi     # 0x4101f
leaq 0x3258c(%rip), %rcx     # 0x41105
movl $0xe6, %edx
callq 0xc180
leaq 0x32eab(%rip), %rdi     # 0x41a35
leaq 0x3248e(%rip), %rsi     # 0x4101f
leaq 0x3256d(%rip), %rcx     # 0x41105
movl $0xcd, %edx
callq 0xc180
leaq 0x325a3(%rip), %rdi     # 0x4114c
leaq 0x3246f(%rip), %rsi     # 0x4101f
leaq 0x3254e(%rip), %rcx     # 0x41105
movl $0xd3, %edx
callq 0xc180
nop