// File: akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::reduceTheory(int, bool, int)
void Formula::reduceTheory ( int var, bool equals, int val ) {

	if ( equals ) {

		if ( LOG ) {
			cout << "Reducing literal: " << var << "="<< 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 the Decision Stack
		DECSTACK.push_back ( Literal ( var, '=', val ) );

		if (heuristic==Heuristic::BK) {
			VARLIST[var] -> ATOMCNTPOS[val] = 0;
			VARLIST[var] -> ATOMCNTNEG[val] = 0;
		}
		VARLIST[var] -> ATOMASSIGN[val] = 1;
		VARLIST[var] -> ATOMLEVEL[val] = LEVEL;
		VARLIST[var] -> VAL = val;
		VARLIST[var] -> CLAUSEID[val] = UNITCLAUSE;
		VARLIST[var] -> ATOMINDEX[val] = DECSTACK.size() - 1; // to use in maxLit

		// satisfy all clauses with the literal, and remove the complement literal from clauses
		satisfyClauses ( var, equals, val );
		removeLiteral ( var, !equals, val );



		//foreach domain value x from dom(v) which is not assigned assign it
		for ( int i = 0; i < val && ! CONFLICT; i++ ) {

			if ( VARLIST[var] -> ATOMASSIGN[i] == 0 ) {

				if (heuristic==Heuristic::BK) {
					VARLIST[var] -> ATOMCNTPOS[i] = 0;
					VARLIST[var] -> ATOMCNTNEG[i] = 0;
				}
				VARLIST[var] -> ATOMASSIGN[i] = -1;
				VARLIST[var]->ATOMLEVEL[i] = LEVEL;
				VARLIST[var]->CLAUSEID[i] = UNITCLAUSE;
				VARLIST[var]->ATOMINDEX[i] = DECSTACK.size() - 1;

				satisfyClauses ( var, !equals, i );
				removeLiteral ( var, equals, i );
			}
		}

		for ( int i = val+1; i < VARLIST[var] -> DOMAINSIZE && ! CONFLICT; i++ ) {
			if ( VARLIST[var] -> ATOMASSIGN[i] == 0 ) {

				if (heuristic==Heuristic::BK) {
					VARLIST[var] -> ATOMCNTPOS[i] = 0;
					VARLIST[var] -> ATOMCNTNEG[i] = 0;
				}

				VARLIST[var] -> ATOMASSIGN[i] = -1;
				VARLIST[var] -> ATOMLEVEL[i] = LEVEL;
				VARLIST[var] -> CLAUSEID[i] = UNITCLAUSE;
				VARLIST[var] -> ATOMINDEX[i] = DECSTACK.size() - 1;

				satisfyClauses ( var, !equals, i );
				removeLiteral ( var, equals, i );
			}
		}
	}
	else {
		if ( LOG ) {
			cout << "Reducing literal: " << var << "!="<< 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 ( var, '!', val ) );

		if (heuristic==Heuristic::BK) {
			VARLIST[var] -> ATOMCNTPOS[val] = 0;
			VARLIST[var] -> ATOMCNTNEG[val] = 0;
		}
		VARLIST[var] -> ATOMASSIGN[val] = -1;
		VARLIST[var] -> ATOMLEVEL[val] = LEVEL;
		VARLIST[var] -> CLAUSEID[val] = UNITCLAUSE;
		VARLIST[var] -> ATOMINDEX[val] = DECSTACK.size() - 1;

		satisfyClauses ( var, equals, val );
		removeLiteral ( var, !equals, val );

		// Check entailment on this variable

		int entailVal = checkEntail ( var );
		if ( entailVal != -1 ) {

			ENTAILS++;
			if ( LOG ) cout << "Entailment... " << var << "=" << entailVal << endl;
			UNITCLAUSE = -2;
			reduceTheory ( var, true, entailVal );
		}
	}
}

// Assembly:
subq $0x98, %rsp
movb %dl, %al
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
andb $0x1, %al
movb %al, 0x8b(%rsp)
movl %ecx, 0x84(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x58(%rsp)
testb $0x1, 0x8b(%rsp)
je 0xeb2b
movq 0x58(%rsp), %rax
testb $0x1, 0xa4(%rax)
je 0xe5a4
movq 0xfb04(%rip), %rdi      # 0x1dfd0
leaq 0x97df(%rip), %rsi      # 0x17cb2
callq 0x2220
movq %rax, %rdi
movl 0x8c(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x96e0(%rip), %rsi      # 0x17bd1
callq 0x2220
movq %rax, %rdi
movl 0x84(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x97b6(%rip), %rsi      # 0x17cc5
callq 0x2220
movq %rax, %rdi
movq 0x58(%rsp), %rax
movl 0x48(%rax), %esi
callq 0x2400
movq %rax, %rdi
movq 0xfa92(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0xfa96(%rip), %rdi      # 0x1dfd0
leaq 0x978f(%rip), %rsi      # 0x17cd0
callq 0x2220
movq %rax, %rdi
movq 0xfa70(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x58(%rsp), %rax
cmpl $-0x1, 0x78(%rax)
jle 0xe57f
movq 0x58(%rsp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x78(%rax), %rsi
callq 0x12f20
movq (%rax), %rdi
callq 0xb600
jmp 0xe5a2
movq 0x58(%rsp), %rax
movl 0x78(%rax), %esi
movq 0xfa42(%rip), %rdi      # 0x1dfd0
callq 0x2400
movq %rax, %rdi
movq 0xfa23(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0xe5a4
movq 0x58(%rsp), %rax
addq $0x88, %rax
movq %rax, 0x50(%rsp)
movl 0x8c(%rsp), %esi
movl 0x84(%rsp), %ecx
leaq 0x78(%rsp), %rdi
movl $0x3d, %edx
callq 0x12e00
movq 0x50(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x12fb0
movq 0x58(%rsp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0xe63e
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x28(%rax), %rax
movslq 0x84(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq 0x84(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x84(%rsp), %rcx
movl $0x1, (%rax,%rcx,4)
movl 0x48(%rdi), %eax
movl %eax, 0x40(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x40(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x84(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x84(%rsp), %eax
movl %eax, 0x44(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x44(%rsp), %ecx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movl 0x78(%rdi), %eax
movl %eax, 0x48(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x48(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0x84(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0x4c(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x4c(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0x84(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
movl 0x84(%rsp), %ecx
andb $0x1, %al
movzbl %al, %edx
callq 0x12fe0
movq 0x58(%rsp), %rdi
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
xorb $-0x1, %al
movl 0x84(%rsp), %ecx
movzbl %al, %edx
andl $0x1, %edx
callq 0x13400
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %ecx
xorl %eax, %eax
cmpl 0x84(%rsp), %ecx
movb %al, 0x3f(%rsp)
jge 0xe7a0
movq 0x58(%rsp), %rax
movb 0x7c(%rax), %al
xorb $-0x1, %al
movb %al, 0x3f(%rsp)
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0xe7ad
jmp 0xe93f
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x74(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xe92d
movq 0x58(%rsp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0xe82d
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x28(%rax), %rax
movslq 0x74(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq 0x74(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x74(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x48(%rdi), %eax
movl %eax, 0x30(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x30(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x74(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x78(%rdi), %eax
movl %eax, 0x34(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x34(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0x74(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0x38(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x38(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0x74(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
xorb $-0x1, %al
movl 0x74(%rsp), %ecx
movzbl %al, %edx
andl $0x1, %edx
callq 0x12fe0
movq 0x58(%rsp), %rdi
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
movl 0x74(%rsp), %ecx
andb $0x1, %al
movzbl %al, %edx
callq 0x13400
jmp 0xe92f
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0xe77f
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
movq 0x58(%rsp), %rdi
movl 0x70(%rsp), %eax
movl %eax, 0x28(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x28(%rsp), %ecx
movq (%rax), %rdx
xorl %eax, %eax
cmpl 0x8(%rdx), %ecx
movb %al, 0x2f(%rsp)
jge 0xe987
movq 0x58(%rsp), %rax
movb 0x7c(%rax), %al
xorb $-0x1, %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0xe994
jmp 0xeb26
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x70(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xeb14
movq 0x58(%rsp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0xea14
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x28(%rax), %rax
movslq 0x70(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq 0x70(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x70(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x48(%rdi), %eax
movl %eax, 0x1c(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x1c(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x70(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x78(%rdi), %eax
movl %eax, 0x20(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x20(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0x70(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0x24(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x24(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0x70(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
xorb $-0x1, %al
movl 0x70(%rsp), %ecx
movzbl %al, %edx
andl $0x1, %edx
callq 0x12fe0
movq 0x58(%rsp), %rdi
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
movl 0x70(%rsp), %ecx
andb $0x1, %al
movzbl %al, %edx
callq 0x13400
jmp 0xeb16
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0xe94d
jmp 0xee6e
movq 0x58(%rsp), %rax
testb $0x1, 0xa4(%rax)
je 0xec1c
movq 0xf48c(%rip), %rdi      # 0x1dfd0
leaq 0x9167(%rip), %rsi      # 0x17cb2
callq 0x2220
movq %rax, %rdi
movl 0x8c(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x9067(%rip), %rsi      # 0x17bd0
callq 0x2220
movq %rax, %rdi
movl 0x84(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x913e(%rip), %rsi      # 0x17cc5
callq 0x2220
movq %rax, %rdi
movq 0x58(%rsp), %rax
movl 0x48(%rax), %esi
callq 0x2400
movq %rax, %rdi
movq 0xf41a(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0xf41e(%rip), %rdi      # 0x1dfd0
leaq 0x9117(%rip), %rsi      # 0x17cd0
callq 0x2220
movq %rax, %rdi
movq 0xf3f8(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x58(%rsp), %rax
cmpl $-0x1, 0x78(%rax)
jle 0xebf7
movq 0x58(%rsp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movslq 0x78(%rax), %rsi
callq 0x12f20
movq (%rax), %rdi
callq 0xb600
jmp 0xec1a
movq 0x58(%rsp), %rax
movl 0x78(%rax), %esi
movq 0xf3ca(%rip), %rdi      # 0x1dfd0
callq 0x2400
movq %rax, %rdi
movq 0xf3ab(%rip), %rsi      # 0x1dfc0
callq 0x2260
jmp 0xec1c
movq 0x58(%rsp), %rax
addq $0x88, %rax
movq %rax, 0x10(%rsp)
movl 0x8c(%rsp), %esi
movl 0x84(%rsp), %ecx
leaq 0x64(%rsp), %rdi
movl $0x21, %edx
callq 0x12e00
movq 0x10(%rsp), %rdi
leaq 0x64(%rsp), %rsi
callq 0x12fb0
movq 0x58(%rsp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0xecb6
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x28(%rax), %rax
movslq 0x84(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq 0x84(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x58(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x84(%rsp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x48(%rdi), %eax
movl %eax, 0x4(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x4(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x84(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x78(%rdi), %eax
movl %eax, 0x8(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0x8(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0x84(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
addq $0x88, %rdi
callq 0xb890
movq 0x58(%rsp), %rdi
subq $0x1, %rax
movl %eax, 0xc(%rsp)
movslq 0x8c(%rsp), %rsi
callq 0xaab0
movl 0xc(%rsp), %edx
movq 0x58(%rsp), %rdi
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq 0x84(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
movl 0x84(%rsp), %ecx
andb $0x1, %al
movzbl %al, %edx
callq 0x12fe0
movq 0x58(%rsp), %rdi
movl 0x8c(%rsp), %esi
movb 0x8b(%rsp), %al
xorb $-0x1, %al
movl 0x84(%rsp), %ecx
movzbl %al, %edx
andl $0x1, %edx
callq 0x13400
movq 0x58(%rsp), %rdi
movl 0x8c(%rsp), %esi
callq 0xde60
movl %eax, 0x60(%rsp)
cmpl $-0x1, 0x60(%rsp)
je 0xee6c
movq 0x58(%rsp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
testb $0x1, 0xa4(%rax)
je 0xee4b
movq 0xf1ca(%rip), %rdi      # 0x1dfd0
leaq 0x8ee0(%rip), %rsi      # 0x17ced
callq 0x2220
movq %rax, %rdi
movl 0x8c(%rsp), %esi
callq 0x2400
movq %rax, %rdi
leaq 0x8da6(%rip), %rsi      # 0x17bd1
callq 0x2220
movq %rax, %rdi
movl 0x60(%rsp), %esi
callq 0x2400
movq %rax, %rdi
movq 0xf17a(%rip), %rsi      # 0x1dfc0
callq 0x2260
movq 0x58(%rsp), %rdi
movl $0xfffffffe, 0x78(%rdi) # imm = 0xFFFFFFFE
movl 0x8c(%rsp), %esi
movl 0x60(%rsp), %ecx
movl $0x1, %edx
callq 0xe470
jmp 0xee6e
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)