// File: 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
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x7670
cmpl $0x0, %eax
je 0x2cd8
movl $0x10, %edi
callq 0x2090
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
leaq 0xc447(%rip), %rsi      # 0xf0e7
callq 0x21a0
jmp 0x2ca7
movq -0x60(%rbp), %rdi
movq 0x13326(%rip), %rsi     # 0x15fd8
movq 0x132d7(%rip), %rdx     # 0x15f90
callq 0x2210
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x20c0
jmp 0x2f59
movq -0x18(%rbp), %rdi
callq 0x76d0
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x76f0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x7690
leaq -0x28(%rbp), %rdi
callq 0x7710
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl 0x13435(%rip), %eax     # 0x1614c
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x7720
movl %eax, %ecx
movl -0x6c(%rbp), %eax
cmpl %ecx, %eax
jge 0x2e4e
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x77a0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %esi
callq 0x7740
movb %al, -0x31(%rbp)
leaq -0x31(%rbp), %rdi
leaq 0x133f3(%rip), %rsi     # 0x16154
callq 0x77c0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x6d(%rbp)
jne 0x2d9e
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x77a0
movq %rax, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x75b0
movq -0x78(%rbp), %rdi
movl %eax, -0x3c(%rbp)
leaq -0x3c(%rbp), %rsi
callq 0x7820
movb %al, -0x6d(%rbp)
movb -0x6d(%rbp), %al
testb $0x1, %al
jne 0x2da7
jmp 0x2db0
movb $0x1, -0x1(%rbp)
jmp 0x2f4b
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x77a0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %esi
callq 0x7740
movb %al, -0x3d(%rbp)
leaq -0x3d(%rbp), %rdi
leaq 0x1337a(%rip), %rsi     # 0x16155
callq 0x7840
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x79(%rbp)
jne 0x2dee
jmp 0x2e09
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x77a0
movq %rax, %rdi
leaq -0x28(%rbp), %rsi
callq 0x7870
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x2e12
jmp 0x2e3c
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x77a0
movl (%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movl -0x30(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
callq 0x77a0
movl -0x28(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x2e3e
jmp 0x2e40
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2d1a
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
subl -0x30(%rbp), %esi
callq 0x7890
movq -0x18(%rbp), %rdi
callq 0x7720
cmpl $0x0, %eax
jne 0x2e7f
movq -0x58(%rbp), %rax
movb $0x0, 0x188(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x2f4b
movq -0x18(%rbp), %rdi
callq 0x7720
cmpl $0x1, %eax
jne 0x2ed3
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x77a0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2f70
movq -0x58(%rbp), %rdi
callq 0x30b0
movq -0x58(%rbp), %rcx
cmpl $-0x1, %eax
sete %al
movb %al, %dl
andb $0x1, %dl
movb %dl, 0x188(%rcx)
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x2f4b
movq -0x58(%rbp), %rdi
addq $0xf8, %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0x7940
movq -0x58(%rbp), %rdi
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %esi
callq 0x3560
testb $0x1, %al
jne 0x2efe
jmp 0x2f17
movq -0x58(%rbp), %rdi
addq $0xf8, %rdi
movl -0x4c(%rbp), %esi
callq 0x79e0
movb $0x0, -0x1(%rbp)
jmp 0x2f4b
movq -0x58(%rbp), %rdi
addq $0x8, %rdi
leaq -0x4c(%rbp), %rsi
callq 0x7a40
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x36d0
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x37f0
jmp 0x2f47
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x80, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x2230
nopw %cs:(%rax,%rax)