// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b92
movsd %xmm0, 0x40(%rbx)
subsd 0x38(%rbx), %xmm0
cvtsi2sdl 0x30(%rbx), %xmm1
movl $0x1, %r12d
ucomisd %xmm1, %xmm0
ja 0xb96a
leaq 0x60(%rbx), %r14
cmpq %r14, 0x60(%rbx)
je 0xb77c
movq %rbx, %rdi
callq 0xb66e
callq 0x2b92
movsd %xmm0, 0x40(%rbx)
subsd 0x38(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x30(%rbx), %xmm1
ucomisd %xmm1, %xmm0
ja 0xb96a
cmpb $0x1, 0x7c(%rbx)
jne 0xb7cd
incl 0x4c(%rbx)
movb $0x0, 0x7c(%rbx)
movl 0x48(%rbx), %esi
decl %esi
movq %rbx, %rdi
callq 0x95aa
movq %r14, %rdi
callq 0xbab2
decl 0x48(%rbx)
movl $0x2, %r12d
jmp 0xb96a
movl 0xa8(%rbx), %eax
xorl %r12d, %r12d
cmpl $0x2, %eax
je 0xb7ed
testl %eax, %eax
jne 0xb96a
movq %rbx, %rdi
callq 0x814c
jmp 0xb7f5
movq %rbx, %rdi
callq 0xab80
movq %rax, %r14
movl %edx, %ebp
cmpl $-0x1, %r14d
je 0xb96a
incl 0x50(%rbx)
incl 0x48(%rbx)
cmpb $0x0, 0xa4(%rbx)
je 0xb8a0
movq 0x57b2(%rip), %r15      # 0x10fd0
leaq 0x2696(%rip), %rsi      # 0xdebb
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, %r15
shrq $0x20, %r15
movq %rax, %rdi
movl %r15d, %esi
callq 0x2390
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
jmp 0xb8a7
movq %r14, %r15
shrq $0x20, %r15
movzbl %bpl, %edx
andl $0x1, %edx
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %ecx
callq 0x833c
movl 0x48(%rbx), %esi
movq %rbx, %rdi
callq 0xb734
movl %eax, %r12d
cmpl $0x2, %eax
jb 0xb96a
cmpl $0x0, 0x48(%rbx)
js 0xb7c2
cmpb $0x1, 0xa4(%rbx)
jne 0xb944
movq 0x56e3(%rip), %r12      # 0x10fd0
leaq 0x25d2(%rip), %rsi      # 0xdec6
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 0x833c
movl 0x48(%rbx), %esi
movq %rbx, %rdi
callq 0xb734
movl %eax, %r12d
movl %r12d, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq