// File: /workspace/github_cpp_makefile_star2_O1/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 0xabaa
movq 0x5461(%rip), %r15      # 0xffd0
leaq 0x22a1(%rip), %rsi      # 0xce17
movl $0x2d, %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
callq 0x2b7e
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
cvtsi2sdl 0x30(%r14), %xmm1
movl $0x1, %eax
ucomisd %xmm1, %xmm0
ja 0xafc3
leaq 0x60(%r14), %r12
movq 0x53f5(%rip), %r15      # 0xffd0
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpb $0x1, 0x7c(%r14)
jne 0xae47
cmpb $0x1, 0xa4(%r14)
jne 0xac95
movl $0x1e, %edx
movq %r15, %rdi
leaq 0x223a(%rip), %rsi      # 0xce45
callq 0x2270
movl 0x48(%r14), %esi
movq %r15, %rdi
callq 0x2390
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movl $0x14, %edx
movq %r15, %rdi
leaq 0x220f(%rip), %rsi      # 0xce64
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 0x6fb0
cmpl $0x0, 0x48(%r14)
je 0xaf7f
movslq 0x80(%r14), %rax
movq 0x18(%r14), %rcx
movq (%rcx,%rax,8), %rsi
xorl %ebx, %ebx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9bec
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq $0x2, %rcx
jb 0xacf0
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)
incl 0x4c(%r14)
cmpb $0x1, 0xa4(%r14)
jne 0xad9a
movl $0x22, %edx
movq %r15, %rdi
leaq 0x216a(%rip), %rsi      # 0xce7f
callq 0x2270
movl 0x48(%r14), %esi
movq %r15, %rdi
callq 0x2390
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movl $0x18, %edx
movq %r15, %rdi
leaq 0x2143(%rip), %rsi      # 0xcea2
callq 0x2270
movl 0x4c(%r14), %esi
movq %r15, %rdi
callq 0x2390
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movb $0x0, 0x7c(%r14)
movl 0x14(%rsp), %eax
cmpl %eax, 0x4c(%r14)
jne 0xae09
movq %r14, %rdi
xorl %esi, %esi
callq 0x9aca
movl 0x4c(%r14), %eax
addl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
incl 0xa0(%r14)
movq %r12, %rdi
callq 0xb94e
cmpl $0x0, 0x48(%r14)
jne 0xadff
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 0xae47
movl 0x48(%r14), %esi
movq %r14, %rdi
callq 0x9aca
movq %r12, %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 %r12, %rsi
callq 0x2070
incq 0x70(%r14)
cmpq %r12, (%r12)
je 0xae55
movq %r14, %rdi
callq 0xa0fc
cmpb $0x0, 0x7c(%r14)
jne 0xaf54
movl 0xa8(%r14), %eax
cmpl $0x3, %eax
je 0xae8a
cmpl $0x2, %eax
je 0xae80
cmpl $0x1, %eax
jne 0xae99
movq %r14, %rdi
callq 0x82be
jmp 0xae92
movq %r14, %rdi
callq 0xa7d8
jmp 0xae92
movq %r14, %rdi
callq 0x837e
movq %rax, %r13
movl %edx, %ebp
jmp 0xaea2
movq $-0x1, %r13
xorl %ebp, %ebp
cmpl $-0x1, %r13d
je 0xafc1
incl 0x50(%r14)
incl 0x48(%r14)
movl $0xffffffff, 0x78(%r14) # imm = 0xFFFFFFFF
cmpb $0x1, 0xa4(%r14)
jne 0xaf45
movl $0xa, %edx
movq %r15, %rdi
leaq 0x1fe6(%rip), %rsi      # 0xcebb
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 0xa1cc
callq 0x2b7e
movsd %xmm0, 0x40(%r14)
subsd 0x38(%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x30(%r14), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xabe3
movl $0x1, %eax
jmp 0xafc3
leaq 0x1ef3(%rip), %rsi      # 0xce79
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, %eax
jmp 0xafc3
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq