// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r15d
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movq 0xb8(%rbx), %rsi
callq 0x3d3ba
movq %rbx, %rdi
callq 0x131f4
movq %rbx, %rdi
movl %r15d, %esi
callq 0x132bc
testl %r15d, %r15d
je 0x125af
movl %eax, %r14d
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
callq *0x58(%rax)
cmpl %eax, %r14d
je 0x125af
cmpl $0x7ffffffe, %r14d      # imm = 0x7FFFFFFE
jae 0x12741
movq 0x8(%rbx), %rax
movl %r14d, 0x8(%rax)
movl %r14d, 0xb0(%rax)
movq %rbx, -0x30(%rbp)
movq 0x8(%rbx), %rax
cmpl $-0x1, 0xc8(%rax)
jne 0x12722
leaq 0x78(%rax), %rdi
movl 0x88(%rax), %r12d
movq 0x78(%rax), %rax
xorl %r13d, %r13d
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq *(%rax)
testl %r12d, %r12d
je 0x12637
movl $0x7fff, %ebx           # imm = 0x7FFF
movq -0x30(%rbp), %rdi
movq 0x18(%rdi), %rax
movq (%rax), %rax
movl %r13d, %ecx
leaq (%rax,%rcx,4), %r15
addq $0xc, %r15
movl (%r15), %r14d
andl %ebx, %r14d
movq %r15, %rsi
callq 0x189d2
testb %al, %al
je 0x1262b
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq %r15, %rsi
leaq -0x40(%rbp), %rdx
callq 0x113ba
addl %r14d, %r13d
addl $0x4, %r13d
cmpl %r12d, %r13d
jb 0x125e8
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rdi
movq 0xb8(%rbx), %rsi
callq 0x3d2a2
movq 0x28(%rbx), %rax
movq 0x18(%rax), %rdi
addq $0x8, %rax
cmpq %rax, %rdi
je 0x12711
movq -0x30(%rbp), %r14
cmpl $0x0, 0x48(%rdi)
je 0x126f4
movq 0x40(%rdi), %r13
xorl %r15d, %r15d
movq %rdi, -0x48(%rbp)
movl (%r13,%r15,4), %eax
leal -0x2(%rax), %ecx
cmpl $-0x3, %ecx
setae %cl
orb %cl, %al
testb $0x1, %al
jne 0x126e9
movq 0x8(%r14), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, %r12d
movq 0x10(%r14), %rdi
movl (%r13,%r15,4), %eax
xorl $0x1, %eax
movl %r12d, -0x40(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x40(%rbp), %rbx
movq %rbx, %rsi
movl $0x2, %edx
callq 0x10fec
movq 0x10(%r14), %rdi
movl %r12d, %eax
xorl $0x1, %eax
movl (%r13,%r15,4), %ecx
movl %eax, -0x40(%rbp)
movl %ecx, -0x3c(%rbp)
movq %rbx, %rsi
movl $0x2, %edx
callq 0x10fec
movq -0x48(%rbp), %rdi
movl %r12d, (%r13,%r15,4)
incq %r15
movl 0x48(%rdi), %eax
cmpq %rax, %r15
jb 0x12679
callq 0xc1b0
movq %rax, %rdi
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
addq $0x8, %rax
cmpq %rax, %rdi
jne 0x12664
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x31b4b(%rip), %rdi     # 0x44274
leaq 0x31b5e(%rip), %rsi     # 0x4428e
leaq 0x3436d(%rip), %rcx     # 0x46aa4
movl $0x52, %edx
callq 0xc180
leaq 0x2eec3(%rip), %rdi     # 0x4160b
leaq 0x2eed9(%rip), %rsi     # 0x41628
leaq 0x2eeea(%rip), %rcx     # 0x41640
movl $0x9b, %edx
callq 0xc180