// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, %rbx
movq %rsi, 0x10(%rsp)
movl $0x0, 0x18(%rsi)
cmpb $0x1, 0xa4(%rdi)
jne 0x9318
movq 0x6cfd(%rip), %r14      # 0xffd0
leaq 0x3ad2(%rip), %rsi      # 0xcdac
movl $0x12, %edx
movq %r14, %rdi
callq 0x2270
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq 0x10(%rsp), %rdi
callq 0x6fb0
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x9331
movq 0x10(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x20(%rbx)
jmp 0x933f
leaq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rdx
callq 0xbab2
movq 0x20(%rbx), %rsi
subq 0x18(%rbx), %rsi
shrq $0x3, %rsi
decl %esi
movl %esi, 0xc(%rsp)
cmpb $0x1, 0xa5(%rbx)
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
jne 0x93b5
movq 0x10(%rsp), %rax
movslq 0x20(%rax), %rcx
movq (%rbx), %rdx
movq (%rdx,%rcx,8), %rdi
movl 0x24(%rax), %edx
movzbl 0x28(%rax), %ecx
callq 0x7604
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
imulq %r15, %rcx
cmpq $0x2, %rcx
jb 0x93b5
movslq 0x2c(%rax), %rcx
movq (%rbx), %rdx
movq (%rdx,%rcx,8), %rdi
movl 0xc(%rsp), %esi
movl 0x30(%rax), %edx
movzbl 0x34(%rax), %ecx
callq 0x7604
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x94e4
xorl %r12d, %r12d
movsd 0x38ce(%rip), %xmm1     # 0xcca0
leaq (%r12,%r12,2), %rcx
movslq (%rax,%rcx,4), %r14
movslq 0x4(%rax,%rcx,4), %r13
movb 0x8(%rax,%rcx,4), %bpl
cmpb $0x0, 0xa5(%rbx)
jne 0x943f
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
testb $0x1, %bpl
je 0x940b
movq 0x60(%rax), %rax
jmp 0x940f
movq 0x68(%rax), %rax
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x942d
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x943f
leaq 0xc(%rsp), %rdx
callq 0x5530
movsd 0x3861(%rip), %xmm1     # 0xcca0
movl 0xa8(%rbx), %eax
cmpl $0x3, %eax
je 0x946b
cmpl $0x1, %eax
jne 0x9490
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
notb %bpl
movzbl %bpl, %ecx
andl $0x1, %ecx
shlq $0x3, %r13
addq 0x38(%rax,%rcx,8), %r13
jmp 0x9480
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
testb $0x1, %bpl
je 0x94b5
shlq $0x3, %r13
addq 0x38(%rax), %r13
movsd (%r13), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%r13)
incq %r12
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
imulq %r15, %rcx
cmpq %r12, %rcx
ja 0x93d2
jmp 0x94e4
movslq 0x8(%rax), %rcx
testq %rcx, %rcx
jle 0x9490
movl %r13d, %edx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x94da
movq 0x38(%rax), %rdi
movsd (%rdi,%rsi,8), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x94c3
jmp 0x9490
cmpl $0x1, 0xa8(%rbx)
jne 0x953f
movq (%rbx), %rax
xorl %ecx, %ecx
movsd 0x37b6(%rip), %xmm0     # 0xccb0
movq (%rax,%rcx,8), %rdi
movslq 0x8(%rdi), %rdx
testq %rdx, %rdx
jle 0x953a
movq 0x38(%rdi), %rsi
movq 0x40(%rdi), %rdi
xorl %r8d, %r8d
movsd (%rsi,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rsi,%r8,8)
movsd (%rdi,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rdx
jne 0x9512
incq %rcx
jmp 0x94fa
movq (%rbx), %rax
xorl %ecx, %ecx
movsd 0x3764(%rip), %xmm0     # 0xccb0
movq (%rax,%rcx,8), %rsi
movslq 0x8(%rsi), %rdx
testq %rdx, %rdx
jle 0x9575
movq 0x38(%rsi), %rsi
xorl %edi, %edi
movsd (%rsi,%rdi,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rdx
jne 0x955f
incq %rcx
jmp 0x954c