// File: /workspace/github_cpp_makefile_star2_O1/akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::ChronoBacktrack(int)
int Formula::ChronoBacktrack(int level)
{
	//start of finite domain extended dpll
	// return 0 : if theory satisfied
	// return 1 : if time out
	// return 2 : if conflict and later used as unsatisfied

	//set LEVEL
	LEVEL = level;

	//check if time out
	TIME_E = GetTime();
	if((TIME_E - TIME_S) > TIMELIMIT)
		return 1;

	//check unit literal
	if(!UNITLIST.empty())
		unitPropagation();

	//check if time out
	TIME_E = GetTime();
	if((TIME_E - TIME_S) > TIMELIMIT)
		return 1;

	//check if conflict
	if(CONFLICT)
	{
		BACKTRACKS++;
		CONFLICT = false;
		undoTheory(LEVEL-1);
		UNITLIST.clear();
		LEVEL = LEVEL-1;
		return 2;
	}

	//since all is fine, now need to choose a literal
	//to branch on
	Literal atom;

	switch(heuristic) {
		case Heuristic::BK  : atom = chooseLiteral (); break;
		case Heuristic::lazy  : atom = lazyChooseLiteral (); break;
	}

	if(atom.VAR != -1)
	{
		DECISIONS++;
		LEVEL++;
		if (LOG) cout << "Decision: " << atom . VAR << ( atom . EQUAL ? '=' : '!' ) << atom . VAL << endl;
		reduceTheory(atom.VAR, atom.EQUAL, atom.VAL);
		int result = ChronoBacktrack(LEVEL);
		if(result == 0)
			return 0;
		else if(result == 1)
			return 1;
		else if((result == 2) && (LEVEL >= 0))
		{
			if (LOG) cout << "Conflict: Propagating " << atom . VAR << ( !atom . EQUAL ? '=' : '!' ) << atom . VAL << endl;
			reduceTheory(atom.VAR, !atom.EQUAL, atom.VAL);
			return ChronoBacktrack(LEVEL);
		}
		else
			return 2;
	}
	else
	{
		// The theory is satisfied if all variables are assigned and there is no conflict
		return 0;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl %esi, 0x48(%rdi)
callq 0x2b7e
movsd %xmm0, 0x40(%rbx)
subsd 0x38(%rbx), %xmm0
cvtsi2sdl 0x30(%rbx), %xmm1
movl $0x1, %r12d
ucomisd %xmm1, %xmm0
ja 0xb6ce
leaq 0x60(%rbx), %r14
cmpq %r14, 0x60(%rbx)
je 0xb4dc
movq %rbx, %rdi
callq 0xb3ce
callq 0x2b7e
movsd %xmm0, 0x40(%rbx)
subsd 0x38(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x30(%rbx), %xmm1
ucomisd %xmm1, %xmm0
ja 0xb6ce
cmpb $0x1, 0x7c(%rbx)
jne 0xb52d
incl 0x4c(%rbx)
movb $0x0, 0x7c(%rbx)
movl 0x48(%rbx), %esi
decl %esi
movq %rbx, %rdi
callq 0x9656
movq %r14, %rdi
callq 0xb94e
decl 0x48(%rbx)
movl $0x2, %r12d
jmp 0xb6ce
movl 0xa8(%rbx), %eax
cmpl $0x2, %eax
je 0xb546
testl %eax, %eax
jne 0xb555
movq %rbx, %rdi
callq 0x8224
jmp 0xb54e
movq %rbx, %rdi
callq 0xa848
movq %rax, %r14
movl %edx, %ebp
jmp 0xb55e
movq $-0x1, %r14
xorl %ebp, %ebp
cmpl $-0x1, %r14d
je 0xb6cb
incl 0x50(%rbx)
incl 0x48(%rbx)
cmpb $0x1, 0xa4(%rbx)
jne 0xb5ff
movq 0x4a4e(%rip), %r15      # 0xffd0
leaq 0x1932(%rip), %rsi      # 0xcebb
movl $0xa, %edx
movq %r15, %rdi
callq 0x2270
movq %r15, %rdi
movl %r14d, %esi
callq 0x2390
testb $0x1, %bpl
movl $0x3d, %ecx
movl $0x21, %edx
cmovnel %ecx, %edx
leaq 0xe(%rsp), %rsi
movb %dl, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rsi
shrq $0x20, %rsi
movq %rax, %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
callq 0x2040
movq %rax, %rdi
callq 0x2180
movq %r14, %r15
shrq $0x20, %r15
movzbl %bpl, %edx
andl $0x1, %edx
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %ecx
callq 0x8414
movl 0x48(%rbx), %esi
movq %rbx, %rdi
callq 0xb494
movl %eax, %r12d
cmpl $0x2, %eax
jb 0xb6ce
cmpl $0x0, 0x48(%rbx)
js 0xb522
cmpb $0x1, 0xa4(%rbx)
jne 0xb6a3
movq 0x4984(%rip), %r12      # 0xffd0
leaq 0x1873(%rip), %rsi      # 0xcec6
movl $0x16, %edx
movq %r12, %rdi
callq 0x2270
movq %r12, %rdi
movl %r14d, %esi
callq 0x2390
testb $0x1, %bpl
movl $0x21, %ecx
movl $0x3d, %edx
cmovnel %ecx, %edx
leaq 0xf(%rsp), %rsi
movb %dl, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq %rax, %rdi
movl %r15d, %esi
callq 0x2390
movq %rax, %rdi
callq 0x2120
notb %bpl
movzbl %bpl, %edx
andl $0x1, %edx
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %ecx
callq 0x8414
movl 0x48(%rbx), %esi
movq %rbx, %rdi
callq 0xb494
movl %eax, %r12d
jmp 0xb6ce
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq