// File: /workspace/github_cpp_makefile_star2_O2/akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::learnClause(Clause*)
Clause* Formula::learnClause ( Clause * clause ) {
	// After backtracking the clause should be detected as unit
	clause -> NumUnAss = 0;

	if (LOG) {
		cout << "Learned a clause: " << endl;
		clause->Print();
	}
	// add the clause to the clause list
	CLAUSELIST.push_back( clause );
	// it's id
	int cid = CLAUSELIST.size()-1;
	// add clause id to watched lists
	if (WATCH) {
		VARLIST[clause->WATCHED[0].VAR]->addRecord(cid, clause->WATCHED[0].VAL, clause->WATCHED[0].EQUAL);
		if (clause->ATOM_LIST.size()>1)
			VARLIST[clause->WATCHED[1].VAR]->addRecord(cid, clause->WATCHED[1].VAL, clause->WATCHED[1].EQUAL);
	}
	// update global records for each atom in the clause
	for ( int i = 0; i < clause -> ATOM_LIST.size(); i++ ) {
		Literal atom = clause->ATOM_LIST[i];

		if (!WATCH)
			if (atom.EQUAL)
				VARLIST[atom.VAR]->ATOMRECPOS[atom.VAL].push_back(cid);
			else
				VARLIST[atom.VAR]->ATOMRECNEG[atom.VAL].push_back(cid);


		if ( heuristic==Heuristic::VSIDS ) {
			if (atom.EQUAL) {
				VARLIST[atom.VAR]->VSIDS_SCORE[atom.VAL]++;
			} else {
				VARLIST[atom.VAR]->VSIDS_SCORE_NEG[atom.VAL]++;
			}
		}
		if ( heuristic==Heuristic::VSIDS_pos ) {
			if (atom.EQUAL) {
				VARLIST[atom.VAR]->VSIDS_SCORE[atom.VAL]++;
			} else {
				for (int j=0;j<VARLIST[atom.VAR] -> DOMAINSIZE;j++) {
					if (j!=atom.VAL)
						VARLIST[atom.VAR]->VSIDS_SCORE[j]++;
				}
			}
		}
	}

	if ( heuristic==Heuristic::VSIDS ) {
		for ( int i = 0; i < VARLIST.size(); i++ ) {
			for ( int j = 0; j < VARLIST[i] -> DOMAINSIZE; j++ ) {
				VARLIST[i] -> VSIDS_SCORE[j] /= 2;
				VARLIST[i] -> VSIDS_SCORE_NEG[j] /= 2;
			}
		}
	}
	else if ( heuristic==Heuristic::VSIDS_pos ) {
		for ( int i = 0; i < VARLIST.size(); i++ ) {
			for ( int j = 0; j < VARLIST[i] -> DOMAINSIZE; j++ ) {
				VARLIST[i] -> VSIDS_SCORE[j] /= 2;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, 0x8(%rsp)
andl $0x0, 0x18(%rsi)
movq %rdi, %rbx
cmpb $0x1, 0xa4(%rdi)
jne 0x711f
movq %rsi, %r14
movq 0x7ecd(%rip), %rdi      # 0xefd0
leaq 0x3c12(%rip), %rsi      # 0xad1c
callq 0x2210
movq %rax, %rdi
callq 0x2140
movq %r14, %rdi
callq 0x5814
leaq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8b86
movq 0x20(%rbx), %r14
subq 0x18(%rbx), %r14
shrq $0x3, %r14
decl %r14d
movl %r14d, 0x14(%rsp)
cmpb $0x1, 0xa5(%rbx)
pushq $0xc
popq %r15
jne 0x719e
movq 0x8(%rsp), %rax
movslq 0x20(%rax), %rcx
movq (%rbx), %rdx
movq (%rdx,%rcx,8), %rdi
movl 0x24(%rax), %edx
movzbl 0x28(%rax), %ecx
movl %r14d, %esi
callq 0x5e1a
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
idivq %r15
cmpq $0x2, %rax
jb 0x719e
movslq 0x2c(%rcx), %rax
movq (%rbx), %rdx
movq (%rdx,%rax,8), %rdi
movl 0x30(%rcx), %edx
movzbl 0x34(%rcx), %ecx
movl %r14d, %esi
callq 0x5e1a
movsd 0x3a6a(%rip), %xmm1     # 0xac10
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
subq %rcx, %rax
cqto
idivq %r15
cmpq %r13, %rax
jbe 0x7292
imulq $0xc, %r13, %rax
movslq (%rcx,%rax), %r12
movslq 0x4(%rcx,%rax), %rbp
movb 0x8(%rcx,%rax), %r14b
cmpb $0x0, 0xa5(%rbx)
jne 0x720e
movq (%rbx), %rax
movq (%rax,%r12,8), %rax
movl %r14d, %ecx
notb %cl
movzbl %cl, %ecx
andl $0x1, %ecx
imulq $0x18, %rbp, %rdi
addq 0x60(%rax,%rcx,8), %rdi
leaq 0x14(%rsp), %rsi
callq 0x4170
movsd 0x3a02(%rip), %xmm1     # 0xac10
movl 0xa8(%rbx), %eax
cmpl $0x3, %eax
je 0x7235
cmpl $0x1, %eax
jne 0x7258
movq (%rbx), %rax
movq (%rax,%r12,8), %rax
testb $0x1, %r14b
jne 0x7242
shlq $0x3, %rbp
addq 0x40(%rax), %rbp
jmp 0x724a
movq (%rbx), %rax
movq (%rax,%r12,8), %rax
testb $0x1, %r14b
je 0x7260
shlq $0x3, %rbp
addq 0x38(%rax), %rbp
movsd (%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rbp)
incq %r13
jmp 0x71a9
movl 0x8(%rax), %ecx
movl %ebp, %edx
testl %ecx, %ecx
movl $0x0, %esi
cmovlel %esi, %ecx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x7258
cmpq %rsi, %rdx
je 0x728d
movq 0x38(%rax), %rdi
movsd (%rdi,%rsi,8), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
jmp 0x7271
cmpl $0x1, 0xa8(%rbx)
jne 0x72f0
movq (%rbx), %rax
xorl %ecx, %ecx
movsd 0x3978(%rip), %xmm0     # 0xac20
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movl 0x8(%rsi), %edi
testl %edi, %edi
cmovlel %ecx, %edi
xorl %r8d, %r8d
cmpq %r8, %rdi
je 0x72eb
movq 0x38(%rsi), %r9
movsd (%r9,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r9,%r8,8)
movq 0x40(%rsi), %r9
movsd (%r9,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r9,%r8,8)
incq %r8
jmp 0x72b9
incq %rdx
jmp 0x72aa
movq (%rbx), %rax
xorl %ecx, %ecx
movsd 0x3923(%rip), %xmm0     # 0xac20
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movl 0x8(%rsi), %edi
testl %edi, %edi
cmovlel %ecx, %edi
xorl %r8d, %r8d
cmpq %r8, %rdi
je 0x732c
movq 0x38(%rsi), %r9
movsd (%r9,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%r9,%r8,8)
incq %r8
jmp 0x730e
incq %rdx
jmp 0x72ff
nop