// File: 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:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movl %esi, 0xc4(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, 0xc0(%rsp)
callq 0x2ec0
movq 0x28(%rsp), %rax
movsd %xmm0, 0x40(%rax)
movsd 0x40(%rax), %xmm0
subsd 0x38(%rax), %xmm0
cvtsi2sdl 0x30(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x120c5
movl $0x1, 0xd4(%rsp)
jmp 0x12595
movq 0x28(%rsp), %rax
testb $0x1, 0x7c(%rax)
je 0x1232a
movq 0x28(%rsp), %rax
testb $0x1, 0xa4(%rax)
je 0x12156
movq 0xbee7(%rip), %rdi      # 0x1dfd0
leaq 0x5ca5(%rip), %rsi      # 0x17d95
callq 0x2220
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x48(%rax), %esi
callq 0x2400
movq %rax, %rdi
movq 0xbeb1(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0xbeb5(%rip), %rdi      # 0x1dfd0
leaq 0x5c92(%rip), %rsi      # 0x17db4
callq 0x2220
movq %rax, %rdi
movq 0xbe8f(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x28(%rsp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x80(%rax), %rsi
callq 0x12f20
movq (%rax), %rdi
callq 0xb600
movq 0x28(%rsp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x12171
movl $0x2, 0xd4(%rsp)
jmp 0x12595
movq 0x28(%rsp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x80(%rax), %rsi
callq 0x12f20
movq 0x28(%rsp), %rdi
movq (%rax), %rsi
xorl %edx, %edx
callq 0x10110
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0xfa30
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x48(%rax)
testb $0x1, 0xa4(%rax)
je 0x121ea
movq 0xbe11(%rip), %rdi      # 0x1dfd0
leaq 0x5c09(%rip), %rsi      # 0x17dcf
callq 0x2220
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x48(%rax), %esi
callq 0x2400
movq %rax, %rdi
movq 0xbddb(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x28(%rsp), %rax
movl 0x4c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4c(%rax)
movb $0x0, 0x7c(%rax)
testb $0x1, 0xa4(%rax)
je 0x12237
movq 0xbdc4(%rip), %rdi      # 0x1dfd0
leaq 0x5bdf(%rip), %rsi      # 0x17df2
callq 0x2220
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x4c(%rax), %esi
callq 0x2400
movq %rax, %rdi
movq 0xbd8e(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x28(%rsp), %rax
movl 0x4c(%rax), %eax
cmpl 0xc0(%rsp), %eax
jne 0x122d6
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0xfb30
movq 0x28(%rsp), %rdi
movl 0x4c(%rdi), %eax
addl 0xc4(%rsp), %eax
movl %eax, 0xc0(%rsp)
movl 0xa0(%rdi), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rdi)
addq $0x60, %rdi
callq 0x141e0
movq 0x28(%rsp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x122c8
movq 0x28(%rsp), %rdi
movq %rdi, %rax
addq $0x60, %rax
movq %rax, 0x20(%rsp)
addq $0x18, %rdi
callq 0x12f00
movq 0x20(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0xbc(%rsp)
leaq 0xbc(%rsp), %rsi
callq 0x14210
movq 0x28(%rsp), %rax
movl $0x0, 0x48(%rax)
jmp 0x12328
movq 0x28(%rsp), %rdi
movl 0x48(%rdi), %esi
callq 0xfb30
movq 0x28(%rsp), %rdi
addq $0x60, %rdi
callq 0x141e0
movq 0x28(%rsp), %rdi
movq %rdi, %rax
addq $0x60, %rax
movq %rax, 0x18(%rsp)
addq $0x18, %rdi
callq 0x12f00
movq 0x18(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0xb8(%rsp)
leaq 0xb8(%rsp), %rsi
callq 0x14210
jmp 0x1232a
movq 0x28(%rsp), %rdi
addq $0x60, %rdi
callq 0x13e10
testb $0x1, %al
jne 0x12346
movq 0x28(%rsp), %rdi
callq 0x125b0
movq 0x28(%rsp), %rax
testb $0x1, 0x7c(%rax)
jne 0x12590
leaq 0xac(%rsp), %rdi
callq 0x59f0
movq 0x28(%rsp), %rax
movl 0xa8(%rax), %eax
movq %rax, 0x10(%rsp)
subq $0x3, %rax
ja 0x124b2
movq 0x10(%rsp), %rax
leaq 0x5880(%rip), %rcx      # 0x17c08
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x28(%rsp), %rdi
callq 0xe0d0
movb %dl, 0x98(%rsp)
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0xa0(%rsp)
movb 0x98(%rsp), %al
movb %al, 0xa8(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0xac(%rsp)
movb 0xa8(%rsp), %al
movb %al, 0xb4(%rsp)
jmp 0x124b2
movq 0x28(%rsp), %rdi
callq 0xe2d0
movb %dl, 0x78(%rsp)
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x84(%rsp)
movb 0x78(%rsp), %al
movb %al, 0x8c(%rsp)
movq 0x84(%rsp), %rax
movq %rax, 0xac(%rsp)
movb 0x8c(%rsp), %al
movb %al, 0xb4(%rsp)
jmp 0x124b2
movq 0x28(%rsp), %rdi
callq 0xdf30
movb %dl, 0x58(%rsp)
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x64(%rsp)
movb 0x58(%rsp), %al
movb %al, 0x6c(%rsp)
movq 0x64(%rsp), %rax
movq %rax, 0xac(%rsp)
movb 0x6c(%rsp), %al
movb %al, 0xb4(%rsp)
jmp 0x124b2
movq 0x28(%rsp), %rdi
callq 0x116e0
movb %dl, 0x38(%rsp)
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x44(%rsp)
movb 0x38(%rsp), %al
movb %al, 0x4c(%rsp)
movq 0x44(%rsp), %rax
movq %rax, 0xac(%rsp)
movb 0x4c(%rsp), %al
movb %al, 0xb4(%rsp)
cmpl $-0x1, 0xac(%rsp)
je 0x12581
movq 0x28(%rsp), %rax
testb $0x1, 0xa4(%rax)
je 0x12542
movq 0xbafb(%rip), %rdi      # 0x1dfd0
leaq 0x592f(%rip), %rsi      # 0x17e0b
callq 0x2220
movq %rax, %rdi
movl 0xac(%rsp), %esi
callq 0x2400
movq %rax, (%rsp)
movb 0xb4(%rsp), %cl
movb $0x3d, %al
movb $0x21, %dl
movb %dl, 0xe(%rsp)
testb $0x1, %cl
movb %al, 0xf(%rsp)
jne 0x12514
movb 0xe(%rsp), %al
movb %al, 0xf(%rsp)
movq (%rsp), %rdi
movb 0xf(%rsp), %al
movsbl %al, %esi
callq 0x22d0
movq %rax, %rdi
movl 0xb0(%rsp), %esi
callq 0x2400
movq %rax, %rdi
movq 0xba83(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x28(%rsp), %rdi
movl 0x50(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x50(%rdi)
movl 0x48(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x48(%rdi)
movl $0xffffffff, 0x78(%rdi) # imm = 0xFFFFFFFF
movl 0xac(%rsp), %esi
movb 0xb4(%rsp), %al
movl 0xb0(%rsp), %ecx
andb $0x1, %al
movzbl %al, %edx
callq 0xe470
jmp 0x1258e
movl $0x0, 0xd4(%rsp)
jmp 0x12595
jmp 0x12590
jmp 0x12091
movl 0xd4(%rsp), %eax
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)