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

	if ( lit.EQUAL ) {

		if ( LOG ) {
			cout << "Reducing literal: " << lit.VAR << "="<< lit.VAL << " at level " << LEVEL << endl;
			cout << "The reason for the literal: " << endl;
			if ( UNITCLAUSE > -1 ) CLAUSELIST[UNITCLAUSE] -> Print(); else cout << UNITCLAUSE << endl;
		}

		DECSTACK.push_back(Literal(lit.VAR, lit.EQUAL, lit.VAL)); 		// Add literal to the decision stack

		VARLIST[lit.VAR] -> ATOMASSIGN[lit.VAL] = 1;
		VARLIST[lit.VAR] -> ATOMLEVEL[lit.VAL] = LEVEL;
		VARLIST[lit.VAR] -> VAL = lit.VAL;
		VARLIST[lit.VAR] -> CLAUSEID[lit.VAL] = UNITCLAUSE; 		// Set the reason for the literal
		VARLIST[lit.VAR] -> ATOMINDEX[lit.VAL] = DECSTACK.size() - 1; // to use in maxLit

		// update watched literals:
		watchedFalsifyLiteral ( Literal(lit.VAR, ! lit.EQUAL, lit.VAL) ); // if one of the watched literals falsified, swap watched literals


		//for each different domain value x from dom(lit.VAR) which is not assigned (0) assign it

		for ( int i = 0; i < lit.VAL && ! CONFLICT; i++ ) {

			if ( VARLIST[lit.VAR] -> ATOMASSIGN[i] == 0 ) {

				VARLIST[lit.VAR]->ATOMASSIGN[i] = -1;
				VARLIST[lit.VAR]->ATOMLEVEL[i] = LEVEL;

				// Set the same reason:
				VARLIST[lit.VAR]->CLAUSEID[i] = UNITCLAUSE;
				VARLIST[lit.VAR] -> ATOMINDEX[i] = DECSTACK.size() - 1; // to use in maxLit


				watchedFalsifyLiteral ( Literal(lit.VAR, lit.EQUAL, i) ); // if one of the watched literals falsified, swap watched literals

			}
		}

		for ( int i = lit.VAL + 1; i < VARLIST[lit.VAR] -> DOMAINSIZE && ! CONFLICT; i++ ) {

			if ( VARLIST[lit.VAR] -> ATOMASSIGN[i] == 0 ) {

				VARLIST[lit.VAR]->ATOMASSIGN[i] = -1;
				VARLIST[lit.VAR]->ATOMLEVEL[i] = LEVEL;

				VARLIST[lit.VAR] -> CLAUSEID[i] = UNITCLAUSE;
				VARLIST[lit.VAR] -> ATOMINDEX[i] = DECSTACK.size() - 1; // to use in maxLit

				watchedFalsifyLiteral ( Literal(lit.VAR, lit.EQUAL, i) ); // if one of the watched literals falsified, swap watched literals
			}
		}
	} else {

		if ( LOG ) {
			cout << "Reducing literal: " << lit.VAR << "!="<< lit.VAL << " at level " << LEVEL << endl;
			cout << "The reason for the literal: " << endl;
			if ( UNITCLAUSE > -1 ) CLAUSELIST[UNITCLAUSE] -> Print(); else cout << UNITCLAUSE << endl;
		}

		//Add literal to decision stack:
		DECSTACK.push_back ( Literal(lit.VAR, lit.EQUAL, lit.VAL) );

		VARLIST[lit.VAR] -> ATOMASSIGN[lit.VAL] = -1;
		VARLIST[lit.VAR] -> ATOMLEVEL[lit.VAL] = LEVEL;
		// Set the reason:
		VARLIST[lit.VAR] -> CLAUSEID[lit.VAL] = UNITCLAUSE;
		VARLIST[lit.VAR] -> ATOMINDEX[lit.VAL] = DECSTACK.size() - 1; // to use in maxLit

		watchedFalsifyLiteral ( Literal(lit.VAR, ! lit.EQUAL, lit.VAL) );


		//check Entailment on this variable
		int entailVal = checkEntail ( lit.VAR );
		if ( entailVal != -1 ) {
			if ( LOG ) cout << "Entailment... " << lit.VAR << "=" << entailVal << endl;
			ENTAILS++;
			// Set the reason:
			UNITCLAUSE = -2;
			watchedReduceTheory ( Literal(lit.VAR, true, entailVal) );
		}

	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %r15
shrq $0x20, %r15
movb 0xa4(%rdi), %al
testb $0x1, %dl
je 0xa2ed
testb %al, %al
je 0xa41a
movq 0x5dcb(%rip), %r12      # 0xffd0
leaq 0x2b56(%rip), %rsi      # 0xcd62
movl $0x12, %edx
movq %r12, %rdi
callq 0x2270
movq %r12, %rdi
movl %r14d, %esi
callq 0x2390
movq %rax, %r13
leaq 0x2a53(%rip), %rsi      # 0xcc81
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq %r13, %rdi
movl %r15d, %esi
callq 0x2390
movq %rax, %r13
leaq 0x2b25(%rip), %rsi      # 0xcd75
movl $0xa, %edx
movq %rax, %rdi
callq 0x2270
movl 0x48(%rbx), %esi
movq %r13, %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
leaq 0x2ae7(%rip), %rsi      # 0xcd80
movl $0x1c, %edx
movq %r12, %rdi
callq 0x2270
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movslq 0x78(%rbx), %rsi
testq %rsi, %rsi
js 0xa3e4
movq 0x18(%rbx), %rax
movq (%rax,%rsi,8), %rdi
callq 0x6fb0
jmp 0xa41a
testb %al, %al
je 0xa62a
movq 0x5cd4(%rip), %r12      # 0xffd0
leaq 0x2a5f(%rip), %rsi      # 0xcd62
movl $0x12, %edx
movq %r12, %rdi
callq 0x2270
movq %r12, %rdi
movl %r14d, %esi
callq 0x2390
movq %rax, %r13
leaq 0x295b(%rip), %rsi      # 0xcc80
movl $0x2, %edx
movq %rax, %rdi
callq 0x2270
movq %r13, %rdi
movl %r15d, %esi
callq 0x2390
movq %rax, %r13
leaq 0x2a2e(%rip), %rsi      # 0xcd75
movl $0xa, %edx
movq %rax, %rdi
callq 0x2270
movl 0x48(%rbx), %esi
movq %r13, %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
leaq 0x29f0(%rip), %rsi      # 0xcd80
movl $0x1c, %edx
movq %r12, %rdi
callq 0x2270
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movslq 0x78(%rbx), %rsi
testq %rsi, %rsi
js 0xa5f4
movq 0x18(%rbx), %rax
movq (%rax,%rsi,8), %rdi
callq 0x6fb0
jmp 0xa62a
movq 0x5be5(%rip), %rdi      # 0xffd0
callq 0x2390
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movl %r14d, 0x4(%rsp)
movl %r15d, 0x8(%rsp)
movb $0x1, 0xc(%rsp)
movq 0x90(%rbx), %rsi
cmpq 0x98(%rbx), %rsi
je 0xa452
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0x4(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x90(%rbx)
jmp 0xa463
leaq 0x88(%rbx), %rdi
leaq 0x4(%rsp), %rdx
callq 0xbbd2
movabsq $0x100000000, %r12      # imm = 0x100000000
movslq %r14d, %r13
movq (%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x20(%rax), %rcx
movq %r14, %rdx
sarq $0x20, %rdx
movl $0x1, (%rcx,%rdx,4)
movl 0x48(%rbx), %ecx
movq 0x18(%rax), %rsi
movl %ecx, (%rsi,%rdx,4)
movl %r15d, 0x4(%rax)
movl 0x78(%rbx), %ecx
movq 0x48(%rax), %rsi
movl %ecx, (%rsi,%rdx,4)
movq 0x90(%rbx), %rcx
subq 0x88(%rbx), %rcx
shrq $0x2, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
decl %ecx
movq 0x10(%rax), %rax
movl %ecx, (%rax,%rdx,4)
movl %r13d, %eax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xb80a
testl %r15d, %r15d
jle 0xa551
xorl %ebp, %ebp
movq 0x10(%rsp), %r14
cmpb $0x1, 0x7c(%rbx)
je 0xa551
movq (%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x20(%rax), %rcx
cmpl $0x0, (%rcx,%rbp,4)
jne 0xa546
movl $0xffffffff, (%rcx,%rbp,4) # imm = 0xFFFFFFFF
movl 0x48(%rbx), %ecx
movq 0x18(%rax), %rdx
movl %ecx, (%rdx,%rbp,4)
movl 0x78(%rbx), %ecx
movq 0x48(%rax), %rdx
movl %ecx, (%rdx,%rbp,4)
movq 0x90(%rbx), %rcx
subq 0x88(%rbx), %rcx
shrq $0x2, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
decl %ecx
movq 0x10(%rax), %rax
movl %ecx, (%rax,%rbp,4)
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xb80a
incq %rbp
addq %r12, %r14
cmpq %rbp, %r15
jne 0xa4e3
leal 0x1(%r15), %ecx
movq (%rbx), %rax
movq (%rax,%r13,8), %rax
cmpl 0x8(%rax), %ecx
jge 0xa7c9
movslq %ecx, %r15
movq %r15, %r14
shlq $0x20, %r14
addq 0x10(%rsp), %r14
cmpb $0x0, 0x7c(%rbx)
jne 0xa7c9
movq 0x20(%rax), %rcx
cmpl $0x0, (%rcx,%r15,4)
jne 0xa5d9
movl $0xffffffff, (%rcx,%r15,4) # imm = 0xFFFFFFFF
movl 0x48(%rbx), %ecx
movq 0x18(%rax), %rdx
movl %ecx, (%rdx,%r15,4)
movl 0x78(%rbx), %ecx
movq 0x48(%rax), %rdx
movl %ecx, (%rdx,%r15,4)
movq 0x90(%rbx), %rcx
subq 0x88(%rbx), %rcx
shrq $0x2, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
decl %ecx
movq 0x10(%rax), %rax
movl %ecx, (%rax,%r15,4)
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xb80a
incq %r15
movq (%rbx), %rax
movq (%rax,%r13,8), %rax
movslq 0x8(%rax), %rcx
addq %r12, %r14
cmpq %rcx, %r15
jl 0xa574
jmp 0xa7c9
movq 0x59d5(%rip), %rdi      # 0xffd0
callq 0x2390
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
movl %r14d, 0x4(%rsp)
movl %r15d, 0x8(%rsp)
movb $0x0, 0xc(%rsp)
movq 0x90(%rbx), %rsi
cmpq 0x98(%rbx), %rsi
je 0xa662
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0x4(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x90(%rbx)
jmp 0xa673
leaq 0x88(%rbx), %rdi
leaq 0x4(%rsp), %rdx
callq 0xbbd2
movq (%rbx), %rax
movslq %r14d, %r15
movq (%rax,%r15,8), %rax
movq 0x20(%rax), %rcx
movq %r14, %rdx
sarq $0x20, %rdx
movl $0xffffffff, (%rcx,%rdx,4) # imm = 0xFFFFFFFF
movl 0x48(%rbx), %ecx
movq 0x18(%rax), %rsi
movl %ecx, (%rsi,%rdx,4)
movl 0x78(%rbx), %ecx
movq 0x48(%rax), %rsi
movl %ecx, (%rsi,%rdx,4)
movq 0x90(%rbx), %rcx
subq 0x88(%rbx), %rcx
shrq $0x2, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
decl %ecx
movq 0x10(%rax), %rax
movl %ecx, (%rax,%rdx,4)
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0xb80a
movq (%rbx), %rax
movq (%rax,%r15,8), %rcx
movslq 0x8(%rcx), %rax
testq %rax, %rax
jle 0xa71a
movq 0x20(%rcx), %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
xorl %edi, %edi
cmpl $0x0, (%rcx,%rdx,4)
jne 0xa702
testb $0x1, %dil
jne 0xa71a
movb $0x1, %dil
movl %edx, %esi
incq %rdx
cmpq %rdx, %rax
jne 0xa6f1
testb $0x1, %dil
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmovnel %esi, %r15d
jmp 0xa720
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r15d
je 0xa7c9
movl %r14d, %r13d
cmpb $0x1, 0xa4(%rbx)
jne 0xa7a8
movq 0x5893(%rip), %r12      # 0xffd0
leaq 0x2659(%rip), %rsi      # 0xcd9d
movl $0xe, %edx
movq %r12, %rdi
callq 0x2270
movq %r12, %rdi
movl %r14d, %esi
callq 0x2390
movq %rax, %r14
leaq 0x251b(%rip), %rsi      # 0xcc81
movl $0x1, %edx
movq %rax, %rdi
callq 0x2270
movq %r14, %rdi
movl %r15d, %esi
callq 0x2390
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2180
incl 0x58(%rbx)
movl $0xfffffffe, 0x78(%rbx) # imm = 0xFFFFFFFE
shlq $0x20, %r15
orq %r13, %r15
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0xa1cc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq