// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rax
movl %esi, %r12d
movq %rdi, %r14
callq 0x2b92
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
ja 0xb651
leaq 0x60(%r14), %r15
movq 0x5d33(%rip), %rbp      # 0x10fd0
movl %r12d, 0x4(%rsp)
cmpb $0x1, 0x7c(%r14)
jne 0xb4e8
cmpb $0x1, 0xa4(%r14)
jne 0xb355
movl $0x1e, %edx
movq %rbp, %rdi
leaq 0x2b7b(%rip), %rsi      # 0xde45
callq 0x2270
movl 0x48(%r14), %esi
movq %rbp, %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 %rbp, %rdi
leaq 0x2b50(%rip), %rsi      # 0xde64
callq 0x2270
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rdi
callq 0x6f0c
cmpl $0x0, 0x48(%r14)
je 0xb667
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x9b02
movq %r14, %rdi
movq %rax, %rsi
callq 0x94da
movl %eax, 0x48(%r14)
movb 0xa4(%r14), %al
cmpb $0x1, %al
jne 0xb3e4
movl $0x22, %edx
movq %rbp, %rdi
leaq 0x2add(%rip), %rsi      # 0xde7f
callq 0x2270
movl 0x48(%r14), %esi
movq %rbp, %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
movb 0xa4(%r14), %al
movl 0x4c(%r14), %ecx
incl %ecx
movl %ecx, 0x4c(%r14)
movb $0x0, 0x7c(%r14)
testb $0x1, %al
je 0xb445
movl $0x18, %edx
movq %rbp, %rdi
leaq 0x2a9c(%rip), %rsi      # 0xdea2
callq 0x2270
movl 0x4c(%r14), %esi
movq %rbp, %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 0x4c(%r14), %ecx
cmpl 0x4(%rsp), %ecx
jne 0xb4aa
movq %r14, %rdi
xorl %esi, %esi
callq 0x95aa
movl 0x4c(%r14), %eax
addl %r12d, %eax
movl %eax, 0x4(%rsp)
incl 0xa0(%r14)
movq %r15, %rdi
callq 0xbab2
cmpl $0x0, 0x48(%r14)
jne 0xb4a0
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 0xb4e8
movl 0x48(%r14), %esi
movq %r14, %rdi
callq 0x95aa
movq %r15, %rdi
callq 0xbab2
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 0xb4f5
movq %r14, %rdi
callq 0xb66e
cmpb $0x0, 0x7c(%r14)
jne 0xb62d
movl 0xa8(%r14), %eax
xorl %ebx, %ebx
cmpq $0x3, %rax
ja 0xb656
leaq 0x279e(%rip), %rcx      # 0xdcb8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x814c
jmp 0xb549
movq %r14, %rdi
callq 0xab80
jmp 0xb549
movq %r14, %rdi
callq 0x82a6
jmp 0xb549
movq %r14, %rdi
callq 0x81e6
movq %rax, %r13
cmpl $-0x1, %r13d
je 0xb656
cmpb $0x0, 0xa4(%r14)
je 0xb603
movb %dl, 0x2(%rsp)
movl $0xa, %edx
movq %rbp, %rdi
leaq 0x2944(%rip), %rsi      # 0xdebb
callq 0x2270
movq %rbp, %rdi
movl %r13d, %esi
callq 0x2390
testb $0x1, 0x2(%rsp)
movl $0x21, %ecx
movl $0x3d, %edx
cmovnel %edx, %ecx
movb %cl, 0x3(%rsp)
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3(%rsp), %rsi
callq 0x2270
movq %r13, %rbx
shrq $0x20, %rbx
movq %rax, %rdi
movl %ebx, %esi
callq 0x2390
movq %r15, %rbp
movl %r12d, %r15d
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
movl %r15d, %r12d
movq %rbp, %r15
movq 0x59e0(%rip), %rbp      # 0x10fd0
callq 0x2040
movq %rax, %rdi
callq 0x2180
movb 0x2(%rsp), %dl
jmp 0xb60a
movq %r13, %rbx
shrq $0x20, %rbx
incl 0x50(%r14)
incl 0x48(%r14)
movl $0xffffffff, 0x78(%r14) # imm = 0xFFFFFFFF
movzbl %dl, %edx
andl $0x1, %edx
movq %r14, %rdi
movl %r13d, %esi
movl %ebx, %ecx
callq 0x833c
callq 0x2b92
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb2a2
movl $0x1, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, %ebx
jmp 0xb656