// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movq %rdi, %rbx
movq %rsi, 0x10(%rsp)
movl $0x0, 0x18(%rsi)
cmpb $0x1, 0xa4(%rdi)
jne 0x9277
movq 0x7d9c(%rip), %r15      # 0x10fd0
leaq 0x4b71(%rip), %rsi      # 0xddac
movl $0x12, %edx
movq %r15, %rdi
callq 0x2270
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
callq 0x6f0c
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x9292
movq %r14, (%rsi)
movq 0x20(%rbx), %rsi
addq $0x8, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x92a4
leaq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rdx
callq 0xbc1e
movq 0x20(%rbx), %rsi
subq 0x18(%rbx), %rsi
shrq $0x3, %rsi
decl %esi
movl %esi, 0xc(%rsp)
movq 0x10(%rsp), %rax
cmpb $0x1, 0xa5(%rbx)
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
jne 0x931b
movslq 0x20(%rax), %rcx
movq (%rbx), %rdx
movq (%rdx,%rcx,8), %rdi
movl 0x24(%rax), %edx
movzbl 0x28(%rax), %ecx
callq 0x7558
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
imulq %r15, %rcx
cmpq $0x2, %rcx
jb 0x931b
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 0x7558
movq 0x10(%rsp), %rax
movq (%rax), %rcx
cmpq %rcx, 0x8(%rax)
je 0x9442
xorl %r12d, %r12d
movsd 0x496d(%rip), %xmm1     # 0xdca0
leaq (%r12,%r12,2), %rax
movslq (%rcx,%rax,4), %rbp
movslq 0x4(%rcx,%rax,4), %r13
movb 0x8(%rcx,%rax,4), %r14b
cmpb $0x0, 0xa5(%rbx)
jne 0x93a0
movq (%rbx), %rax
movq (%rax,%rbp,8), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
testb $0x1, %r14b
je 0x936c
movq 0x60(%rax), %rax
jmp 0x9370
movq 0x68(%rax), %rax
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x938e
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x93a0
leaq 0xc(%rsp), %rdx
callq 0x54e4
movsd 0x4900(%rip), %xmm1     # 0xdca0
movl 0xa8(%rbx), %eax
cmpl $0x3, %eax
je 0x93c7
cmpl $0x1, %eax
jne 0x93ec
movq (%rbx), %rcx
movq (%rcx,%rbp,8), %rcx
testb $0x1, %r14b
jne 0x93d4
shlq $0x3, %r13
addq 0x40(%rcx), %r13
jmp 0x93dc
movq (%rbx), %rcx
movq (%rcx,%rbp,8), %rcx
testb $0x1, %r14b
je 0x9411
shlq $0x3, %r13
addq 0x38(%rcx), %r13
movsd (%r13), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%r13)
incq %r12
movq 0x10(%rsp), %rdx
movq (%rdx), %rcx
movq 0x8(%rdx), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
imulq %r15, %rdx
cmpq %r12, %rdx
ja 0x9333
jmp 0x9448
movslq 0x8(%rcx), %rdx
testq %rdx, %rdx
jle 0x93ec
movl %r13d, %esi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x9438
movq 0x38(%rcx), %r8
movsd (%r8,%rdi,8), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%r8,%rdi,8)
incq %rdi
cmpq %rdi, %rdx
jne 0x941f
jmp 0x93ec
movl 0xa8(%rbx), %eax
cmpl $0x1, %eax
jne 0x949f
movq (%rbx), %rax
xorl %ecx, %ecx
movsd 0x4856(%rip), %xmm0     # 0xdcb0
movq (%rax,%rcx,8), %rdi
movslq 0x8(%rdi), %rdx
testq %rdx, %rdx
jle 0x949a
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 0x9472
incq %rcx
jmp 0x945a
movq (%rbx), %rax
xorl %ecx, %ecx
movsd 0x4804(%rip), %xmm0     # 0xdcb0
movq (%rax,%rcx,8), %rsi
movslq 0x8(%rsi), %rdx
testq %rdx, %rdx
jle 0x94d5
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 0x94bf
incq %rcx
jmp 0x94ac