// File: /workspace/github_cpp_makefile_star2_O1/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 0x1729d
movl %r15d, %eax
andl $0x1, %eax
je 0x1729d
movq %rdi, %rbx
movl %edx, %r14d
shrl %r15d
movq 0x48299(%rip), %rdi     # 0x5f310
testq %rdi, %rdi
je 0x17082
movq (%rdi), %rax
callq *0x20(%rax)
leal -0x1(%r15), %r12d
movq 0x48283(%rip), %rdi     # 0x5f310
testq %rdi, %rdi
je 0x1709e
movq (%rdi), %rax
movl %r12d, %esi
movl %r14d, %edx
callq *0x30(%rax)
movq 0x4826b(%rip), %rdi     # 0x5f310
testq %rdi, %rdi
je 0x170b0
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 0x17162
leal -0x2(%r14), %ecx
cmpl $-0x4, %ecx
ja 0x170e4
movl %edx, %esi
xorl %r14d, %esi
cmpl $0x1, %esi
jbe 0x172bc
cmpl $-0x4, %ecx
ja 0x1710c
movl %r14d, %esi
shrl %esi
leal -0x1(%rsi), %edi
cmpl %r12d, %edi
ja 0x172db
movl %r14d, %edi
orl $0x1, %edi
movl %esi, %esi
cmpl -0x4(%rax,%rsi,4), %edi
jne 0x172fa
movl %edx, %esi
shrl %esi
cmpl %esi, %r15d
jne 0x17190
movl %r14d, (%rax,%r13,4)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl %r12d, 0x68(%rbx)
jbe 0x1712d
movq 0x60(%rbx), %rax
movl (%rax,%r13,4), %r14d
movq 0x18(%rbx), %rax
movq 0x38(%rbx), %rcx
cmpl $-0x1, %r14d
je 0x171c3
movl %r14d, %r8d
movl 0x4(%rcx,%r8,8), %esi
movq (%rax), %rdi
movl 0xc(%rdi,%rsi,4), %edi
testw %di, %di
jns 0x17159
movl (%rcx,%r8,8), %r14d
movl %edx, %esi
movl %esi, %edx
testw %di, %di
js 0x17135
jmp 0x171c8
movl $0x3, %r15d
cmpl %r14d, %edx
je 0x17267
leaq 0x2e5a7(%rip), %rdi     # 0x4571f
leaq 0x2cc79(%rip), %rsi     # 0x43df8
leaq 0x2e3a4(%rip), %rcx     # 0x4552a
movl $0x2e3, %edx            # imm = 0x2E3
callq 0xc180
cmpl $-0x4, %ecx
ja 0x1722d
cmpl %r14d, %edx
jae 0x1722d
movl %r14d, %esi
orl $0x1, %esi
andl $0x1, %r14d
xorl %edx, %r14d
xorl $0x1, %r14d
movq %rbx, %rdi
movl %r14d, %edx
callq 0x17036
jmp 0x1725c
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x3, %r15d
cmpl $-0x1, %esi
je 0x17267
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x15568
cmpl $0x4, %eax
je 0x17261
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpl $-0x1, %r14d
je 0x17226
movq 0x18(%rbx), %rcx
movq 0x38(%rbx), %rdx
movl %r14d, %edi
movl (%rdx,%rdi,8), %r14d
cmpq %r12, %r14
je 0x1721c
movl 0x4(%rdx,%r14,8), %edi
movq (%rcx), %r8
testb $-0x80, 0xd(%r8,%rdi,4)
cmovel %edi, %eax
je 0x17224
cmpl $-0x1, %r14d
jne 0x171fd
jmp 0x17226
movl %eax, %esi
cmpl $-0x1, %esi
jne 0x171dd
jmp 0x17267
movl %edx, %esi
orl $0x1, %esi
andl $0x1, %edx
xorl %r14d, %edx
xorl $0x1, %edx
movq %rbx, %rdi
callq 0x17036
movl $0x4, %r15d
cmpl $0x4, %eax
je 0x17267
movq 0xb8(%rbx), %rcx
movq (%rcx), %rcx
movl %r14d, (%rcx,%r13,4)
movl %eax, %r15d
jmp 0x17267
movl $0x4, %r15d
movq 0x480a2(%rip), %rdi     # 0x5f310
testq %rdi, %rdi
je 0x17279
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x48090(%rip), %rdi     # 0x5f310
testq %rdi, %rdi
je 0x1728b
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
leaq 0x2e210(%rip), %rdi     # 0x454b4
leaq 0x2cb4d(%rip), %rsi     # 0x43df8
leaq 0x2e278(%rip), %rcx     # 0x4552a
movl $0x2a5, %edx            # imm = 0x2A5
callq 0xc180
leaq 0x2e2c8(%rip), %rdi     # 0x4558b
leaq 0x2cb2e(%rip), %rsi     # 0x43df8
leaq 0x2e259(%rip), %rcx     # 0x4552a
movl $0x2b0, %edx            # imm = 0x2B0
callq 0xc180
leaq 0x2e322(%rip), %rdi     # 0x45604
leaq 0x2cb0f(%rip), %rsi     # 0x43df8
leaq 0x2e23a(%rip), %rcx     # 0x4552a
movl $0x2b2, %edx            # imm = 0x2B2
callq 0xc180
leaq 0x2e386(%rip), %rdi     # 0x45687
leaq 0x2caf0(%rip), %rsi     # 0x43df8
leaq 0x2e21b(%rip), %rcx     # 0x4552a
movl $0x2b7, %edx            # imm = 0x2B7
callq 0xc180
nop