// File: 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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x68(%rsp), %rcx
movl $0x0, 0x18(%rcx)
testb $0x1, 0xa4(%rax)
je 0xf5b9
movq 0xea3c(%rip), %rdi      # 0x1dfd0
leaq 0x8761(%rip), %rsi      # 0x17cfc
callq 0x2220
movq %rax, %rdi
movq 0xea16(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x68(%rsp), %rdi
callq 0xb600
movq 0x38(%rsp), %rdi
addq $0x18, %rdi
leaq 0x68(%rsp), %rsi
callq 0x12e50
movq 0x38(%rsp), %rdi
addq $0x18, %rdi
callq 0x12f00
movq %rax, %rcx
movq 0x38(%rsp), %rax
subq $0x1, %rcx
movl %ecx, 0x64(%rsp)
testb $0x1, 0xa5(%rax)
je 0xf66d
movq 0x38(%rsp), %rdi
movq 0x68(%rsp), %rax
movslq 0x20(%rax), %rsi
callq 0xaab0
movq (%rax), %rdi
movl 0x64(%rsp), %esi
movq 0x68(%rsp), %rax
movl 0x24(%rax), %edx
movq 0x68(%rsp), %rax
movb 0x28(%rax), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0xcb10
movq 0x68(%rsp), %rdi
callq 0xb890
cmpq $0x1, %rax
jbe 0xf66b
movq 0x38(%rsp), %rdi
movq 0x68(%rsp), %rax
movslq 0x2c(%rax), %rsi
callq 0xaab0
movq (%rax), %rdi
movl 0x64(%rsp), %esi
movq 0x68(%rsp), %rax
movl 0x30(%rax), %edx
movq 0x68(%rsp), %rax
movb 0x34(%rax), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0xcb10
jmp 0xf66d
movl $0x0, 0x60(%rsp)
movslq 0x60(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x68(%rsp), %rdi
callq 0xb890
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0xf871
movq 0x68(%rsp), %rdi
movslq 0x60(%rsp), %rsi
callq 0xb8b0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq (%rcx), %rdx
movq %rdx, 0x54(%rsp)
movl 0x8(%rcx), %ecx
movl %ecx, 0x5c(%rsp)
testb $0x1, 0xa5(%rax)
jne 0xf72c
testb $0x1, 0x5c(%rsp)
je 0xf6fe
movq 0x38(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x60(%rax), %rdi
movslq 0x58(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x64(%rsp), %rsi
callq 0x6340
jmp 0xf72a
movq 0x38(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x68(%rax), %rdi
movslq 0x58(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x64(%rsp), %rsi
callq 0x6340
jmp 0xf72c
movq 0x38(%rsp), %rax
cmpl $0x1, 0xa8(%rax)
jne 0xf79f
testb $0x1, 0x5c(%rsp)
je 0xf770
movq 0x38(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x38(%rax), %rax
movslq 0x58(%rsp), %rcx
movsd 0x848c(%rip), %xmm0     # 0x17bf0
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0xf79d
movq 0x38(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x40(%rax), %rax
movslq 0x58(%rsp), %rcx
movsd 0x845d(%rip), %xmm0     # 0x17bf0
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0xf79f
movq 0x38(%rsp), %rax
cmpl $0x3, 0xa8(%rax)
jne 0xf85f
testb $0x1, 0x5c(%rsp)
je 0xf7e7
movq 0x38(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x38(%rax), %rax
movslq 0x58(%rsp), %rcx
movsd 0x8415(%rip), %xmm0     # 0x17bf0
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0xf85d
movl $0x0, 0x50(%rsp)
movq 0x38(%rsp), %rdi
movl 0x50(%rsp), %eax
movl %eax, 0x2c(%rsp)
movslq 0x54(%rsp), %rsi
callq 0xaab0
movq %rax, %rcx
movl 0x2c(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0xf85b
movl 0x50(%rsp), %eax
cmpl 0x58(%rsp), %eax
je 0xf84c
movq 0x38(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x38(%rax), %rax
movslq 0x50(%rsp), %rcx
movsd 0x83ae(%rip), %xmm0     # 0x17bf0
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0xf84e
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0xf7ef
jmp 0xf85d
jmp 0xf85f
jmp 0xf861
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xf675
movq 0x38(%rsp), %rax
cmpl $0x1, 0xa8(%rax)
jne 0xf967
movl $0x0, 0x4c(%rsp)
movq 0x38(%rsp), %rdi
movslq 0x4c(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0xaa90
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0xf962
movl $0x0, 0x48(%rsp)
movq 0x38(%rsp), %rdi
movl 0x48(%rsp), %eax
movl %eax, 0x1c(%rsp)
movslq 0x4c(%rsp), %rsi
callq 0xaab0
movq %rax, %rcx
movl 0x1c(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0xf950
movq 0x38(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xaab0
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movq 0x38(%rax), %rax
movslq 0x48(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x82f5(%rip), %xmm1     # 0x17c00
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movslq 0x4c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x40(%rax), %rax
movslq 0x48(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x82c9(%rip), %xmm1     # 0x17c00
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0xf8b8
jmp 0xf952
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xf88b
jmp 0xfa24
movq 0x38(%rsp), %rax
cmpl $0x3, 0xa8(%rax)
jne 0xfa22
movl $0x0, 0x44(%rsp)
movq 0x38(%rsp), %rdi
movslq 0x44(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0xaa90
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0xfa20
movl $0x0, 0x40(%rsp)
movq 0x38(%rsp), %rdi
movl 0x40(%rsp), %eax
movl %eax, 0xc(%rsp)
movslq 0x44(%rsp), %rsi
callq 0xaab0
movq %rax, %rcx
movl 0xc(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0xfa0e
movq 0x38(%rsp), %rdi
movslq 0x44(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x38(%rax), %rax
movslq 0x40(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x8208(%rip), %xmm1     # 0x17c00
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xf9aa
jmp 0xfa10
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xf981
jmp 0xfa22
jmp 0xfa24
ud2
nopw %cs:(%rax,%rax)