// File: vsklad[P]cgen/./bal/cnf/processor/cnfoptimizer.cpp
// Function: bal::processor_result_t bal::CnfOptimizer::normalize_ca<false>(unsigned int const*, unsigned int*) const
inline processor_result_t CnfOptimizer::normalize_ca(const uint32_t* const p_src, uint32_t* const p_dst) const {
        processor_result_t result = erUndetermined;
        const clause_size_t clause_size = _clause_size(p_src);
        const literalid_t* const literals = _clause_literals(p_src);
        uint16_t flags = _clause_flags(p_src);
        const literalid_t* const variable_values = variables_.data();
        
        literalid_t* new_literals = _clause_literals(p_dst);
        clause_size_t new_clause_size = 0;
        
        _assert_level_0(_clause_size_is_aggregated(clause_size));
        
        for (auto i = 0; i < clause_size && flags != 0; i++) {
            const literalid_t original_value = literals[i]; // because p_src may == p_dst
            _assert_level_0(literal_t__is_variable(original_value) && !literal_t__is_negation(original_value));
            literalid_t new_value = literal_t::resolve(variable_values, original_value);
            
            if (literal_t__is_variable(new_value)) {
                if (literal_t__is_negation(new_value)) {
                    __TRACE_ASSIGN_LITERAL;
                    ca_flags_negate(flags, new_clause_size);
                    literal_t__unnegate(new_value);
                    result = erChangedV;
                } else if (new_value != original_value) {
                    __TRACE_ASSIGN_LITERAL;
                    result = erChangedV;
                };
                new_literals[new_clause_size] = new_value;
                ca_insert_last_literal_sorted(flags, new_clause_size, new_literals);
            } else { // is_constant
                __TRACE_ASSIGN_LITERAL;
                new_literals[new_clause_size] = new_value;
                __reduce_clause_flags(flags, new_clause_size, new_value);
                if (result == erUndetermined) {
                    result = erChangedC;
                };
            };
        };
        // save new clause size and flags
        _clause_header_set(p_dst, flags, new_clause_size);
        return (flags != 0) ? result : erSatisfied;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
andl $0x7fff, %ecx           # imm = 0x7FFF
movw %cx, -0x1e(%rbp)
movq -0x10(%rbp), %rcx
addq $0x4, %rcx
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
shrl $0x10, %ecx
movw %cx, -0x2a(%rbp)
movq 0xb8(%rax), %rdi
callq 0x10310
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movw $0x0, -0x42(%rbp)
movzwl -0x1e(%rbp), %eax
cmpl $0x4, %eax
jg 0x18125
jmp 0x18144
leaq 0x464df(%rip), %rdi     # 0x5e60b
leaq 0x45de1(%rip), %rsi     # 0x5df14
movl $0x101, %edx            # imm = 0x101
leaq 0x463d0(%rip), %rcx     # 0x5e50f
callq 0xd1c0
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %ecx
movzwl -0x1e(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x51(%rbp)
jge 0x18168
movzwl -0x2a(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x18174
jmp 0x183c7
movq -0x28(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x4c(%rbp)
movb %al, -0x52(%rbp)
jbe 0x18197
cmpl $-0x2, -0x4c(%rbp)
setbe %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x53(%rbp)
jne 0x181a6
jmp 0x181b7
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
movb %al, -0x53(%rbp)
movb -0x53(%rbp), %al
testb $0x1, %al
jne 0x181c0
jmp 0x181c2
jmp 0x181e1
leaq 0x463bf(%rip), %rdi     # 0x5e588
leaq 0x45d44(%rip), %rsi     # 0x5df14
movl $0x105, %edx            # imm = 0x105
leaq 0x46333(%rip), %rcx     # 0x5e50f
callq 0xd1c0
movq -0x38(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x12cc0
movl %eax, -0x50(%rbp)
xorl %eax, %eax
cmpl $0x1, -0x50(%rbp)
movb %al, -0x54(%rbp)
jbe 0x18205
cmpl $-0x2, -0x50(%rbp)
setbe %al
movb %al, -0x54(%rbp)
movb -0x54(%rbp), %al
testb $0x1, %al
jne 0x18211
jmp 0x1832a
movl -0x50(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x18298
leaq 0x6b16d(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x18279
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1825c
leaq 0x6b150(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
movl -0x50(%rbp), %edx
xorl $0x1, %edx
movq (%rdi), %rax
callq *0x48(%rax)
jmp 0x18277
leaq 0x6b12d(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movl -0x4c(%rbp), %esi
movl -0x50(%rbp), %edx
movq (%rdi), %rax
callq *0x48(%rax)
jmp 0x18279
leaq -0x2a(%rbp), %rdi
movzwl -0x42(%rbp), %esi
callq 0x187e0
movl -0x50(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x50(%rbp)
movl $0x2, -0x1c(%rbp)
jmp 0x18306
movl -0x50(%rbp), %eax
cmpl -0x4c(%rbp), %eax
je 0x18304
leaq 0x6b0e9(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x182fd
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x182e0
leaq 0x6b0cc(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
movl -0x50(%rbp), %edx
xorl $0x1, %edx
movq (%rdi), %rax
callq *0x48(%rax)
jmp 0x182fb
leaq 0x6b0a9(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movl -0x4c(%rbp), %esi
movl -0x50(%rbp), %edx
movq (%rdi), %rax
callq *0x48(%rax)
jmp 0x182fd
movl $0x2, -0x1c(%rbp)
jmp 0x18306
movl -0x50(%rbp), %edx
movq -0x40(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rdx
leaq -0x2a(%rbp), %rdi
leaq -0x42(%rbp), %rsi
callq 0x18860
jmp 0x183b7
leaq 0x6b05f(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x18387
movl -0x4c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x1836a
leaq 0x6b042(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
movl -0x50(%rbp), %edx
xorl $0x1, %edx
movq (%rdi), %rax
callq *0x48(%rax)
jmp 0x18385
leaq 0x6b01f(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movl -0x4c(%rbp), %esi
movl -0x50(%rbp), %edx
movq (%rdi), %rax
callq *0x48(%rax)
jmp 0x18387
movl -0x50(%rbp), %edx
movq -0x40(%rbp), %rax
movzwl -0x42(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movw -0x42(%rbp), %ax
movl -0x50(%rbp), %edx
leaq -0x2a(%rbp), %rdi
movzwl %ax, %esi
callq 0x18e50
cmpl $0x0, -0x1c(%rbp)
jne 0x183b5
movl $0x1, -0x1c(%rbp)
jmp 0x183b7
jmp 0x183b9
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1814b
movzwl -0x2a(%rbp), %ecx
shll $0x10, %ecx
movzwl -0x42(%rbp), %eax
orl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movzwl -0x2a(%rbp), %eax
cmpl $0x0, %eax
je 0x183eb
movl -0x1c(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x183f5
movl $0x3, %eax
movl %eax, -0x58(%rbp)
jmp 0x183f5
movl -0x58(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop