// File: /workspace/github_cpp_makefile_star2_O1/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, %ebx
movq %rdi, %r14
callq 0x2b7e
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb018
movl $0x1, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x60(%r14), %r15
movq 0x4fad(%rip), %r12      # 0xffd0
movl %ebx, 0x14(%rsp)
movl %ebx, 0x10(%rsp)
cmpb $0x1, 0x7c(%r14)
jne 0xb26a
cmpb $0x1, 0xa4(%r14)
jne 0xb0de
movl $0x1e, %edx
movq %r12, %rdi
leaq 0x1df2(%rip), %rsi      # 0xce45
callq 0x2270
movl 0x48(%r14), %esi
movq %r12, %rdi
callq 0x2390
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movl $0x14, %edx
movq %r12, %rdi
leaq 0x1dc7(%rip), %rsi      # 0xce64
callq 0x2270
movq (%r12), %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
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x6fb0
cmpl $0x0, 0x48(%r14)
je 0xb3c3
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x9bec
movq %r14, %rdi
movq %rax, %rsi
callq 0x957a
movl %eax, 0x48(%r14)
cmpb $0x1, 0xa4(%r14)
jne 0xb165
movl $0x22, %edx
movq %r12, %rdi
leaq 0x1d55(%rip), %rsi      # 0xce7f
callq 0x2270
movl 0x48(%r14), %esi
movq %r12, %rdi
callq 0x2390
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incl 0x4c(%r14)
movb $0x0, 0x7c(%r14)
cmpb $0x1, 0xa4(%r14)
jne 0xb1c2
movl $0x18, %edx
movq %r12, %rdi
leaq 0x1d1b(%rip), %rsi      # 0xcea2
callq 0x2270
movl 0x4c(%r14), %esi
movq %r12, %rdi
callq 0x2390
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movl 0x10(%rsp), %eax
cmpl %eax, 0x4c(%r14)
jne 0xb22c
movq %r14, %rdi
xorl %esi, %esi
callq 0x9656
movl 0x4c(%r14), %eax
addl 0x14(%rsp), %eax
movl %eax, 0x10(%rsp)
incl 0xa0(%r14)
movq %r15, %rdi
callq 0xb94e
cmpl $0x0, 0x48(%r14)
jne 0xb222
movq 0x20(%r14), %rbx
subq 0x18(%r14), %rbx
shrq $0x3, %rbx
decl %ebx
movl $0x18, %edi
callq 0x2230
movl %ebx, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2070
incq 0x70(%r14)
movl $0x0, 0x48(%r14)
jmp 0xb26a
movl 0x48(%r14), %esi
movq %r14, %rdi
callq 0x9656
movq %r15, %rdi
callq 0xb94e
movq 0x20(%r14), %rbx
subq 0x18(%r14), %rbx
shrq $0x3, %rbx
decl %ebx
movl $0x18, %edi
callq 0x2230
movl %ebx, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2070
incq 0x70(%r14)
cmpq %r15, (%r15)
je 0xb277
movq %r14, %rdi
callq 0xb3ce
cmpb $0x0, 0x7c(%r14)
jne 0xb38c
movl 0xa8(%r14), %eax
xorl %ebx, %ebx
cmpq $0x3, %rax
ja 0xb3b5
leaq 0x1a1c(%rip), %rcx      # 0xccb8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x8224
jmp 0xb2cb
movq %r14, %rdi
callq 0xa848
jmp 0xb2cb
movq %r14, %rdi
callq 0x837e
jmp 0xb2cb
movq %r14, %rdi
callq 0x82be
movq %rax, %r13
movl %edx, %ebp
cmpl $-0x1, %r13d
je 0xb007
cmpb $0x1, 0xa4(%r14)
jne 0xb363
movl $0xa, %edx
movq %r12, %rdi
leaq 0x1bc8(%rip), %rsi      # 0xcebb
callq 0x2270
movq %r12, %rdi
movl %r13d, %esi
callq 0x2390
testb $0x1, %bpl
movl $0x21, %ecx
movl $0x3d, %edx
cmovnel %edx, %ecx
movb %cl, 0xf(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2270
movq %r13, %rsi
shrq $0x20, %rsi
movq %rax, %rdi
callq 0x2390
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incl 0x50(%r14)
incl 0x48(%r14)
movl $0xffffffff, 0x78(%r14) # imm = 0xFFFFFFFF
movq %r13, %rcx
shrq $0x20, %rcx
movzbl %bpl, %edx
andl $0x1, %edx
movq %r14, %rdi
movl %r13d, %esi
callq 0x8414
callq 0x2b7e
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb02b
jmp 0xb002
movq $-0x1, %r13
xorl %ebp, %ebp
jmp 0xb2d0
movl $0x2, %ebx
jmp 0xb007
nop