// File: akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::watchedFalsifyLiteral(Literal)
inline void Formula::watchedFalsifyLiteral ( Literal lit ) {

//	cout << "Falsifying " << var << ( equals ? "=" : "!" ) << val << endl;
	VARRECORD* current = NULL;
	VARRECORD* next = NULL;

	// Go through all occurrences of the literal in clauses and update watched literals

	if ( lit.EQUAL ) current = VARLIST[lit.VAR] -> ATOMWATCHPOS[lit.VAL];
	else current = VARLIST[lit.VAR] -> ATOMWATCHNEG[lit.VAL];

	while ( current &&!CONFLICT ) {

		next = current->next;

		// CLAUSELIST[current -> c_num] -> Print();

		Literal watched1 = CLAUSELIST[current -> c_num] -> WATCHED[0];
		Literal watched2 = CLAUSELIST[current -> c_num] -> WATCHED[1];

		if ( sat ( watched1 ) != 1 )  {

			/*
			 *if the clause is not sat, and literal = watched1 or literal = watched2,
			  it means that watched1 is falsified, need to replace it by a unassigned literal
			  if available
			 */

			if (CLAUSELIST[current->c_num]->ATOM_LIST.size() > 1 && sat(watched2) == 1) {

				CLAUSELIST[current->c_num]->WATCHED[0] = watched2;
				CLAUSELIST[current->c_num]->WATCHED[1] = watched1;

			} else {
				if (watched2 == lit) {
					CLAUSELIST[current->c_num]->WATCHED[0] = watched2;
					CLAUSELIST[current->c_num]->WATCHED[1] = watched1;
				}
				SwapPointer(current);
			}
		}
		current = next;
	}

	current = NULL;

}

// Assembly:
subq $0x98, %rsp
movb %dl, %al
movq %rsi, 0x7c(%rsp)
movb %al, 0x84(%rsp)
movq 0x7c(%rsp), %rax
movq %rax, 0x8c(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x94(%rsp)
movq %rdi, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
testb $0x1, 0x94(%rsp)
je 0x13f87
movq 0x8(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x50(%rax), %rax
movslq 0x90(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x68(%rsp)
jmp 0x13fb1
movq 0x8(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x58(%rax), %rax
movslq 0x90(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x68(%rsp)
jmp 0x13fb3
xorl %eax, %eax
cmpq $0x0, 0x68(%rsp)
movb %al, 0x7(%rsp)
je 0x13fcf
movq 0x8(%rsp), %rax
movb 0x7c(%rax), %al
xorb $-0x1, %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x13fdc
jmp 0x141c0
movq 0x8(%rsp), %rdi
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x60(%rsp)
addq $0x18, %rdi
movq 0x68(%rsp), %rax
movslq (%rax), %rsi
callq 0x12f20
movq 0x8(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rcx
movq %rcx, 0x54(%rsp)
movl 0x28(%rax), %eax
movl %eax, 0x5c(%rsp)
addq $0x18, %rdi
movq 0x68(%rsp), %rax
movslq (%rax), %rsi
callq 0x12f20
movq 0x8(%rsp), %rdi
movq (%rax), %rax
movq 0x2c(%rax), %rcx
movq %rcx, 0x48(%rsp)
movl 0x34(%rax), %eax
movl %eax, 0x50(%rsp)
movq 0x54(%rsp), %rax
movq %rax, 0x3c(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x3c(%rsp), %rax
movq %rax, 0x2c(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x2c(%rsp), %rsi
movzbl 0x34(%rsp), %edx
callq 0x109b0
cmpl $0x1, %eax
je 0x141b1
movq 0x8(%rsp), %rdi
addq $0x18, %rdi
movq 0x68(%rsp), %rax
movslq (%rax), %rsi
callq 0x12f20
movq (%rax), %rdi
callq 0xb890
cmpq $0x1, %rax
jbe 0x14136
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x28(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x10(%rsp), %rsi
movzbl 0x18(%rsp), %edx
callq 0x109b0
cmpl $0x1, %eax
jne 0x14136
movq 0x8(%rsp), %rdi
addq $0x18, %rdi
movq 0x68(%rsp), %rax
movslq (%rax), %rsi
callq 0x12f20
movq 0x8(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x20(%rax)
movb 0x50(%rsp), %cl
movb %cl, 0x28(%rax)
addq $0x18, %rdi
movq 0x68(%rsp), %rax
movslq (%rax), %rsi
callq 0x12f20
movq (%rax), %rax
movq 0x54(%rsp), %rcx
movq %rcx, 0x2c(%rax)
movb 0x5c(%rsp), %cl
movb %cl, 0x34(%rax)
jmp 0x141af
leaq 0x48(%rsp), %rdi
leaq 0x8c(%rsp), %rsi
callq 0x13660
testb $0x1, %al
jne 0x1414e
jmp 0x141a0
movq 0x8(%rsp), %rdi
addq $0x18, %rdi
movq 0x68(%rsp), %rax
movslq (%rax), %rsi
callq 0x12f20
movq 0x8(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x20(%rax)
movb 0x50(%rsp), %cl
movb %cl, 0x28(%rax)
addq $0x18, %rdi
movq 0x68(%rsp), %rax
movslq (%rax), %rsi
callq 0x12f20
movq (%rax), %rax
movq 0x54(%rsp), %rcx
movq %rcx, 0x2c(%rax)
movb 0x5c(%rsp), %cl
movb %cl, 0x34(%rax)
movq 0x8(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x11840
jmp 0x141b1
movq 0x60(%rsp), %rax
movq %rax, 0x68(%rsp)
jmp 0x13fb3
movq $0x0, 0x68(%rsp)
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)