// File: akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::undoTheory(int)
void Formula::undoTheory ( int level ) {

	// Undo theory to the level
	// for each variable v, for each domain d from dom(v): if this value has been assigned at level this or greater undo

	for ( unsigned int  i = 1; i < VARLIST.size(); i++ ) {

		for ( int j = 0; j < VARLIST[i] -> DOMAINSIZE; j++ ) {

			if ( VARLIST[i] -> ATOMLEVEL[j] > level ) {

				if ( VARLIST[i] -> ATOMASSIGN[j] == -1 )
					addLiteral ( i, true, j );
				else
					addLiteral ( i, false, j );
			}
		}
	}

	for ( unsigned int  i = 1; i < VARLIST.size(); i++ ) {

		for ( int j = 0; j < VARLIST[i] -> DOMAINSIZE; j++ ) {

			if ( VARLIST[i] -> ATOMLEVEL[j] > level ) {

				if ( VARLIST[i] -> ATOMASSIGN[j] == -1)
					unsatisfyClauses (i, false, j, level );
				else
					unsatisfyClauses ( i, true, j, level );

				VARLIST[i]->ATOMLEVEL[j] = -10;
				VARLIST[i]->ATOMASSIGN[j] = 0;
				VARLIST[i]->CLAUSEID[j] = -10;
				VARLIST[i] -> VAL = -1;
			}
		}
	}
	//undo the decision stack

	int decsize = DECSTACK.size();

	for ( int i = decsize-1; i > -1; i-- ) {
		if ( VARLIST[DECSTACK[i] . VAR] -> ATOMASSIGN[DECSTACK[i] . VAL] == 0 ) {
			DECSTACK.erase ( DECSTACK.begin() + i );
		}
	}
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movl %esi, 0x7c(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x1, 0x78(%rsp)
movq 0x38(%rsp), %rdi
movl 0x78(%rsp), %eax
movq %rax, 0x30(%rsp)
callq 0xaa90
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0xfc49
movl $0x0, 0x74(%rsp)
movq 0x38(%rsp), %rdi
movl 0x74(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x78(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq %rax, %rcx
movl 0x2c(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0xfc37
movq 0x38(%rsp), %rdi
movl 0x78(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x74(%rsp), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0x7c(%rsp), %eax
jle 0xfc25
movq 0x38(%rsp), %rdi
movl 0x78(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x74(%rsp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jne 0xfc0f
movq 0x38(%rsp), %rdi
movl 0x78(%rsp), %esi
movl 0x74(%rsp), %ecx
movl $0x1, %edx
callq 0x136d0
jmp 0xfc23
movq 0x38(%rsp), %rdi
movl 0x78(%rsp), %esi
movl 0x74(%rsp), %ecx
xorl %edx, %edx
callq 0x136d0
jmp 0xfc25
jmp 0xfc27
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0xfb84
jmp 0xfc39
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0xfb58
movl $0x1, 0x70(%rsp)
movq 0x38(%rsp), %rdi
movl 0x70(%rsp), %eax
movq %rax, 0x20(%rsp)
callq 0xaa90
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0xfdd1
movl $0x0, 0x6c(%rsp)
movq 0x38(%rsp), %rdi
movl 0x6c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x70(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq %rax, %rcx
movl 0x1c(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0xfdbf
movq 0x38(%rsp), %rdi
movl 0x70(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x6c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0x7c(%rsp), %eax
jle 0xfdad
movq 0x38(%rsp), %rdi
movl 0x70(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x6c(%rsp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jne 0xfd0e
movq 0x38(%rsp), %rdi
movl 0x70(%rsp), %esi
movl 0x6c(%rsp), %ecx
movl 0x7c(%rsp), %r8d
xorl %edx, %edx
callq 0x138f0
jmp 0xfd2a
movq 0x38(%rsp), %rdi
movl 0x70(%rsp), %esi
movl 0x6c(%rsp), %ecx
movl 0x7c(%rsp), %r8d
movl $0x1, %edx
callq 0x138f0
movq 0x38(%rsp), %rdi
movl 0x70(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq 0x6c(%rsp), %rcx
movl $0xfffffff6, (%rax,%rcx,4) # imm = 0xFFFFFFF6
movl 0x70(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq 0x6c(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x70(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movq 0x48(%rax), %rax
movslq 0x6c(%rsp), %rcx
movl $0xfffffff6, (%rax,%rcx,4) # imm = 0xFFFFFFF6
movl 0x70(%rsp), %eax
movl %eax, %esi
callq 0xaab0
movq (%rax), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
jmp 0xfdaf
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0xfc7d
jmp 0xfdc1
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0xfc51
movq 0x38(%rsp), %rdi
addq $0x88, %rdi
callq 0xb890
movl %eax, 0x68(%rsp)
movl 0x68(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x64(%rsp)
cmpl $-0x1, 0x64(%rsp)
jle 0xfec0
movq 0x38(%rsp), %rdi
addq $0x88, %rdi
movslq 0x64(%rsp), %rsi
callq 0xb8b0
movq 0x38(%rsp), %rdi
movslq (%rax), %rsi
callq 0xaab0
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movq 0x20(%rax), %rax
movq %rax, 0x10(%rsp)
addq $0x88, %rdi
movslq 0x64(%rsp), %rsi
callq 0xb8b0
movq %rax, %rcx
movq 0x10(%rsp), %rax
movslq 0x4(%rcx), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0xfeae
movq 0x38(%rsp), %rdi
movq %rdi, %rax
addq $0x88, %rax
movq %rax, 0x8(%rsp)
addq $0x88, %rdi
callq 0xc3c0
movq %rax, 0x48(%rsp)
movslq 0x64(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x13d90
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x13dd0
movq 0x8(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x13d20
movq %rax, 0x40(%rsp)
jmp 0xfeb0
movl 0x64(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0xfdf1
addq $0x88, %rsp
retq
nopl (%rax,%rax)