// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x38, %rsp
movl %edx, %ebx
movl %esi, %r13d
movq %rdi, %r14
callq 0xe4f6
movq 0xb0(%r14), %rdx
movq 0x78(%r14), %rax
movq 0x90(%r14), %rcx
movl -0x4(%rdx), %r15d
movl (%rcx,%r15,4), %edx
movl (%rax,%rdx,4), %r12d
cmpl $0x2, %r12d
jae 0xd9fb
movq 0x98(%r14), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movq %rdx, %rsi
subq %r15, %rsi
cmpq $0x1, %rsi
jne 0xd58d
cmpl $-0x1, %r13d
jne 0xda1a
movq %r14, %rdi
callq 0xe4f6
movq 0xb0(%r14), %rsi
movq 0x90(%r14), %rax
movl -0x4(%rsi), %ecx
leaq (%rax,%rcx,4), %rax
movl (%rax), %ecx
shlq $0x2, %rcx
addq 0x78(%r14), %rcx
cmpq 0x80(%r14), %rcx
je 0xd551
movq %rcx, 0x80(%r14)
cmpq 0x98(%r14), %rax
je 0xd561
movq %rax, 0x98(%r14)
movb $0x1, %al
testb %al, %al
jne 0xd57d
leaq -0x4(%rsi), %rdi
movq %rsi, %rdx
subq %rsi, %rdx
callq 0xb450
movq 0xb0(%r14), %rsi
addq $-0x4, %rsi
movq %rsi, 0xb0(%r14)
jmp 0xd9e9
cmpq $0x2, %rsi
setne %dil
movl %ebx, %r8d
xorb $0x1, %r8b
orb %dil, %r8b
jne 0xd5ee
movq 0x98(%r14), %rdi
subq %rcx, %rdi
sarq $0x2, %rdi
leaq 0x2(%r15), %r8
cmpq %r8, %rdi
jne 0xd5c8
movq 0x80(%r14), %rdi
subq %rax, %rdi
sarq $0x2, %rdi
jmp 0xd5cd
movl 0x8(%rcx,%r15,4), %edi
movl 0x4(%rcx,%r15,4), %r8d
subq %r8, %rdi
cmpq $0x1, %rdi
jne 0xd5ee
cmpl $-0x1, %r13d
jne 0xdab5
xorl (%rax,%r8,4), %r12d
jmp 0xd51a
movl %ebx, -0x38(%rbp)
cmpl $0x1, %r13d
ja 0xd624
cmpq $0x2, %rsi
jne 0xd624
movq 0x98(%r14), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
leaq 0x2(%r15), %rbx
cmpq %rbx, %rsi
jne 0xd643
movq 0x80(%r14), %rsi
subq %rax, %rsi
sarq $0x2, %rsi
jmp 0xd648
cmpl $-0x1, %r13d
jne 0xd6db
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
leal 0x3(,%rax,2), %r13d
jmp 0xd9bd
movl 0x8(%rcx,%r15,4), %esi
movl 0x4(%rcx,%r15,4), %edi
subq %rdi, %rsi
cmpq $0x1, %rsi
jne 0xd6db
cmpb $0x0, -0x38(%rbp)
jne 0xdad4
movl %r13d, -0x30(%rbp)
movl (%rax,%rdi,4), %eax
movq %rax, -0x38(%rbp)
incl %eax
cmpl $0x2, %eax
jbe 0xda58
leaq 0x1(%r15), %r13
movq %r14, %rdi
callq 0xe4f6
movq 0xb0(%r14), %rax
movl -0x4(%rax), %eax
cmpq %rax, %r13
jb 0xda39
movq 0x90(%r14), %rax
movq 0x98(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r13, %rcx
jbe 0xda39
movl %r12d, -0x2c(%rbp)
cmpq %rbx, %rcx
jne 0xd7db
movq 0x78(%r14), %rcx
movq 0x80(%r14), %rdi
subq %rcx, %rdi
sarq $0x2, %rdi
jmp 0xd7e4
movl -0x38(%rbp), %r11d
testb %r11b, %r11b
jne 0xda77
cmpl $0x1, %r13d
ja 0xd7c6
movl %r13d, -0x30(%rbp)
movl %r12d, -0x2c(%rbp)
decq %rdx
movq 0x80(%r14), %rsi
movq 0x98(%r14), %rdi
subq %rcx, %rdi
sarq $0x2, %rdi
subq %rax, %rsi
sarq $0x2, %rsi
addq $-0x2, %rdi
movq %r15, %r13
notq %r13
shlq $0x2, %r13
movq %r15, %r8
leaq 0x1(%r8), %r12
cmpq %rdx, %r12
jae 0xd7ce
movq %rsi, %r9
cmpq %r8, %rdi
je 0xd744
movl 0x8(%rcx,%r8,4), %r9d
movl 0x4(%rcx,%r8,4), %r10d
subq %r10, %r9
addq $-0x4, %r13
movq %r12, %r8
cmpq $0x1, %r9
jne 0xd72a
movl (%rax,%r10,4), %ebx
leal 0x1(%rbx), %eax
cmpl $0x2, %eax
jbe 0xda96
movq %r14, %rdi
callq 0xe4f6
movq 0xb0(%r14), %rax
movl -0x4(%rax), %eax
cmpq %rax, %r12
jb 0xda39
movq 0x90(%r14), %rax
movq 0x98(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r12, %rcx
jbe 0xda39
decq %rcx
cmpq %r12, %rcx
movq %rbx, -0x48(%rbp)
jne 0xd832
movq 0x78(%r14), %rcx
movq 0x80(%r14), %r8
subq %rcx, %r8
sarq $0x2, %r8
jmp 0xd83b
xorl %r13d, %r12d
jmp 0xd9de
movl -0x2c(%rbp), %r12d
movl -0x30(%rbp), %r13d
jmp 0xd9c1
movl 0x8(%rax,%r15,4), %edi
movq 0x78(%r14), %rcx
movl 0x4(%rax,%r15,4), %ebx
cmpq %rbx, %rdi
movq %rdi, -0x48(%rbp)
je 0xd8a8
leaq (%rcx,%rbx,4), %r12
leaq (%rcx,%rdi,4), %rsi
movq 0x80(%r14), %rdx
subq %rsi, %rdx
je 0xd890
movq %r12, %rdi
movq %rsi, -0x40(%rbp)
movq -0x40(%rbp), %rsi
callq 0xb450
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdi
movq 0x80(%r14), %rax
movq %rax, %rcx
jmp 0xd896
movl 0x4(%rax,%r12,4), %r8d
movq 0x78(%r14), %rcx
movl (%rax,%r12,4), %ebx
cmpq %rbx, %r8
movq %r8, -0x40(%rbp)
je 0xd949
leaq (%rcx,%rbx,4), %rdi
leaq (%rcx,%r8,4), %rsi
movq 0x80(%r14), %rdx
subq %rsi, %rdx
je 0xd931
movq %rdi, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq %rsi, -0x58(%rbp)
callq 0xb450
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %r8
movq 0x80(%r14), %rax
movq %rax, %rcx
jmp 0xd937
movq %rsi, %rax
movq %rsi, %rcx
subq %rsi, %rax
addq %rax, %r12
cmpq %r12, %rcx
je 0xd8a8
movq %r12, 0x80(%r14)
movl -0x2c(%rbp), %r12d
xorl -0x30(%rbp), %r12d
movq 0x90(%r14), %rax
movq 0x98(%r14), %rdx
leaq (%rax,%r13,4), %rsi
addq $0x4, %rsi
cmpq %rdx, %rsi
je 0xd8e9
leaq (%rax,%r13,4), %rdi
subq %rsi, %rdx
callq 0xb450
movq -0x48(%rbp), %rdi
movq 0x90(%r14), %rax
movq 0x98(%r14), %rdx
xorl -0x38(%rbp), %r12d
addq $-0x4, %rdx
movq %rdx, 0x98(%r14)
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r13, %rdx
jbe 0xd919
subl %edi, %ebx
addl %ebx, (%rax,%r13,4)
incq %r13
cmpq %r13, %rdx
jne 0xd906
movq 0x90(%r14), %rax
movl (%rax,%r15,4), %eax
movq 0x78(%r14), %rcx
movl %r12d, (%rcx,%rax,4)
notl %r12d
andl $0x1, %r12d
jmp 0xd9e9
movq %rsi, %rax
movq %rsi, %rcx
subq %rsi, %rax
addq %rax, %rdi
cmpq %rdi, %rcx
je 0xd949
movq %rdi, 0x80(%r14)
movq 0x90(%r14), %rax
movq 0x98(%r14), %rdx
movq %rax, %rcx
subq %r13, %rcx
cmpq %rdx, %rcx
je 0xd98b
leaq (%rax,%r12,4), %rdi
leaq (%rax,%r12,4), %rsi
addq $0x4, %rsi
subq %rax, %rdx
addq %r13, %rdx
callq 0xb450
movq -0x40(%rbp), %r8
movq 0x90(%r14), %rax
movq 0x98(%r14), %rdx
movl -0x30(%rbp), %r13d
xorl -0x48(%rbp), %r13d
addq $-0x4, %rdx
movq %rdx, 0x98(%r14)
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r12, %rdx
jbe 0xd9b9
subl %r8d, %ebx
addl %ebx, (%rax,%r12,4)
incq %r12
cmpq %r12, %rdx
jne 0xd9ad
movl -0x2c(%rbp), %r12d
movl -0x38(%rbp), %r11d
xorl %r13d, %r12d
movq 0x78(%r14), %rax
movq 0x90(%r14), %rcx
testb %r11b, %r11b
je 0xd9de
movl (%rcx,%r15,4), %ecx
movl %r13d, (%rax,%rcx,4)
jmp 0xd9e9
movl (%rcx,%r15,4), %ecx
movl %r12d, (%rax,%rcx,4)
movl %r13d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x316da(%rip), %rdi     # 0x3f0dc
leaq 0x31616(%rip), %rsi     # 0x3f01f
leaq 0x316f5(%rip), %rcx     # 0x3f105
movl $0xc5, %edx
callq 0xb180
leaq 0x32000(%rip), %rdi     # 0x3fa21
leaq 0x315f7(%rip), %rsi     # 0x3f01f
leaq 0x316d6(%rip), %rcx     # 0x3f105
movl $0xc8, %edx
callq 0xb180
leaq 0x31c37(%rip), %rdi     # 0x3f677
leaq 0x315d8(%rip), %rsi     # 0x3f01f
leaq 0x31c77(%rip), %rcx     # 0x3f6c5
movl $0x26, %edx
callq 0xb180
leaq 0x31700(%rip), %rdi     # 0x3f15f
leaq 0x315b9(%rip), %rsi     # 0x3f01f
leaq 0x31698(%rip), %rcx     # 0x3f105
movl $0xd4, %edx
callq 0xb180
leaq 0x316ce(%rip), %rdi     # 0x3f14c
leaq 0x3159a(%rip), %rsi     # 0x3f01f
leaq 0x31679(%rip), %rcx     # 0x3f105
movl $0xe0, %edx
callq 0xb180
leaq 0x3174c(%rip), %rdi     # 0x3f1e9
leaq 0x3157b(%rip), %rsi     # 0x3f01f
leaq 0x3165a(%rip), %rcx     # 0x3f105
movl $0xe6, %edx
callq 0xb180
leaq 0x31f65(%rip), %rdi     # 0x3fa21
leaq 0x3155c(%rip), %rsi     # 0x3f01f
leaq 0x3163b(%rip), %rcx     # 0x3f105
movl $0xcd, %edx
callq 0xb180
leaq 0x31671(%rip), %rdi     # 0x3f14c
leaq 0x3153d(%rip), %rsi     # 0x3f01f
leaq 0x3161c(%rip), %rcx     # 0x3f105
movl $0xd3, %edx
callq 0xb180
nop