// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
incq 0xd0(%rdi)
movl %esi, %r15d
leal -0x2(%r15), %eax
cmpl $-0x4, %eax
ja 0x15dbe
movl %r15d, %eax
andl $0x1, %eax
je 0x15dbe
movq %rdi, %rbx
movl %edx, %r14d
shrl %r15d
leal -0x1(%r15), %r12d
movq 0x4674b(%rip), %rdi     # 0x5c310
testq %rdi, %rdi
je 0x15bfa
movq (%rdi), %rax
callq *0x20(%rax)
movq 0x46739(%rip), %rdi     # 0x5c310
testq %rdi, %rdi
je 0x15bfa
movq (%rdi), %rax
movl %r12d, %esi
movl %r14d, %edx
callq *0x30(%rax)
movq 0x46721(%rip), %rdi     # 0x5c310
testq %rdi, %rdi
je 0x15bfa
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 0x15cb1
leal -0x2(%r14), %ecx
cmpl $-0x4, %ecx
ja 0x15c2e
movl %edx, %esi
xorl %r14d, %esi
cmpl $0x1, %esi
jbe 0x15ddd
cmpl $-0x4, %ecx
ja 0x15c56
movl %r14d, %esi
shrl %esi
leal -0x1(%rsi), %edi
cmpl %r12d, %edi
ja 0x15dfc
movl %r14d, %edi
orl $0x1, %edi
movl %esi, %esi
cmpl -0x4(%rax,%rsi,4), %edi
jne 0x15e1b
movl %edx, %esi
shrl %esi
cmpl %esi, %r15d
jne 0x15cdb
movl %r14d, (%rax,%r13,4)
movl $0x3, %r15d
cmpl %r12d, 0x68(%rbx)
jbe 0x15d35
movq 0x60(%rbx), %rax
movl (%rax,%r13,4), %r14d
cmpl $-0x1, %r14d
je 0x15d35
movq 0x18(%rbx), %rcx
movq 0x38(%rbx), %rax
movq (%rcx), %rcx
movl %r14d, %edx
movl 0x4(%rax,%rdx,8), %esi
testb $-0x80, 0xd(%rcx,%rsi,4)
je 0x15d6b
movl (%rax,%rdx,8), %r14d
cmpl $-0x1, %r14d
jne 0x15c90
jmp 0x15d35
movl $0x3, %r15d
cmpl %r14d, %edx
je 0x15d35
leaq 0x2da6c(%rip), %rdi     # 0x4372f
leaq 0x2c13e(%rip), %rsi     # 0x41e08
leaq 0x2d869(%rip), %rcx     # 0x4353a
movl $0x2e3, %edx            # imm = 0x2E3
callq 0xb180
cmpl $-0x4, %ecx
ja 0x15d03
cmpl %r14d, %edx
jae 0x15d03
movl %r14d, %esi
orl $0x1, %esi
andl $0x1, %r14d
xorl %edx, %r14d
xorl $0x1, %r14d
movq %rbx, %rdi
movl %r14d, %edx
callq 0x15b80
jmp 0x15d32
movl %edx, %esi
orl $0x1, %esi
andl $0x1, %edx
xorl %r14d, %edx
xorl $0x1, %edx
movq %rbx, %rdi
callq 0x15b80
movl $0x4, %r15d
cmpl $0x4, %eax
je 0x15d35
movq 0xb8(%rbx), %rcx
movq (%rcx), %rcx
movl %r14d, (%rcx,%r13,4)
movl %eax, %r15d
movq 0x465d4(%rip), %rdi     # 0x5c310
testq %rdi, %rdi
je 0x15d59
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x465c2(%rip), %rdi     # 0x5c310
testq %rdi, %rdi
je 0x15d59
movq (%rdi), %rax
callq *0x28(%rax)
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, %esi
je 0x15d35
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x140e6
cmpl $0x4, %eax
je 0x15db3
cmpl $-0x1, %r14d
je 0x15d35
movq 0x18(%rbx), %rax
movq 0x38(%rbx), %rcx
movl %r14d, %edx
movl (%rcx,%rdx,8), %r14d
cmpq %r12, %r14
je 0x15d35
movl 0x4(%rcx,%r14,8), %esi
movq (%rax), %rdx
testb $-0x80, 0xd(%rdx,%rsi,4)
jne 0x15d91
cmpl $-0x1, %esi
jne 0x15d76
jmp 0x15d35
movl $0x4, %r15d
jmp 0x15d35
leaq 0x2d6ff(%rip), %rdi     # 0x434c4
leaq 0x2c03c(%rip), %rsi     # 0x41e08
leaq 0x2d767(%rip), %rcx     # 0x4353a
movl $0x2a5, %edx            # imm = 0x2A5
callq 0xb180
leaq 0x2d7b7(%rip), %rdi     # 0x4359b
leaq 0x2c01d(%rip), %rsi     # 0x41e08
leaq 0x2d748(%rip), %rcx     # 0x4353a
movl $0x2b0, %edx            # imm = 0x2B0
callq 0xb180
leaq 0x2d811(%rip), %rdi     # 0x43614
leaq 0x2bffe(%rip), %rsi     # 0x41e08
leaq 0x2d729(%rip), %rcx     # 0x4353a
movl $0x2b2, %edx            # imm = 0x2B2
callq 0xb180
leaq 0x2d875(%rip), %rdi     # 0x43697
leaq 0x2bfdf(%rip), %rsi     # 0x41e08
leaq 0x2d70a(%rip), %rcx     # 0x4353a
movl $0x2b7, %edx            # imm = 0x2B7
callq 0xb180