// File: /workspace/github_cpp_makefile_star2_O1/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 0x2c03
movq %rsi, %r14
movq %rdi, -0x38(%rbp)
movslq 0x8(%rsi), %rax
testq %rax, %rax
je 0x2a29
movq (%r14), %r15
leaq (%r15,%rax,4), %r12
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x6f79
movq %r15, %rdi
movq %r12, %rsi
callq 0x7052
cmpl $0x0, 0x8(%r14)
jle 0x2b1c
movl 0xa732(%rip), %ebx      # 0xd16c
movq -0x38(%rbp), %rax
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 0x6c82
movb (%rax), %al
andb $0x1, %r12b
xorb %al, %r12b
movb 0xa700(%rip), %dil      # 0xd174
xorl %edx, %edx
movl %edi, %ecx
andb $0x2, %cl
sete %sil
cmpb %dil, %r12b
je 0x2a88
xorl %edx, %edx
jmp 0x2a8b
movb %sil, %dl
andb %al, %cl
movb $0x1, %r13b
orb %cl, %dl
jne 0x2bf1
movq (%r14), %rax
movl (%rax,%r15,4), %r12d
movl %r12d, %eax
xorl %ebx, %eax
cmpl $0x1, %eax
je 0x2bf1
movl %r12d, %esi
sarl %esi
movq -0x40(%rbp), %r13
movq %r13, %rdi
callq 0x6c82
movb (%rax), %al
andb $0x1, %r12b
xorb %al, %r12b
movb 0xa6a7(%rip), %dil      # 0xd175
xorl %edx, %edx
movl %edi, %ecx
andb $0x2, %cl
sete %sil
cmpb %dil, %r12b
je 0x2ae2
xorl %edx, %edx
jmp 0x2ae5
movb %sil, %dl
andb %al, %cl
orb %cl, %dl
jne 0x2af6
movq (%r14), %rcx
movl (%rcx,%r15,4), %eax
cmpl %ebx, %eax
jne 0x2b0c
movl %ebx, %eax
incq %r15
movslq 0x8(%r14), %rcx
movl %eax, %ebx
cmpq %rcx, %r15
jl 0x2a50
jmp 0x2b21
movl -0x2c(%rbp), %esi
movslq %esi, %rdx
incl %esi
movl %esi, -0x2c(%rbp)
movl %eax, (%rcx,%rdx,4)
jmp 0x2af8
xorl %r15d, %r15d
jmp 0x2b25
subl -0x2c(%rbp), %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x5bc0
movl 0x8(%r14), %eax
cmpl $0x1, %eax
movq -0x38(%rbp), %rbx
je 0x2b50
testl %eax, %eax
jne 0x2b7a
movb $0x0, 0x188(%rbx)
xorl %r13d, %r13d
jmp 0x2bf1
movq (%r14), %rax
movl (%rax), %esi
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2c48
movq %rbx, %rdi
callq 0x2d3a
cmpl $-0x1, %eax
sete %r13b
sete 0x188(%rbx)
jmp 0x2bf1
leaq 0xf8(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x5c1e
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
movl %eax, %esi
callq 0x30be
movl %eax, %r13d
testb %al, %al
je 0x2bc2
movl -0x30(%rbp), %esi
movq %r15, %rdi
callq 0x6a4e
movl (%rax), %eax
movl %eax, %ecx
shrl $0x5, %ecx
incl %ecx
btl $0x3, %eax
adcl %ecx, 0x108(%rbx)
jmp 0x2bed
leaq 0x8(%rbx), %rdi
leaq -0x30(%rbp), %r14
movq %r14, %rsi
callq 0x5c7a
movl (%r14), %esi
movq %rbx, %rdi
callq 0x31a4
movl (%r14), %esi
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x322e
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 0x646e(%rip), %rsi      # 0x9085
movq %rax, %rdi
callq 0x21d0
movq 0xa3b2(%rip), %rsi      # 0xcfd8
movq 0xa363(%rip), %rdx      # 0xcf90
movq %rbx, %rdi
callq 0x2250
movq %rax, %r14
movq %rbx, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x2270