// File: /workspace/github_cpp_makefile_star2_O1/akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::analyzeConflict(Clause*, bool)
Clause* Formula::analyzeConflict ( Clause * clause, bool freeClauseAfterUse ) {

	/*
    First check if there is exactly one atom falsified at the current level.
    If yes, learn the clause: this way upon backtrack it becomes unit. Otherwise
    continue analyzing the conflict.
	 */

	if ( potent ( clause ) ) {
		learnClause(clause);
		return clause;
	}

	// Resolve the clause and its latest falsified literal's reason
	// Latest falsified literal in the clause:
	Literal lastFalse;
	if (WATCH)
		lastFalse = clause->WATCHED[0];
	else
		lastFalse = clause -> ATOM_LIST[maxLit ( clause )];
	int var = lastFalse . VAR;
	int val = lastFalse . VAL;


	if ( LOG ) {
		cout << "Latest falsified literal: " << endl;
		lastFalse . Print ();
		cout << "It's reason: " << endl;
		cout << VARLIST[var]-> CLAUSEID[val] << endl;
	}

	// Generate reasons for decision and entail reasons:
	Clause* reason;

	if ( VARLIST[var]-> CLAUSEID[val] == -1 ) {
		// Take literal in the decstack that falsified lastFalse
		Literal falsifier = DECSTACK[VARLIST[var]->ATOMINDEX[val]];

		// Generate the reason clause:
		reason = new Clause(2);
		reason -> addAtom ( Literal ( falsifier . VAR, '=', falsifier . VAL ) );
		reason -> addAtom ( Literal ( falsifier . VAR, '!', falsifier . VAL ) );

	} else if ( VARLIST[var] -> CLAUSEID[val] == -2 ) {

		reason = new Clause(VARLIST[var] -> DOMAINSIZE);
		for ( int i = 0; i < VARLIST[var] -> DOMAINSIZE; i++ ) {
			reason -> addAtom ( Literal ( var, '=', i ) );
		}
	} else {
		reason = (CLAUSELIST[VARLIST[var] -> CLAUSEID[val]]);
	}

	// resolve:
	Clause * resolvent = resolve ( clause, lastFalse, reason );

	if (WATCH) {
		assignWatched(resolvent);
	}


	/*
	The parameter clause is kept if analyzeConflict was called with a conflict 
	clause that is part of the formula and deleted if it was called recursively 
	with a temporary resolvent
	*/
	if (freeClauseAfterUse) {
		delete clause;
	}
	// Created reason clauses for reason -1 or -2 are deleted
	if (VARLIST[var] -> CLAUSEID[val] <0) {
		delete reason;
	}

	//cout << "Clause size: " << resolvent -> ATOM_LIST.size() << endl;

	if (LOG) {
		cout << "Resolvent:" << endl;
		resolvent -> Print();
	}
	return analyzeConflict ( resolvent, true );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r12d
movq %rsi, %rbp
movq %rdi, %rbx
callq 0x91b4
testb %al, %al
jne 0x9f2d
movq $-0x1, 0x8(%rsp)
movb $0x0, 0x10(%rsp)
cmpb $0x1, 0xa5(%rbx)
jne 0x9c39
movb 0x28(%rbp), %al
movb %al, 0x10(%rsp)
movq 0x20(%rbp), %rax
movq %rax, 0x8(%rsp)
jmp 0x9c5f
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x9f52
cltq
movq (%rbp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,4), %rdx
movq %rdx, 0x8(%rsp)
movb 0x8(%rcx,%rax,4), %al
movb %al, 0x10(%rsp)
movslq 0x8(%rsp), %r13
movslq 0xc(%rsp), %r15
cmpb $0x1, 0xa4(%rbx)
jne 0x9d44
movq %r15, %r14
movq 0x6350(%rip), %r15      # 0xffd0
leaq 0x3153(%rip), %rsi      # 0xcdda
movl $0x1a, %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
leaq 0x8(%rsp), %rdi
callq 0x70f6
leaq 0x3129(%rip), %rsi      # 0xcdf5
movl $0xd, %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 (%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x48(%rax), %rax
movl (%rax,%r14,4), %esi
movq %r15, %rdi
callq 0x2390
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r15, %rdi
movq %r14, %r15
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq (%rbx), %r14
movq (%r14,%r13,8), %rax
movq 0x48(%rax), %rcx
movslq (%rcx,%r15,4), %rcx
cmpq $-0x2, %rcx
movl %r12d, 0x14(%rsp)
movq %r15, 0x20(%rsp)
je 0x9dc8
cmpl $-0x1, %ecx
jne 0x9e32
movq 0x10(%rax), %rax
movslq (%rax,%r15,4), %rax
movq 0x88(%rbx), %rcx
leaq (%rax,%rax,2), %rax
movl (%rcx,%rax,4), %r14d
movl 0x4(%rcx,%rax,4), %r12d
movl $0x38, %edi
callq 0x2230
movq %rax, %r15
movq %rax, %rdi
movl $0x2, %esi
callq 0x6ed8
shlq $0x20, %r12
orq %r14, %r12
movq %r15, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x6f6c
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x6f6c
jmp 0x9e3a
movl $0x38, %edi
callq 0x2230
movq %rax, %r15
movq (%r14,%r13,8), %rax
movl 0x8(%rax), %esi
movq %r15, %rdi
callq 0x6ed8
movq (%rbx), %rax
movq (%rax,%r13,8), %rax
cmpl $0x0, 0x8(%rax)
jle 0x9e3a
movq %rbp, 0x18(%rsp)
movl %r13d, %r12d
xorl %ebp, %ebp
movabsq $0x100000000, %r14      # imm = 0x100000000
movq %r15, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x6f6c
incq %rbp
movq (%rbx), %rax
movq (%rax,%r13,8), %rax
movslq 0x8(%rax), %rax
addq %r14, %r12
cmpq %rax, %rbp
jl 0x9e05
movq 0x18(%rsp), %rbp
jmp 0x9e3a
movq 0x18(%rbx), %rax
movq (%rax,%rcx,8), %r15
movq 0x8(%rsp), %rdx
movl 0x10(%rsp), %ecx
movq %rbp, %rsi
movq %r15, %r8
callq 0x9026
movq %rax, %r12
cmpb $0x1, 0xa5(%rbx)
jne 0x9e65
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9fb4
testq %rbp, %rbp
sete %al
movl 0x14(%rsp), %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x9e8b
movq %rbp, %rdi
callq 0x6f4a
movl $0x38, %esi
movq %rbp, %rdi
callq 0x2240
testq %r15, %r15
je 0x9ebb
movq (%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x48(%rax), %rax
movq 0x20(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jns 0x9ebb
movq %r15, %rdi
callq 0x6f4a
movl $0x38, %esi
movq %r15, %rdi
callq 0x2240
cmpb $0x1, 0xa4(%rbx)
jne 0x9f0e
movq 0x6105(%rip), %r14      # 0xffd0
leaq 0x2f31(%rip), %rsi      # 0xce03
movl $0xa, %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 %r12, %rdi
callq 0x6fb0
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x9bec
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x92a6
jmp 0x9f3a
movq %rax, %rbx
movl $0x38, %esi
movq %r15, %rdi
callq 0x2240
movq %rbx, %rdi
callq 0x23a0