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


	int restartCount = restarts;

	// returns 0 if sat, 1 if timeout, 2 if unsat

	if ( LOG ) cout << "Solving with the watched literal algorithm..." << endl;

	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 ) { cout << "UNSAT" << endl; return 2; }

			Clause* learned = analyzeConflict ( CLAUSELIST[CONFLICTINGCLAUSE], false );
			if (learned->ATOM_LIST.size() > 1)
				LEVEL = VARLIST[learned->WATCHED[1].VAR]->ATOMLEVEL[learned->WATCHED[1].VAL];
			else
				LEVEL = 0;

			BACKTRACKS++;
			if ( LOG ) {
				cout << "We are backtracking to the level: " << LEVEL << endl;
				cout << "# of backtracks so far: " << BACKTRACKS << endl;
			}
			CONFLICT = false;

			if ( BACKTRACKS == restartCount ) {


				//	cout << "restarting" << endl;
				watchedUndoTheory ( 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 {
				watchedUndoTheory ( 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() )
			WatchedUnitPropagation();

		if ( ! CONFLICT ) {
			Literal atom;
			switch(heuristic) {
			case Heuristic::VSIDS : atom = chooseLiteralVSIDS(); break;
			case Heuristic::VSIDS_pos : atom = chooseLiteralVSIDS_allPos(); break;
			case Heuristic::lazy  : atom = lazyWatchedChooseLiteral (); break;
			}
			if ( atom.VAR != -1 ) {
				DECISIONS++;
				LEVEL++;
				// set REASON for subsequent falsified atoms
				UNITCLAUSE = -1;
				if ( LOG ) cout << "Decision: " << atom . VAR << ( atom . EQUAL ? '=' : '!' ) << atom . VAL << endl;
				watchedReduceTheory ( atom );
			}
			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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, 0x10(%rsp)
movq %rdi, %r14
cmpb $0x1, 0xa4(%rdi)
jne 0xae3e
movq 0x61cd(%rip), %rbx      # 0x10fd0
leaq 0x300d(%rip), %rsi      # 0xde17
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x2270
movq (%rbx), %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
callq 0x2b92
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
ja 0xb208
leaq 0x60(%r14), %r12
movq 0x6166(%rip), %r15      # 0x10fd0
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpb $0x1, 0x7c(%r14)
jne 0xb0dc
cmpb $0x1, 0xa4(%r14)
jne 0xaf24
movl $0x1e, %edx
movq %r15, %rdi
leaq 0x2fab(%rip), %rsi      # 0xde45
callq 0x2270
movl 0x48(%r14), %esi
movq %r15, %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 %r15, %rdi
leaq 0x2f80(%rip), %rsi      # 0xde64
callq 0x2270
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r15, %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 0xb21e
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rsi
xorl %ebx, %ebx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9b02
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq $0x2, %rcx
jb 0xaf7f
movslq 0x2c(%rax), %rcx
movq (%r14), %rdx
movq (%rdx,%rcx,8), %rcx
movq 0x18(%rcx), %rcx
movslq 0x30(%rax), %rax
movl (%rcx,%rax,4), %ebx
movl %ebx, 0x48(%r14)
movl 0x4c(%r14), %eax
incl %eax
movl %eax, 0x4c(%r14)
cmpb $0x1, 0xa4(%r14)
jne 0xb033
movl $0x22, %edx
movq %r15, %rdi
leaq 0x2ed5(%rip), %rsi      # 0xde7f
callq 0x2270
movl 0x48(%r14), %esi
movq %r15, %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 $0x18, %edx
movq %r15, %rdi
leaq 0x2eae(%rip), %rsi      # 0xdea2
callq 0x2270
movl 0x4c(%r14), %esi
movq %r15, %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), %eax
movb $0x0, 0x7c(%r14)
cmpl 0x14(%rsp), %eax
jne 0xb09e
movq %r14, %rdi
xorl %esi, %esi
callq 0x99d4
movl 0x4c(%r14), %eax
addl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
incl 0xa0(%r14)
movq %r12, %rdi
callq 0xbab2
cmpl $0x0, 0x48(%r14)
jne 0xb094
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 %r12, %rsi
callq 0x2070
incq 0x70(%r14)
movl $0x0, 0x48(%r14)
jmp 0xb0dc
movl 0x48(%r14), %esi
movq %r14, %rdi
callq 0x99d4
movq %r12, %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 %r12, %rsi
callq 0x2070
incq 0x70(%r14)
cmpq %r12, (%r12)
je 0xb0ea
movq %r14, %rdi
callq 0x9ffe
cmpb $0x0, 0x7c(%r14)
jne 0xb1e4
movl 0xa8(%r14), %eax
xorl %ebx, %ebx
cmpl $0x3, %eax
je 0xb125
cmpl $0x2, %eax
je 0xb11b
cmpl $0x1, %eax
jne 0xb20d
movq %r14, %rdi
callq 0x81e6
jmp 0xb12d
movq %r14, %rdi
callq 0xab26
jmp 0xb12d
movq %r14, %rdi
callq 0x82a6
movq %rax, %r13
movl %edx, %ebp
cmpl $-0x1, %r13d
je 0xb20d
incl 0x50(%r14)
incl 0x48(%r14)
movl $0xffffffff, 0x78(%r14) # imm = 0xFFFFFFFF
cmpb $0x1, 0xa4(%r14)
jne 0xb1d5
movl $0xa, %edx
movq %r15, %rdi
leaq 0x2d56(%rip), %rsi      # 0xdebb
callq 0x2270
movq %r15, %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
movzbl %bpl, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0xa0ce
callq 0x2b92
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xae72
movl $0x1, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c54(%rip), %rsi      # 0xde79
movl $0x5, %edx
movq %r15, %rdi
callq 0x2270
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movl $0x2, %ebx
jmp 0xb20d