// File: vsklad[P]cgen/./bal/cnf/processor/cnfoptimizer.cpp
// Function: bal::CnfVariableNormalizer::execute(bool)
bool CnfVariableNormalizer::execute(const bool b_reindex_variables) {
        cnf_.named_variables_assign_negations(variables_);
        
        // index is needed for checking if a variable is used
        build_clauses_index();
        const variableid_t new_variables_size = update_variables(b_reindex_variables);
        if (b_reindex_variables && new_variables_size != cnf_.variables_size()) {
            set_variables_size(new_variables_size);
        };
            
        // nothe that rebuild_clauses() invalidates clauses_index_ and processed_offset_
        // since these are not used below, its fine
        rebuild_clauses<CnfOptimizer, &CnfOptimizer::_update_clause_variables>(this, false);
        cnf_.named_variables_update(variables_);
        
        // it is possible that some negated references remain
        // since the same variable may appear straight and complemented
        // across named variables
        // for those, need to introduce new variables
        
        for (auto vit = named_variables_.begin(); vit != named_variables_.end(); vit++) {
            literalid_t* const template_ = vit->second.data();
            for (auto j = 0; j < vit->second.size(); j++) {
                if (literal_t__is_variable(template_[j]) && literal_t__is_negation(template_[j])) {
                    literalid_t value = cnf_.new_variable_literal();
                    clauses_.append_clause_l(value, literal_t__negated(template_[j]));
                    clauses_.append_clause_l(literal_t__negated(value), template_[j]);
                    template_[j] = value;
                };
            };
        };
        
        return true;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x8(%rax), %rdi
movq 0xb8(%rax), %rsi
callq 0x55470
movq -0x40(%rbp), %rdi
callq 0x16ac0
movq -0x40(%rbp), %rdi
movb -0x9(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x16ae0
movl %eax, -0x10(%rbp)
testb $0x1, -0x9(%rbp)
je 0x16048
movq -0x40(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, -0x44(%rbp)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x58(%rax)
movl %eax, %ecx
movl -0x44(%rbp), %eax
cmpl %ecx, %eax
je 0x16048
movq -0x40(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x16df0
movq -0x40(%rbp), %rsi
xorl %edx, %edx
movq %rsi, %rdi
callq 0x16e20
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0xb8(%rax), %rsi
callq 0x55280
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x17250
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x172b0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x17280
testb $0x1, %al
jne 0x160a2
jmp 0x161ae
leaq -0x18(%rbp), %rdi
callq 0x172e0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x10310
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x172e0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x102f0
movl %eax, %ecx
movl -0x48(%rbp), %eax
cmpl %ecx, %eax
jae 0x16198
movq -0x28(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
xorl %eax, %eax
cmpl $0x1, (%rcx,%rdx,4)
movb %al, -0x49(%rbp)
jbe 0x1610f
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpl $-0x2, (%rax,%rcx,4)
setbe %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x16118
jmp 0x16188
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x16188
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, -0x30(%rbp)
movq 0x10(%rax), %rdi
movl -0x30(%rbp), %esi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
xorl $0x1, %edx
callq 0x13ae0
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x30(%rbp), %esi
xorl $0x1, %esi
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
callq 0x13ae0
movl -0x30(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x1618a
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x160c2
jmp 0x1619a
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x17310
movq %rax, -0x38(%rbp)
jmp 0x1607b
movb $0x1, %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)