// File: vsklad[P]cgen/./bal/cnf/processor/cnfoptimizer.cpp
// Function: bal::processor_result_t bal::CnfOptimizer::resolve_ca_c2<false, (unsigned short)2, (unsigned short)0, (unsigned short)0>(unsigned int*, unsigned int*, unsigned short)
inline processor_result_t CnfOptimizer::resolve_ca_c2(uint32_t* const p_ca, uint32_t* const p_c2, const clause_flags_t ca_flags) {
        static_assert(ca_size >= 2 && ca_size <= 4, "ca_size out of bounds; p_ca must be an aggregated clause");
        static_assert(ca_index >= 0 && ca_index < ca_size, "ca_index out of bounds; p_ca must be an aggregated clause");
        static_assert(c2_index >= 0 && c2_index <= 1, "c2_index out of bounds; p_c2 must be a binary clause");
        _assert_level_0(_clause_size(p_ca) == ca_size);
        _assert_level_0(_clause_size(p_c2) == 2);
        _assert_level_0(_clause_literal(p_ca, ca_index) == _clause_literal(p_c2, c2_index));
        _assert_level_0(ca_flags != 0);
        
        // check that the clauses are unchanged
        const literalid_t* const variables = variables_.data();
        if (b_ca_master) {
            _assert_level_3(_clause_is_literal_unchanged(p_c2, c2_index, variables));
            _assert_level_3(ca_size < 1 || ca_index == 0 || _clause_is_literal_unchanged(p_ca, 0, variables));
            _assert_level_3(ca_size < 2 || ca_index == 1 || _clause_is_literal_unchanged(p_ca, 1, variables));
            _assert_level_3(ca_size < 3 || ca_index == 2 || _clause_is_literal_unchanged(p_ca, 2, variables));
            _assert_level_3(ca_size < 4 || ca_index == 3 || _clause_is_literal_unchanged(p_ca, 3, variables));
        } else {
            _assert_level_3(_clause_is_literal_unchanged(p_c2, 0, variables));
            _assert_level_3(_clause_is_literal_unchanged(p_c2, 0, variables));
            _assert_level_3(_clause_is_literal_unchanged(p_ca, ca_index, variables));
        };
        
        const bool is_clause_unchanged = b_ca_master ? (
            _clause_literal(p_c2, 1 - c2_index) == variables[literal_t__variable_id(_clause_literal(p_c2, 1 - c2_index))]
                                                  ) : (
            (ca_size < 1 || ca_index == 0 || _clause_literal(p_ca, 0) == variables[literal_t__variable_id(_clause_literal(p_ca, 0))]) &&
            (ca_size < 2 || ca_index == 1 || _clause_literal(p_ca, 1) == variables[literal_t__variable_id(_clause_literal(p_ca, 1))]) &&
            (ca_size < 3 || ca_index == 2 || _clause_literal(p_ca, 2) == variables[literal_t__variable_id(_clause_literal(p_ca, 2))]) &&
            (ca_size < 4 || ca_index == 3 || _clause_literal(p_ca, 3) == variables[literal_t__variable_id(_clause_literal(p_ca, 3))])
                                                  );
        
        if (is_clause_unchanged) {
            // determine the resolvent flags
            clause_flags_t resolvent_flags = ca_flags;
            resolve_ca_c2_flags(resolvent_flags, ca_index, c2_index, _clause_flags(p_c2));
            
            if (resolvent_flags != 0) {
                // construct the resolvent
                uint32_t resolvent[_clause_size_memory_size(ca_size)];
                clause_size_t resolvent_size = 1;
                _clause_literal(resolvent, 0) = (ca_index == 0) ? _clause_literal(p_c2, 1 - c2_index) : _clause_literal(p_ca, 0);
                for (auto i = 1; i < ca_size; i++) {
                    const literalid_t literal = (ca_index == i) ? _clause_literal(p_c2, 1 - c2_index) : _clause_literal(p_ca, i);
                    _clause_literal(resolvent, resolvent_size) = literal;
                    if (literal <= _clause_literal(resolvent, resolvent_size - 1)) {
                        ca_insert_last_literal_sorted(resolvent_flags, resolvent_size, _clause_literals(resolvent));
                    } else {
                        resolvent_size++;
                    };
                };
                
                if (resolvent_flags != 0) {
                    _clause_header_set(resolvent, resolvent_flags, resolvent_size);
                    
                    TRACE_LEVEL_NEXT;
                    TRACE_CLAUSE(b_ca_master ? p_c2 : p_ca, CONTAINER_END);
                    TRACE_LEVEL_NEXT;
                    TRACE_CLAUSE_RESOLVENT(resolvent);
                    
                    // with c2 resolution, resolvent_size < ca_size is only possible if both c2 literals are in ca
                    // which means resolution should be handled within the aggregation concept
                    _assert_level_2(resolvent_size == ca_size);
                    _assert_level_3(normalize_ca(resolvent, resolvent) == erUndetermined);
                    
                    processor_result_t result = evaluate_clause_a(resolvent);
                    
                    TRACE_LEVEL_PREV;
                    TRACE_LEVEL_PREV;
                    
                    if (result != erConflict) {
                        result = normalize_ca(b_ca_master ? p_ca : p_c2, b_ca_master ? p_ca : p_c2);
                    };
                    
                    return result;
                };
            };
        };
        return erUndetermined;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movw %cx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movw %ax, -0x22(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0x7fff, %eax           # imm = 0x7FFF
cmpl $0x2, %eax
jne 0x1cf85
jmp 0x1cfa4
leaq 0x42085(%rip), %rdi     # 0x5f011
leaq 0x40f81(%rip), %rsi     # 0x5df14
movl $0x2f1, %edx            # imm = 0x2F1
leaq 0x4209d(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x7fff, %eax           # imm = 0x7FFF
cmpl $0x2, %eax
jne 0x1cfb6
jmp 0x1cfd5
leaq 0x4215a(%rip), %rdi     # 0x5f117
leaq 0x40f50(%rip), %rsi     # 0x5df14
movl $0x2f2, %edx            # imm = 0x2F2
leaq 0x4206c(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x1cfe7
jmp 0x1d006
leaq 0x4214e(%rip), %rdi     # 0x5f13c
leaq 0x40f1f(%rip), %rsi     # 0x5df14
movl $0x2f3, %edx            # imm = 0x2F3
leaq 0x4203b(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movzwl -0x22(%rbp), %eax
cmpl $0x0, %eax
je 0x1d011
jmp 0x1d030
leaq 0x42159(%rip), %rdi     # 0x5f171
leaq 0x40ef5(%rip), %rsi     # 0x5df14
movl $0x2f4, %edx            # imm = 0x2F4
leaq 0x42011(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x58(%rbp), %rax
movq 0xb8(%rax), %rdi
callq 0x10310
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl 0x4(%rdx), %edx
shrl %edx
subl $0x1, %edx
movl %edx, %edx
cmpl (%rcx,%rdx,4), %eax
jne 0x1d064
jmp 0x1d083
leaq 0x42114(%rip), %rdi     # 0x5f17f
leaq 0x40ea2(%rip), %rsi     # 0x5df14
movl $0x2ff, %edx            # imm = 0x2FF
leaq 0x41fbe(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl 0x4(%rdx), %edx
shrl %edx
subl $0x1, %edx
movl %edx, %edx
cmpl (%rcx,%rdx,4), %eax
jne 0x1d0a3
jmp 0x1d0c2
leaq 0x420d5(%rip), %rdi     # 0x5f17f
leaq 0x40e63(%rip), %rsi     # 0x5df14
movl $0x300, %edx            # imm = 0x300
leaq 0x41f7f(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rdx
movl 0x4(%rdx), %edx
shrl %edx
subl $0x1, %edx
movl %edx, %edx
cmpl (%rcx,%rdx,4), %eax
jne 0x1d0e2
jmp 0x1d101
leaq 0x420f4(%rip), %rdi     # 0x5f1dd
leaq 0x40e24(%rip), %rsi     # 0x5df14
movl $0x301, %edx            # imm = 0x301
leaq 0x41f40(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
xorl %eax, %eax
cmpl (%rdx,%rsi,4), %ecx
movb %al, -0x59(%rbp)
jne 0x1d12d
movb $0x1, %al
movb %al, -0x59(%rbp)
jmp 0x1d12d
movb -0x59(%rbp), %al
andb $0x1, %al
movb %al, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
je 0x1d3be
movw -0x22(%rbp), %ax
movw %ax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x10, %eax
leaq -0x34(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
movzwl %ax, %ecx
callq 0x1e530
movzwl -0x34(%rbp), %eax
cmpl $0x0, %eax
je 0x1d3bc
movw $0x1, -0x42(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x1, -0x48(%rbp)
cmpl $0x2, -0x48(%rbp)
jge 0x1d200
xorl %eax, %eax
cmpl -0x48(%rbp), %eax
jne 0x1d19d
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x60(%rbp)
jmp 0x1d1ac
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movzwl -0x42(%rbp), %eax
movl %ecx, -0x3c(%rbp,%rax,4)
movl -0x4c(%rbp), %eax
movzwl -0x42(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl -0x3c(%rbp,%rcx,4), %eax
ja 0x1d1e7
leaq -0x40(%rbp), %rdx
addq $0x4, %rdx
leaq -0x34(%rbp), %rdi
leaq -0x42(%rbp), %rsi
callq 0x18860
jmp 0x1d1f3
movw -0x42(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x42(%rbp)
jmp 0x1d1f5
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1d184
movzwl -0x34(%rbp), %eax
cmpl $0x0, %eax
je 0x1d3ba
movzwl -0x34(%rbp), %eax
shll $0x10, %eax
movzwl -0x42(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x40(%rbp)
leaq 0x6616c(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x1d244
leaq 0x6615a(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movq (%rdi), %rax
callq *0x20(%rax)
leaq 0x66145(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x1d276
leaq 0x66133(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
movq (%rdi), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
callq *0x40(%rax)
leaq 0x66113(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x1d29d
leaq 0x66101(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movq (%rdi), %rax
callq *0x20(%rax)
leaq 0x660ec(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x1d2d2
leaq 0x660da(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
movq (%rdi), %rax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
callq *0x40(%rax)
movzwl -0x42(%rbp), %eax
cmpl $0x2, %eax
jne 0x1d2dd
jmp 0x1d2fc
leaq 0x41f65(%rip), %rdi     # 0x5f249
leaq 0x40c29(%rip), %rsi     # 0x5df14
movl $0x32b, %edx            # imm = 0x32B
leaq 0x41d45(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x180b0
cmpl $0x0, %eax
jne 0x1d314
jmp 0x1d333
leaq 0x41f48(%rip), %rdi     # 0x5f263
leaq 0x40bf2(%rip), %rsi     # 0x5df14
movl $0x32c, %edx            # imm = 0x32C
leaq 0x41d0e(%rip), %rcx     # 0x5f03c
callq 0xd1c0
movq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, %edx
callq 0x1b1f0
movl %eax, -0x50(%rbp)
leaq 0x6603f(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x1d371
leaq 0x6602d(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movq (%rdi), %rax
callq *0x28(%rax)
leaq 0x66018(%rip), %rdi     # 0x83390
callq 0x16210
cmpq $0x0, %rax
je 0x1d398
leaq 0x66006(%rip), %rdi     # 0x83390
callq 0x178d0
movq %rax, %rdi
movq (%rdi), %rax
callq *0x28(%rax)
cmpl $0x4, -0x50(%rbp)
je 0x1d3b2
movq -0x58(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x180b0
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1d3c5
jmp 0x1d3bc
jmp 0x1d3be
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop