// File: /workspace/github_cpp_makefile_star2_O2/vsklad[P]cgen/./bal/cnf/processor/cnfoptimizer.cpp
// Function: bal::CnfOptimizer::assign_literal_value(unsigned int, unsigned int)
inline processor_result_t CnfOptimizer::assign_literal_value(const literalid_t literal_id, const literalid_t value) {
        variables_assigned_++;
        _assert_level_1(literal_t__is_variable(literal_id) && !literal_t__is_negation(literal_id));
        
        processor_result_t result = erSatisfied;
        const variableid_t variable_id = literal_t__variable_id(literal_id);
        TRACE_LEVEL_NEXT;
        TRACE_VARIABLE_ASSIGNMENT(variable_id, value);
        TRACE_LEVEL_NEXT;
        
        const literalid_t old_value = variables_.data()[variable_id];
        if (literal_t__is_variable(old_value)) {
            // if variable then the new value must be other than self
            _assert_level_2(!literal_t__is_variable(value) || !literal_t__is_same_variable(old_value, value));
            // can reference preceding variables only
            _assert_level_1(!literal_t__is_variable(value) || literal_t__variable_id(value) <= variable_id);
            // the referenced variable must point to self
            // note the same is fine for old_value since eliminated variables are not updated
            // until post-processing
            _assert_level_1(!literal_t__is_variable(value) ||
                            literal_t__unnegated(value) == variables_.data()[literal_t__variable_id(value)]);
            
            if (variable_id != literal_t__variable_id(old_value)) {
                // a variable is pointing to some other variable already
                // can happen during recursion; resolve the pair of values
                // TPDO: the only known reason for thsi situation is when pair of variables resolves to two values
                // and the second varianble is resolved while assigning the first one;
                // a more optimal solution would be to assign both at once and iterate clauses for both at the same time
                if (literal_t__is_variable(value) && value > old_value) {
                    result = assign_literal_value(literal_t__unnegated(value), literal_t__substitute_literal(value, old_value));
                } else {
                    result = assign_literal_value(literal_t__unnegated(old_value), literal_t__substitute_literal(old_value, value));
                    if (result != erConflict) {
                        // the clauses are handled where the variable was assigned from earlier
                        // all that remains is to update the reference value
                        variables_.data()[variable_id] = value;
                    };
                };
            } else {
                // assign the value immediately to prevent recursive evaluation
                variables_.data()[variable_id] = value;
                
                // go through all clauses that the variable is in
                // exclude the original clause
                // if not satisfied:
                //   remove the old clause from the indexes of all variables
                //   prepare a simplified copy
                //     note this may simplify the flags if an aggregate
                //   append afresh with validation check and merging
                //     note this may be an aggregate
                
                // there is no need to optimize the index since it will not be used again
                CnfProcessor::nonoptimizing_clauses_iterator_t iterator(clauses_index_, *this);
                container_offset_t offset = iterator.first(variable_id);
                while (offset != CONTAINER_END) {
                    if (evaluate_clause(offset) == erConflict) {
                        result = erConflict;
                        break;
                    };
                    offset = iterator.next();
                };
            };
        } else {
            // the same constant can be assigned again while updating indexes recursively
            _assert_level_0(old_value == value);
        };
        TRACE_LEVEL_PREV;
        TRACE_LEVEL_PREV;
        return result;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
incq 0xd0(%rdi)
movl %esi, %r15d
leal -0x2(%r15), %eax
cmpl $-0x4, %eax
ja 0x13c8f
movl %r15d, %eax
andl $0x1, %eax
je 0x13c8f
movq %rdi, %rbx
movl %edx, %r14d
shrl %r15d
leal -0x1(%r15), %r12d
movq 0x3d80a(%rip), %rdi     # 0x51300
testq %rdi, %rdi
je 0x13b2b
movq (%rdi), %rax
callq *0x20(%rax)
movq 0x3d7f8(%rip), %rdi     # 0x51300
testq %rdi, %rdi
je 0x13b2b
movq (%rdi), %rax
movl %r12d, %esi
movl %r14d, %edx
callq *0x30(%rax)
movq 0x3d7e0(%rip), %rdi     # 0x51300
testq %rdi, %rdi
je 0x13b2b
movq (%rdi), %rax
callq *0x20(%rax)
movq 0xb8(%rbx), %rax
movq (%rax), %rax
movl %r12d, %r13d
movl (%rax,%r13,4), %edx
leal -0x2(%rdx), %ecx
cmpl $-0x4, %ecx
ja 0x13be1
leal -0x2(%r14), %ecx
cmpl $-0x4, %ecx
ja 0x13b5f
movl %edx, %esi
xorl %r14d, %esi
cmpl $0x1, %esi
jbe 0x13cae
cmpl $-0x4, %ecx
ja 0x13b87
movl %r14d, %esi
shrl %esi
leal -0x1(%rsi), %edi
cmpl %r12d, %edi
ja 0x13cec
movl %r14d, %edi
orl $0x1, %edi
movl %esi, %esi
cmpl -0x4(%rax,%rsi,4), %edi
jne 0x13d0b
movl %edx, %esi
shrl %esi
cmpl %esi, %r15d
jne 0x13c24
movl %r14d, (%rax,%r13,4)
leaq 0x30(%rbx), %rax
leaq -0x40(%rbp), %r14
movq %rax, (%r14)
orq $-0x1, 0x8(%r14)
movq %rbx, 0x10(%r14)
movq %r14, %rdi
movl %r12d, %esi
callq 0x14b90
pushq $0x3
popq %r15
pushq $0x4
popq %r12
cmpl $-0x1, %eax
je 0x13bee
movq %rbx, %rdi
movl %eax, %esi
callq 0x1292a
cmpl $0x4, %eax
je 0x13c71
movq %r14, %rdi
callq 0x14be6
jmp 0x13bbf
cmpl %r14d, %edx
jne 0x13ccd
pushq $0x3
popq %r15
movq 0x3d70b(%rip), %rdi     # 0x51300
testq %rdi, %rdi
je 0x13c12
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x3d6f9(%rip), %rdi     # 0x51300
testq %rdi, %rdi
je 0x13c12
movq (%rdi), %rax
callq *0x28(%rax)
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x4, %ecx
ja 0x13c4f
cmpl %r14d, %edx
jae 0x13c4f
movl %r14d, %esi
orl $0x1, %esi
andl $0x1, %r14d
xorl %edx, %r14d
xorl $0x1, %r14d
movq %rbx, %rdi
movl %r14d, %edx
callq 0x13aae
movl %eax, %r15d
jmp 0x13bee
movl %edx, %esi
orl $0x1, %esi
andl $0x1, %edx
xorl %r14d, %edx
xorl $0x1, %edx
movq %rbx, %rdi
callq 0x13aae
cmpl $0x4, %eax
jne 0x13c79
pushq $0x4
jmp 0x13bec
movl %r12d, %r15d
jmp 0x13bee
movl %eax, %r15d
movq 0xb8(%rbx), %rax
movq (%rax), %rax
movl %r14d, (%rax,%r13,4)
jmp 0x13bee
leaq 0x2182e(%rip), %rdi     # 0x354c4
leaq 0x2016b(%rip), %rsi     # 0x33e08
leaq 0x21896(%rip), %rcx     # 0x3553a
movl $0x2a5, %edx            # imm = 0x2A5
callq 0xc180
leaq 0x218e6(%rip), %rdi     # 0x3559b
leaq 0x2014c(%rip), %rsi     # 0x33e08
leaq 0x21877(%rip), %rcx     # 0x3553a
movl $0x2b0, %edx            # imm = 0x2B0
callq 0xc180
leaq 0x21a5b(%rip), %rdi     # 0x3572f
leaq 0x2012d(%rip), %rsi     # 0x33e08
leaq 0x21858(%rip), %rcx     # 0x3553a
movl $0x2e3, %edx            # imm = 0x2E3
callq 0xc180
leaq 0x21921(%rip), %rdi     # 0x35614
leaq 0x2010e(%rip), %rsi     # 0x33e08
leaq 0x21839(%rip), %rcx     # 0x3553a
movl $0x2b2, %edx            # imm = 0x2B2
callq 0xc180
leaq 0x21985(%rip), %rdi     # 0x35697
leaq 0x200ef(%rip), %rsi     # 0x33e08
leaq 0x2181a(%rip), %rcx     # 0x3553a
movl $0x2b7, %edx            # imm = 0x2B7
callq 0xc180