// File: /workspace/github_cpp_makefile_star2_O1/vsklad[P]cgen/./bal/cnf/processor/cnfoptimizer.cpp
// Function: bal::CnfOptimizer::normalize_cu(unsigned int const*, unsigned int*) const
inline processor_result_t CnfOptimizer::normalize_cu(const uint32_t* const p_src, uint32_t* const p_dst) const {
        processor_result_t result = erUndetermined;
        
        const literalid_t* literals = _clause_literals(p_src);
        const clause_size_t clause_size = _clause_size(p_src);
        const literalid_t* const var_values = variables_.data();
            
        // an unaggregated clause indeed
        _assert_level_1(!_clause_size_is_aggregated(clause_size));
        
        literalid_t* new_literals = _clause_literals(p_dst);
        clause_size_t new_clause_size = 0;
        
        for (auto i = 0; i < clause_size; i++) {
            const literalid_t original_value = literals[i]; // because p_src may == p_dst
            const literalid_t new_value = literal_t::resolve(var_values, original_value);
            // count resolved literal if not a constant
            if (literal_t__is_variable(new_value)) {
                if (new_value != original_value) {
                    __TRACE_ASSIGN_LITERAL;
                    if (result == erUndetermined || result == erChangedC) {
                        result = erChangedV;
                    };
                };
                // insert into the sorted sequence
                auto j = new_clause_size;
                while (j > 0) {
                    if (new_value >= new_literals[j - 1]) {
                        new_literals[j] = new_value;
                        break;
                    } else {
                        new_literals[j] = new_literals[j - 1];
                        j--;
                    };
                };
                if (j == 0) {
                    new_literals[0] = new_value;
                    new_clause_size++;
                } else if (new_value == new_literals[j - 1]) {
                    // check duplicate; should be rare
                    for (auto k = j; k < new_clause_size; k++) {
                        new_literals[k] = new_literals[k + 1];
                    };
                } else {
                    // check presence of a variable together with its negation
                    if (literal_t__is_same_variable(new_value, new_literals[j - 1])) {
                        result = erSatisfied;
                        break;
                    };
                    new_clause_size++;
                };
                // check presence of a variable together with its negation
                if (j < new_clause_size - 1 && literal_t__is_same_variable(new_value, new_literals[j + 1])) {
                    result = erSatisfied;
                    break;
                };
            } else if (literal_t__is_constant_1(new_value)) {
                result = erSatisfied;
                break;
            } else {
                // a literal is 0; the clause is shortened
                __TRACE_ASSIGN_LITERAL;
                if (result == erUndetermined) {
                    result = erChangedC;
                };
            };
        };
        
        if (result != erSatisfied) {
            if (_clause_size_is_aggregated(new_clause_size)) {
                // the clause has become aggregated; unnegate literals and build flags
                uint16_t flags = 0x1;
                for (auto i = 0; i < new_clause_size; i++) {
                    if (literal_t__is_negation(new_literals[i])) {
                        literal_t__unnegate(new_literals[i]);
                    } else {
                        flags <<= (0x1 << i);
                    };
                };
                _clause_header_set(p_dst, flags, new_clause_size);
            } else {
                _clause_header_set(p_dst, 0, new_clause_size);
            }
        } else {
            _clause_header_set(p_dst, 0, 0);
        };
    
        return result;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl (%rsi), %r9d
andl $0x7fff, %r9d           # imm = 0x7FFF
cmpl $0x4, %r9d
jbe 0x145de
movq %rdx, %rbx
movq %rsi, %r8
movq 0xb8(%rdi), %rax
movq (%rax), %r13
leaq 0x8(%rdx), %rax
movq %rax, -0x48(%rbp)
xorl %r14d, %r14d
xorl %eax, %eax
xorl %r15d, %r15d
movq %rsi, -0x40(%rbp)
movq %r9, -0x38(%rbp)
movl 0x4(%r8,%r14,4), %esi
movl %esi, %edx
leal -0x2(%rdx), %ecx
cmpl $-0x4, %ecx
ja 0x1444e
movl %edx, %ecx
shrl %ecx
decl %ecx
movl (%r13,%rcx,4), %ecx
movl %edx, %r12d
andl $0x1, %r12d
xorl %ecx, %r12d
xorl $0x1, %r12d
cmpl $-0x1, %ecx
cmovel %ecx, %r12d
cmpl %edx, %r12d
movl %r12d, %edx
jne 0x1441c
jmp 0x14451
movl %edx, %r12d
leal -0x2(%r12), %ecx
cmpl $-0x4, %ecx
ja 0x14487
cmpl %esi, %r12d
je 0x144e8
movq 0x4aea5(%rip), %rdi     # 0x5f310
testq %rdi, %rdi
je 0x144dd
movl %eax, -0x2c(%rbp)
testb $0x1, %sil
jne 0x144c9
orl $0x1, %esi
movl %r12d, %edx
xorl $0x1, %edx
movq (%rdi), %rax
jmp 0x144cf
cmpl $0x1, %r12d
je 0x1455e
movq 0x4ae78(%rip), %rdi     # 0x5f310
testq %rdi, %rdi
je 0x144c1
movl %eax, -0x2c(%rbp)
testb $0x1, %sil
jne 0x144ad
orl $0x1, %esi
xorl $0x1, %r12d
movq (%rdi), %rax
movl %r12d, %edx
callq *0x48(%rax)
movl -0x2c(%rbp), %eax
movq -0x40(%rbp), %r8
movq -0x38(%rbp), %r9
cmpl $0x1, %eax
adcl $0x0, %eax
jmp 0x1452d
movq (%rdi), %rax
movl %r12d, %edx
callq *0x48(%rax)
movl -0x2c(%rbp), %eax
movq -0x40(%rbp), %r8
movq -0x38(%rbp), %r9
cmpl $0x3, %eax
movl $0x2, %ecx
cmovbl %ecx, %eax
movl %r15d, %edi
testw %r15w, %r15w
je 0x1450e
xorl %ecx, %ecx
movl %r15d, %edi
movzwl %di, %edx
movl (%rbx,%rdx,4), %esi
cmpl %esi, %r12d
jae 0x14531
movl %esi, 0x4(%rbx,%rdx,4)
incl %ecx
decw %di
jne 0x144f6
xorl %edi, %edi
movl %r12d, 0x4(%rbx)
incl %r15d
movzwl %di, %edx
movzwl %r15w, %ecx
decl %ecx
cmpl %edx, %ecx
jle 0x1452d
xorl 0x8(%rbx,%rdx,4), %r12d
cmpl $0x2, %r12d
jb 0x1455e
xorl %ecx, %ecx
jmp 0x14565
movl %r12d, 0x4(%rbx,%rdx,4)
jne 0x14556
cmpw %r15w, %di
jae 0x14515
movq -0x48(%rbp), %rsi
leaq (%rsi,%rdx,4), %rdx
movl (%rdx), %esi
movl %esi, -0x4(%rdx)
addq $0x4, %rdx
decw %cx
jne 0x14546
jmp 0x14515
xorl %r12d, %esi
cmpl $0x2, %esi
jae 0x14512
movl $0x3, %eax
movb $0x1, %cl
testb %cl, %cl
jne 0x14575
incq %r14
cmpq %r9, %r14
jne 0x14415
xorl %esi, %esi
cmpl $0x3, %eax
je 0x145cd
movzwl %r15w, %esi
cmpw $0x4, %si
ja 0x145cd
testw %r15w, %r15w
je 0x145c6
movzwl %r15w, %r8d
movw $0x1, %di
xorl %r9d, %r9d
movl 0x4(%rbx,%r9,4), %ecx
testb $0x1, %cl
jne 0x145ab
orl $0x1, %ecx
movl %ecx, 0x4(%rbx,%r9,4)
jmp 0x145b9
movl $0x1, %edx
movl %r9d, %ecx
shll %cl, %edx
movl %edx, %ecx
shll %cl, %edi
incq %r9
cmpq %r9, %r8
jne 0x14597
shll $0x10, %edi
jmp 0x145cb
movl $0x10000, %edi          # imm = 0x10000
orl %edi, %esi
movl %esi, (%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ff09(%rip), %rdi     # 0x444ee
leaq 0x2f80c(%rip), %rsi     # 0x43df8
leaq 0x2ff0f(%rip), %rcx     # 0x44502
movl $0x12a, %edx            # imm = 0x12A
callq 0xc180