// File: 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:
subq $0x138, %rsp            # imm = 0x138
movb %dl, %al
movq %rsi, 0x11c(%rsp)
movb %al, 0x124(%rsp)
movq 0x11c(%rsp), %rax
movq %rax, 0x12c(%rsp)
movl 0x124(%rsp), %eax
movl %eax, 0x134(%rsp)
movq %rdi, 0x110(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x58(%rsp)
testb $0x1, 0x134(%rsp)
je 0x112c1
movq 0x58(%rsp), %rax
testb $0x1, 0xa4(%rax)
je 0x10dba
movq 0xd2ee(%rip), %rdi      # 0x1dfd0
leaq 0x6fc9(%rip), %rsi      # 0x17cb2
callq 0x2220
movq %rax, %rdi
movl 0x12c(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x6eca(%rip), %rsi      # 0x17bd1
callq 0x2220
movq %rax, %rdi
movl 0x130(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x6fa0(%rip), %rsi      # 0x17cc5
callq 0x2220
movq %rax, %rdi
movq 0x58(%rsp), %rax
movl 0x48(%rax), %esi
callq 0x2400
movq %rax, %rdi
movq 0xd27c(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0xd280(%rip), %rdi      # 0x1dfd0
leaq 0x6f79(%rip), %rsi      # 0x17cd0
callq 0x2220
movq %rax, %rdi
movq 0xd25a(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x58(%rsp), %rax
cmpl $-0x1, 0x78(%rax)
jle 0x10d95
movq 0x58(%rsp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x78(%rax), %rsi
callq 0x12f20
movq (%rax), %rdi
callq 0xb600
jmp 0x10db8
movq 0x58(%rsp), %rax
movl 0x78(%rax), %esi
movq 0xd22c(%rip), %rdi      # 0x1dfd0
callq 0x2400
movq %rax, %rdi
movq 0xd20d(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0x10dba
movq 0x58(%rsp), %rax
addq $0x88, %rax
movq %rax, 0x40(%rsp)
movl 0x12c(%rsp), %esi
movb 0x134(%rsp), %al
movl 0x130(%rsp), %ecx
leaq 0x104(%rsp), %rdi
andb $0x1, %al
movzbl %al, %edx
callq 0x12f70
movq 0x40(%rsp), %rdi
leaq 0x104(%rsp), %rsi
callq 0x12fb0
movq 0x58(%rsp), %rdi
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x130(%rsp), %rcx
movl $0x1, (%rax,%rcx,4)
movl 0x48(%rdi), %eax
movl %eax, 0x48(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x48(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x130(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x130(%rsp), %eax
movl %eax, 0x4c(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x4c(%rsp), %ecx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movl 0x78(%rdi), %eax
movl %eax, 0x50(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x50(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0x130(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0x54(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x54(%rsp), %edx
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0x130(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x12c(%rsp), %esi
movb 0x134(%rsp), %al
xorb $-0x1, %al
movl 0x130(%rsp), %ecx
movzbl %al, %edx
andl $0x1, %edx
leaq 0xf8(%rsp), %rdi
callq 0x12f70
movq 0x58(%rsp), %rdi
movq 0xf8(%rsp), %rax
movq %rax, 0xe8(%rsp)
movl 0x100(%rsp), %eax
movl %eax, 0xf0(%rsp)
movq 0xe8(%rsp), %rsi
movzbl 0xf0(%rsp), %edx
callq 0x13f00
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %ecx
xorl %eax, %eax
cmpl 0x130(%rsp), %ecx
movb %al, 0x3f(%rsp)
jge 0x10f82
movq 0x58(%rsp), %rax
movb 0x7c(%rax), %al
xorb $-0x1, %al
movb %al, 0x3f(%rsp)
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x10f8f
jmp 0x110f8
movq 0x58(%rsp), %rdi
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0xe4(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x110e0
movq 0x58(%rsp), %rdi
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0xe4(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x48(%rdi), %eax
movl %eax, 0x30(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x30(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0xe4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x78(%rdi), %eax
movl %eax, 0x34(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x34(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0xe4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0x38(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x38(%rsp), %edx
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0xe4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x12c(%rsp), %esi
movb 0x134(%rsp), %al
movl 0xe4(%rsp), %ecx
leaq 0xd8(%rsp), %rdi
andb $0x1, %al
movzbl %al, %edx
callq 0x12f70
movq 0x58(%rsp), %rdi
movq 0xd8(%rsp), %rax
movq %rax, 0xc8(%rsp)
movl 0xe0(%rsp), %eax
movl %eax, 0xd0(%rsp)
movq 0xc8(%rsp), %rsi
movzbl 0xd0(%rsp), %edx
callq 0x13f00
jmp 0x110e2
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x10f5e
movl 0x130(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
movq 0x58(%rsp), %rdi
movl 0xc4(%rsp), %eax
movl %eax, 0x28(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x28(%rsp), %ecx
movq (%rax), %rdx
xorl %eax, %eax
cmpl 0x8(%rdx), %ecx
movb %al, 0x2f(%rsp)
jge 0x11146
movq 0x58(%rsp), %rax
movb 0x7c(%rax), %al
xorb $-0x1, %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x11153
jmp 0x112bc
movq 0x58(%rsp), %rdi
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0xc4(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x112a4
movq 0x58(%rsp), %rdi
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0xc4(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x48(%rdi), %eax
movl %eax, 0x1c(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x1c(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0xc4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x78(%rdi), %eax
movl %eax, 0x20(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x20(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0xc4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0x24(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x24(%rsp), %edx
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0xc4(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x12c(%rsp), %esi
movb 0x134(%rsp), %al
movl 0xc4(%rsp), %ecx
leaq 0xb8(%rsp), %rdi
andb $0x1, %al
movzbl %al, %edx
callq 0x12f70
movq 0x58(%rsp), %rdi
movq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movl 0xc0(%rsp), %eax
movl %eax, 0xb0(%rsp)
movq 0xa8(%rsp), %rsi
movzbl 0xb0(%rsp), %edx
callq 0x13f00
jmp 0x112a6
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x11109
jmp 0x115f5
movq 0x58(%rsp), %rax
testb $0x1, 0xa4(%rax)
je 0x113b2
movq 0xccf6(%rip), %rdi      # 0x1dfd0
leaq 0x69d1(%rip), %rsi      # 0x17cb2
callq 0x2220
movq %rax, %rdi
movl 0x12c(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x68d1(%rip), %rsi      # 0x17bd0
callq 0x2220
movq %rax, %rdi
movl 0x130(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x69a8(%rip), %rsi      # 0x17cc5
callq 0x2220
movq %rax, %rdi
movq 0x58(%rsp), %rax
movl 0x48(%rax), %esi
callq 0x2400
movq %rax, %rdi
movq 0xcc84(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0xcc88(%rip), %rdi      # 0x1dfd0
leaq 0x6981(%rip), %rsi      # 0x17cd0
callq 0x2220
movq %rax, %rdi
movq 0xcc62(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x58(%rsp), %rax
cmpl $-0x1, 0x78(%rax)
jle 0x1138d
movq 0x58(%rsp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x78(%rax), %rsi
callq 0x12f20
movq (%rax), %rdi
callq 0xb600
jmp 0x113b0
movq 0x58(%rsp), %rax
movl 0x78(%rax), %esi
movq 0xcc34(%rip), %rdi      # 0x1dfd0
callq 0x2400
movq %rax, %rdi
movq 0xcc15(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0x113b2
movq 0x58(%rsp), %rax
addq $0x88, %rax
movq %rax, 0x8(%rsp)
movl 0x12c(%rsp), %esi
movb 0x134(%rsp), %al
movl 0x130(%rsp), %ecx
leaq 0x9c(%rsp), %rdi
andb $0x1, %al
movzbl %al, %edx
callq 0x12f70
movq 0x8(%rsp), %rdi
leaq 0x9c(%rsp), %rsi
callq 0x12fb0
movq 0x58(%rsp), %rdi
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x130(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x48(%rdi), %eax
movl %eax, 0x10(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x10(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x130(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x78(%rdi), %eax
movl %eax, 0x14(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x14(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0x130(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0x18(%rsp)
movslq 0x12c(%rsp), %rsi
callq 0xaab0
movl 0x18(%rsp), %edx
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0x130(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x12c(%rsp), %esi
movb 0x134(%rsp), %al
xorb $-0x1, %al
movl 0x130(%rsp), %ecx
movzbl %al, %edx
andl $0x1, %edx
leaq 0x90(%rsp), %rdi
callq 0x12f70
movq 0x58(%rsp), %rdi
movq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
movl 0x98(%rsp), %eax
movl %eax, 0x88(%rsp)
movq 0x80(%rsp), %rsi
movzbl 0x88(%rsp), %edx
callq 0x13f00
movq 0x58(%rsp), %rdi
movl 0x12c(%rsp), %esi
callq 0xde60
movl %eax, 0x7c(%rsp)
cmpl $-0x1, 0x7c(%rsp)
je 0x115f3
movq 0x58(%rsp), %rax
testb $0x1, 0xa4(%rax)
je 0x1159e
movq 0xca77(%rip), %rdi      # 0x1dfd0
leaq 0x678d(%rip), %rsi      # 0x17ced
callq 0x2220
movq %rax, %rdi
movl 0x12c(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x6653(%rip), %rsi      # 0x17bd1
callq 0x2220
movq %rax, %rdi
movl 0x7c(%rsp), %esi
callq 0x2400
movq %rax, %rdi
movq 0xca27(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x58(%rsp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movl $0xfffffffe, 0x78(%rax) # imm = 0xFFFFFFFE
movl 0x12c(%rsp), %esi
movl 0x7c(%rsp), %ecx
leaq 0x70(%rsp), %rdi
movl $0x1, %edx
callq 0x12f70
movq 0x58(%rsp), %rdi
movq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x68(%rsp)
movq 0x60(%rsp), %rsi
movzbl 0x68(%rsp), %edx
callq 0x10c70
jmp 0x115f5
addq $0x138, %rsp            # imm = 0x138
retq
nopl (%rax)