// File: /workspace/github_cpp_makefile_star2_O3/Myyura[P]MyyuraSat/./source/./solver_basic.cpp
// Function: MyyuraSat::Solver::_add_clause(MyyuraSat::Vector<MyyuraSat::Literal, int>&)
bool Solver::_add_clause(Vector<Literal>& ps) {
    if (decision_level() != 0) {
        throw std::logic_error("Solver::_add_clause : decision level is not 0");
    }

    std::sort(ps.begin(), ps.end());

    // Check if clause is satisfied and remove false/duplicate literals
    // Bug here ？
    Literal p;
    int i, j;
    for (i = j = 0, p = LITERAL_UNDEF; i < ps.size(); i++) {
        if (value(ps[i]) == LIFTED_BOOLEAN_TRUE || ps[i] == ~p) {
            return true;
        } else if (value(ps[i]) != LIFTED_BOOLEAN_FALSE && ps[i] != p) {
            ps[j++] = p = ps[i];
        }
    }
    ps.shrink(i - j);

    if (ps.size() == 0) {
        return _myyura = false;
    } else if (ps.size() == 1) {
        unchecked_enqueue(ps[0]);
        return _myyura = (propagate() == CRAREF_UNDEF);
    } else {
        CRARef cr = _ca.alloc(ps, false);

        /**
         * Subsumption
         * 
         * TODO : a flag to off
         */
        if (is_subsumed(cr)) {
            _ca.free(cr);
            /**
             * After all clauses are added, function check_garbage will be 
             * called.
             */

            return false;
        }

        _clauses.push(cr);
        attach_clause_watcher(cr);

        // Occurence list for literal
        attach_clause_occlit(cr);
    }

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x0, 0x40(%rdi)
jne 0x2bae
movq %rsi, %r14
movq %rdi, %rbx
movslq 0x8(%rsi), %rax
xorl %r15d, %r15d
testq %rax, %rax
je 0x2ad1
movq (%r14), %r12
leaq (%r12,%rax,4), %r13
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x6dba
movq %r12, %rdi
movq %r13, %rsi
callq 0x6e93
cmpl $0x0, 0x8(%r14)
jle 0x2ad1
movq %rbx, %rax
movl 0x9785(%rip), %ebx      # 0xc16c
movq %rax, -0x38(%rbp)
leaq 0x58(%rax), %r13
xorl %r15d, %r15d
movl $0x0, -0x2c(%rbp)
movq %r13, -0x40(%rbp)
movq (%r14), %rax
movl (%rax,%r15,4), %r12d
movl %r12d, %esi
sarl %esi
movq %r13, %rdi
callq 0x6abc
movb (%rax), %al
andb $0x1, %r12b
xorb %al, %r12b
movb 0x9753(%rip), %dil      # 0xc174
xorl %edx, %edx
movl %edi, %ecx
andb $0x2, %cl
sete %sil
cmpb %dil, %r12b
je 0x2a35
xorl %edx, %edx
jmp 0x2a38
movb %sil, %dl
andb %al, %cl
movb $0x1, %r13b
orb %cl, %dl
jne 0x2b9c
movq (%r14), %rax
movl (%rax,%r15,4), %r12d
movl %r12d, %eax
xorl %ebx, %eax
cmpl $0x1, %eax
je 0x2b9c
movl %r12d, %esi
sarl %esi
movq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x6abc
movb (%rax), %al
andb $0x1, %r12b
xorb %al, %r12b
movb 0x96fa(%rip), %dil      # 0xc175
xorl %edx, %edx
movl %edi, %ecx
andb $0x2, %cl
sete %sil
cmpb %dil, %r12b
je 0x2a8f
xorl %edx, %edx
jmp 0x2a92
movb %sil, %dl
andb %al, %cl
orb %cl, %dl
jne 0x2aa3
movq (%r14), %rcx
movl (%rcx,%r15,4), %eax
cmpl %ebx, %eax
jne 0x2ab9
movl %ebx, %eax
incq %r15
movslq 0x8(%r14), %rcx
movl %eax, %ebx
cmpq %rcx, %r15
jl 0x29fd
jmp 0x2ac9
movl -0x2c(%rbp), %esi
movslq %esi, %rdx
incl %esi
movl %esi, -0x2c(%rbp)
movl %eax, (%rcx,%rdx,4)
jmp 0x2aa5
subl -0x2c(%rbp), %r15d
movq -0x38(%rbp), %rbx
movq %r14, %rdi
movl %r15d, %esi
callq 0x5a2c
movl 0x8(%r14), %eax
cmpl $0x1, %eax
je 0x2af8
testl %eax, %eax
jne 0x2b22
movb $0x0, 0x188(%rbx)
xorl %r13d, %r13d
jmp 0x2b9c
movq (%r14), %rax
movl (%rax), %esi
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2bf4
movq %rbx, %rdi
callq 0x2ce0
cmpl $-0x1, %eax
sete %r13b
sete 0x188(%rbx)
jmp 0x2b9c
leaq 0xf8(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x5a8c
movl %eax, %r14d
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
movl %eax, %esi
callq 0x3064
movl %eax, %r13d
testb %al, %al
je 0x2b6d
movq %r15, %rdi
movl %r14d, %esi
callq 0x687e
movl (%rax), %eax
movl %eax, %ecx
shrl $0x5, %ecx
incl %ecx
btl $0x3, %eax
adcl %ecx, 0x108(%rbx)
jmp 0x2b98
leaq 0x8(%rbx), %rdi
leaq -0x30(%rbp), %r14
movq %r14, %rsi
callq 0x5ae8
movl (%r14), %esi
movq %rbx, %rdi
callq 0x3140
movl (%r14), %esi
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x31ca
xorb $0x1, %r13b
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x20a0
movq %rax, %rbx
leaq 0x54c3(%rip), %rsi      # 0x8085
movq %rax, %rdi
callq 0x21d0
movq 0x9407(%rip), %rsi      # 0xbfd8
movq 0x93b8(%rip), %rdx      # 0xbf90
movq %rbx, %rdi
callq 0x2250
movq %rax, %r14
movq %rbx, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x2270
nop