// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %rax
cmpl $0x0, 0x40(%rdi)
jne 0x2963
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rdi
movslq 0x8(%rsi), %rax
leaq (%rdi,%rax,4), %rsi
callq 0x6158
xorl %r15d, %r15d
movl 0xa952(%rip), %r13d     # 0xd15c
xorl %r12d, %r12d
movslq 0x8(%r14), %rax
cmpq %rax, %r15
jge 0x28aa
movq (%r14), %rax
movl (%rax,%r15,4), %esi
movq %rbx, %rdi
callq 0x4a5c
movb %al, -0x2a(%rbp)
leaq -0x2a(%rbp), %rdi
leaq 0xa92d(%rip), %rsi      # 0xd164
callq 0x4a7e
testb %al, %al
jne 0x2895
movq (%r14), %rax
movl (%rax,%r15,4), %esi
movl %esi, %eax
xorl %r13d, %eax
cmpl $0x1, %eax
je 0x2895
movq %rbx, %rdi
callq 0x4a5c
movb %al, -0x29(%rbp)
leaq -0x29(%rbp), %rdi
leaq 0xa8fe(%rip), %rsi      # 0xd165
callq 0x4aa8
testb %al, %al
je 0x287c
movq (%r14), %rcx
movl (%rcx,%r15,4), %eax
cmpl %r13d, %eax
jne 0x2881
movl %r13d, %eax
jmp 0x288a
movslq %r12d, %rdx
incl %r12d
movl %eax, (%rcx,%rdx,4)
incq %r15
movl %eax, %r13d
jmp 0x280d
movb $0x1, %r14b
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl %r12d, %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x4ab6
movl 0x8(%r14), %eax
cmpl $0x1, %eax
je 0x28d1
testl %eax, %eax
jne 0x28f9
movb $0x0, 0x188(%rbx)
xorl %r14d, %r14d
jmp 0x2898
movq (%r14), %rax
movl (%rax), %esi
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0x29a6
movq %rbx, %rdi
callq 0x2a72
cmpl $-0x1, %eax
sete %r14b
sete 0x188(%rbx)
jmp 0x2898
leaq 0xf8(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4b20
movl %eax, %r12d
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
movl %eax, %esi
callq 0x2cec
movl %eax, %r14d
testb %al, %al
je 0x2931
movq %r15, %rdi
movl %r12d, %esi
callq 0x4b7c
jmp 0x295a
leaq 0x8(%rbx), %rdi
leaq -0x30(%rbp), %r15
movq %r15, %rsi
callq 0x4ba2
movl (%r15), %esi
movq %rbx, %rdi
callq 0x2dc0
movl (%r15), %esi
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0x2e4a
xorb $0x1, %r14b
jmp 0x2898
pushq $0x10
popq %rdi
callq 0x20a0
movq %rax, %rbx
leaq 0x56f4(%rip), %rsi      # 0x8069
movq %rax, %rdi
callq 0x21b0
movq 0xa654(%rip), %rsi      # 0xcfd8
movq 0xa605(%rip), %rdx      # 0xcf90
movq %rbx, %rdi
callq 0x2230
movq %rax, %r14
movq %rbx, %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x2250