// File: /workspace/github_cpp_makefile_star2_O2/akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::NonChronoBacktrack(int)
int Formula::NonChronoBacktrack ( int restarts ) {

	int restartCount = restarts;

	//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

	while ( true ){

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

		if ( CONFLICT ) {

			if ( LOG ) {
				cout << "There is a conflict at level: " << LEVEL << endl;
				cout << "Conflicting clause: " <<  endl;
				CLAUSELIST[CONFLICTINGCLAUSE] -> Print();
			}

			if ( LEVEL == 0 ) return 2;

			LEVEL = backtrackLevel ( analyzeConflict ( CLAUSELIST[CONFLICTINGCLAUSE], false) );

			if ( LOG ) cout << "We are backtracking to the level: " << LEVEL << endl;

			BACKTRACKS++;
			CONFLICT = false;

			if ( LOG ) cout << "# of backtracks so far: " << BACKTRACKS << endl;


			if ( BACKTRACKS == restartCount ) {
				undoTheory ( 0 );
				restartCount = BACKTRACKS + restarts;
				RESTARTS++;
				// After a restart the learned clause is the only potential unit clause
				// The learned clause is a unit clause at level 0 if the backtrack level would be 0
				UNITLIST.clear();
				if (LEVEL==0)
					UNITLIST.push_back(CLAUSELIST.size()-1);
				LEVEL = 0;
			}
			else {
				undoTheory ( LEVEL );

				//After backtracking the learned clause is the only unit clause
				UNITLIST.clear();
				UNITLIST.push_back(CLAUSELIST.size()-1);
			}
		}

		// If there is a unit clause, propagate
		if ( !UNITLIST.empty() )
			unitPropagation();

		// otherwise choose a literal and propagate
		if (!CONFLICT) {
			Literal atom;
			switch(heuristic) {
				case Heuristic::VSIDS : atom = chooseLiteralVSIDS(); break;
				case Heuristic::VSIDS_pos : atom = chooseLiteralVSIDS_allPos(); break;
				case Heuristic::BK  : atom = chooseLiteral (); break;
				case Heuristic::lazy  : atom = lazyChooseLiteral (); break;
			}

			if ( atom.VAR != -1 ) {

				if (LOG) cout << "Decision: " << atom . VAR << ( atom . EQUAL ? '=' : '!' ) << atom . VAL << endl;

				DECISIONS++;
				LEVEL++;
				UNITCLAUSE = -1; // REASON for subsequent falsified atoms

				reduceTheory ( atom . VAR, atom . EQUAL, atom . VAL);
			} else return 0;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %r12d
movq %rdi, %r14
leaq 0x60(%rdi), %r15
movl %esi, 0xc(%rsp)
callq 0x290a
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
ja 0x87cb
cmpb $0x1, 0x7c(%r14)
jne 0x86d6
cmpb $0x1, 0xa4(%r14)
jne 0x85a5
movq 0x6a79(%rip), %rbx      # 0xefd0
movq %rbx, %rdi
leaq 0x2854(%rip), %rsi      # 0xadb5
callq 0x2210
movl 0x48(%r14), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
callq 0x2140
movq %rbx, %rdi
leaq 0x2850(%rip), %rsi      # 0xadd4
callq 0x2210
movq %rax, %rdi
callq 0x2140
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x5814
cmpl $0x0, 0x48(%r14)
je 0x87cf
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x75f4
movq %r14, %rdi
movq %rax, %rsi
callq 0x7332
movl %eax, 0x48(%r14)
movb 0xa4(%r14), %al
cmpb $0x1, %al
jne 0x8611
movq 0x69e6(%rip), %rdi      # 0xefd0
leaq 0x27fe(%rip), %rsi      # 0xadef
callq 0x2210
movl 0x48(%r14), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
callq 0x2140
movb 0xa4(%r14), %al
movl 0x4c(%r14), %ecx
incl %ecx
movl %ecx, 0x4c(%r14)
movb $0x0, 0x7c(%r14)
testb $0x1, %al
je 0x864f
movq 0x69a5(%rip), %rdi      # 0xefd0
leaq 0x27e0(%rip), %rsi      # 0xae12
callq 0x2210
movl 0x4c(%r14), %esi
movq %rax, %rdi
callq 0x2380
movq %rax, %rdi
callq 0x2140
movl 0x4c(%r14), %ecx
cmpl %r12d, %ecx
jne 0x86a3
movq %r14, %rdi
xorl %esi, %esi
callq 0x73ca
movl 0x4c(%r14), %r12d
addl 0xc(%rsp), %r12d
incl 0xa0(%r14)
movq %r15, %rdi
callq 0x902c
cmpl $0x0, 0x48(%r14)
jne 0x869c
movq 0x20(%r14), %rax
subq 0x18(%r14), %rax
shrq $0x3, %rax
decl %eax
movl %eax, 0x14(%rsp)
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
callq 0x9044
andl $0x0, 0x48(%r14)
jmp 0x86d6
movl 0x48(%r14), %esi
movq %r14, %rdi
callq 0x73ca
movq %r15, %rdi
callq 0x902c
movq 0x20(%r14), %rax
subq 0x18(%r14), %rax
shrq $0x3, %rax
decl %eax
movl %eax, 0x10(%rsp)
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0x9044
cmpq %r15, (%r15)
je 0x86e3
movq %r14, %rdi
callq 0x87e4
cmpb $0x0, 0x7c(%r14)
jne 0x851a
movl 0xa8(%r14), %eax
xorl %ebx, %ebx
cmpq $0x3, %rax
ja 0x87d2
leaq 0x2520(%rip), %rcx      # 0xac28
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x6826
jmp 0x8737
movq %r14, %rdi
callq 0x7f9a
jmp 0x8737
movq %r14, %rdi
callq 0x6966
jmp 0x8737
movq %r14, %rdi
callq 0x68ba
movq %rax, %r13
movl %edx, %ebp
cmpl $-0x1, %r13d
je 0x87d2
cmpb $0x0, 0xa4(%r14)
je 0x879e
movq 0x6879(%rip), %rdi      # 0xefd0
leaq 0x26cd(%rip), %rsi      # 0xae2b
callq 0x2210
movq %rax, %rdi
movl %r13d, %esi
callq 0x2380
testb $0x1, %bpl
pushq $0x21
popq %rsi
pushq $0x3d
popq %rcx
cmovnel %ecx, %esi
movq %rax, %rdi
callq 0x2270
movq %r13, %rbx
shrq $0x20, %rbx
movq %rax, %rdi
movl %ebx, %esi
callq 0x2380
movq %rax, %rdi
callq 0x2140
jmp 0x87a5
movq %r13, %rbx
shrq $0x20, %rbx
incl 0x50(%r14)
incl 0x48(%r14)
orl $-0x1, 0x78(%r14)
movzbl %bpl, %edx
andl $0x1, %edx
movq %r14, %rdi
movl %r13d, %esi
movl %ebx, %ecx
callq 0x69ec
jmp 0x851a
pushq $0x1
jmp 0x87d1
pushq $0x2
popq %rbx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop