// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsi, -0x48(%rbp)
movl (%rsi), %eax
andl $0x7fff, %eax           # imm = 0x7FFF
movq %rax, -0x40(%rbp)
cmpl $0x4, %eax
jbe 0x131af
movq %rdx, %rbx
movq 0xb8(%rdi), %rax
movq (%rax), %r13
leaq 0x8(%rdx), %rax
movq %rax, -0x38(%rbp)
xorl %r15d, %r15d
xorl %eax, %eax
xorl %r9d, %r9d
movq -0x48(%rbp), %rcx
movl 0x4(%rcx,%r15,4), %esi
movl %esi, %edx
leal -0x2(%rdx), %ecx
cmpl $-0x4, %ecx
ja 0x13071
movl %edx, %ecx
shrl %ecx
movl -0x4(%r13,%rcx,4), %r14d
movl %edx, %r8d
andl $0x1, %r8d
xorl %r14d, %r8d
movl %r8d, %r12d
xorl $0x1, %r12d
cmpl $-0x1, %r14d
movl %r12d, %ecx
cmovel %r14d, %ecx
cmpl %edx, %ecx
movl %ecx, %edx
jne 0x12fff
leal -0x2(%r12), %ecx
cmpl $-0x4, %ecx
ja 0x1306e
cmpl %esi, %r12d
je 0x130ce
movq 0x492c4(%rip), %rdi     # 0x5c310
movl $0x2, %eax
testq %rdi, %rdi
je 0x130ce
movl %r9d, -0x2c(%rbp)
testb $0x1, %sil
jne 0x130bc
orl $0x1, %esi
movq (%rdi), %rcx
movl %r8d, %edx
callq *0x48(%rcx)
jmp 0x130c5
movl %r12d, %edx
cmpl $0x1, %edx
je 0x1318e
movq 0x4928f(%rip), %rdi     # 0x5c310
testq %rdi, %rdi
je 0x130a4
movl %r9d, %r12d
movl %eax, %r14d
testb $0x1, %sil
jne 0x13098
orl $0x1, %esi
xorl $0x1, %edx
movq (%rdi), %rax
callq *0x48(%rax)
movl %r14d, %eax
movl %r12d, %r9d
cmpl $0x1, %eax
adcl $0x0, %eax
incq %r15
cmpq -0x40(%rbp), %r15
jne 0x12ff4
jmp 0x13144
movq (%rdi), %rax
movl %r12d, %edx
callq *0x48(%rax)
movl $0x2, %eax
movl -0x2c(%rbp), %r9d
testw %r9w, %r9w
je 0x130ef
xorl %ecx, %ecx
movl %r9d, %edi
movzwl %di, %edx
movl (%rbx,%rdx,4), %esi
cmpl %esi, %r12d
jae 0x13112
movl %esi, 0x4(%rbx,%rdx,4)
incl %ecx
decw %di
jne 0x130d9
movl %r12d, 0x4(%rbx)
incl %r9d
xorl %edi, %edi
movzwl %di, %edx
movzwl %r9w, %ecx
decl %ecx
cmpl %edx, %ecx
jle 0x130aa
xorl 0x8(%rbx,%rdx,4), %r14d
cmpl $0x2, %r14d
jae 0x130aa
jmp 0x1318e
movl %r12d, 0x4(%rbx,%rdx,4)
jne 0x13137
cmpw %r9w, %di
jae 0x130f8
movq -0x38(%rbp), %rsi
leaq (%rsi,%rdx,4), %rdx
movl (%rdx), %esi
movl %esi, -0x4(%rdx)
addq $0x4, %rdx
decw %cx
jne 0x13127
jmp 0x130f8
xorl %r14d, %esi
cmpl $0x2, %esi
jb 0x1318e
incl %r9d
jmp 0x130f8
movzwl %r9w, %esi
cmpw $0x4, %si
ja 0x1319e
testw %r9w, %r9w
je 0x13197
movzwl %r9w, %r8d
movw $0x1, %di
xorl %r9d, %r9d
movl 0x4(%rbx,%r9,4), %ecx
testb $0x1, %cl
jne 0x13173
orl $0x1, %ecx
movl %ecx, 0x4(%rbx,%r9,4)
jmp 0x13181
movl $0x1, %edx
movl %r9d, %ecx
shll %cl, %edx
movl %edx, %ecx
shll %cl, %edi
incq %r9
cmpq %r9, %r8
jne 0x1315f
shll $0x10, %edi
jmp 0x1319c
movl $0x3, %eax
xorl %esi, %esi
jmp 0x1319e
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 0x2f348(%rip), %rdi     # 0x424fe
leaq 0x2ec4b(%rip), %rsi     # 0x41e08
leaq 0x2f34e(%rip), %rcx     # 0x42512
movl $0x12a, %edx            # imm = 0x12A
callq 0xb180