// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq (%rdi), %rcx
movq %rdi, (%rsp)
movq 0x8(%rdi), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
movq %rdx, 0x10(%rsp)
cmpq $0x2, %rdx
jb 0x9927
movl $0x1, %edi
movl $0x1, %edx
movq (%rcx,%rdx,8), %r8
cmpl $0x0, 0x8(%r8)
jle 0x96c9
movq 0x18(%r8), %r9
movslq %edi, %r10
movq (%rsp), %rdx
movq 0x18(%rdx), %r11
xorl %r14d, %r14d
cmpl %esi, (%r9,%r14,4)
jle 0x96b9
movq 0x20(%r8), %rdx
cmpl $-0x1, (%rdx,%r14,4)
movq (%rcx,%r10,8), %r15
je 0x9671
movq 0x68(%r15), %r12
leaq (%r14,%r14,2), %r13
movq (%r12,%r13,8), %rdx
movq 0x8(%r12,%r13,8), %r12
cmpq %r12, %rdx
je 0x96b9
movq (%rsp), %rbx
movl 0xa8(%rbx), %ebp
movslq (%rdx), %r13
movq (%r11,%r13,8), %r13
cmpl $-0x1, 0x1c(%r13)
jne 0x9666
incl 0x18(%r13)
testl %ebp, %ebp
jne 0x9666
movq 0x30(%r15), %r13
incl (%r13,%r14,4)
addq $0x4, %rdx
cmpq %r12, %rdx
jne 0x9647
jmp 0x96b9
movq 0x60(%r15), %r12
leaq (%r14,%r14,2), %r13
movq (%r12,%r13,8), %rdx
movq 0x8(%r12,%r13,8), %r12
cmpq %r12, %rdx
je 0x96b9
movq (%rsp), %rbx
movl 0xa8(%rbx), %ebp
movslq (%rdx), %r13
movq (%r11,%r13,8), %r13
cmpl $-0x1, 0x1c(%r13)
jne 0x96b0
incl 0x18(%r13)
testl %ebp, %ebp
jne 0x96b0
movq 0x28(%r15), %r13
incl (%r13,%r14,4)
addq $0x4, %rdx
cmpq %r12, %rdx
jne 0x9691
incq %r14
movslq 0x8(%r8), %rdx
cmpq %rdx, %r14
jl 0x960e
incl %edi
movq %rdi, %rdx
cmpq %rdi, 0x10(%rsp)
ja 0x95ed
cmpq $0x2, 0x10(%rsp)
jb 0x9927
movl $0x1, %edx
movq %rdx, 0x8(%rsp)
movl $0x1, %edx
movq (%rcx,%rdx,8), %r8
movl 0x8(%r8), %edx
testl %edx, %edx
jle 0x990d
movq 0x18(%r8), %r9
movslq 0x8(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movq (%rsp), %rdi
movq 0x18(%rdi), %r14
xorl %r15d, %r15d
movq %r8, 0x28(%rsp)
movq %r9, 0x20(%rsp)
cmpl %esi, (%r9,%r15,4)
jle 0x98fe
movq 0x20(%r8), %rdi
cmpl $-0x1, (%rdi,%r15,4)
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
movq %rdi, 0x30(%rsp)
je 0x980c
movq 0x60(%rdx), %rdx
leaq (%r15,%r15,2), %rdi
movq (%rdx,%rdi,8), %r13
movq 0x8(%rdx,%rdi,8), %rbp
cmpq %rbp, %r13
je 0x98ca
movslq (%r13), %rdx
movq (%r14,%rdx,8), %rdi
cmpl %esi, 0x1c(%rdi)
jle 0x9803
movq (%rdi), %r10
cmpq %r10, 0x8(%rdi)
je 0x97fc
movq (%rsp), %rdx
movl 0xa8(%rdx), %edx
movl $0x8, %r8d
xorl %r11d, %r11d
movslq -0x8(%r10,%r8), %rbx
movb (%r10,%r8), %r9b
movslq -0x4(%r10,%r8), %r10
movq (%rcx,%rbx,8), %r12
movq 0x18(%r12), %rbx
cmpl %esi, (%rbx,%r10,4)
jg 0x97be
movq 0x20(%r12), %rbx
cmpl $0x0, (%rbx,%r10,4)
jne 0x97d6
incl 0x18(%rdi)
testl %edx, %edx
jne 0x97d6
xorb $0x1, %r9b
movzbl %r9b, %edi
movq 0x28(%r12,%rdi,8), %rdi
incl (%rdi,%r10,4)
incq %r11
movslq (%r13), %rdi
movq (%r14,%rdi,8), %rdi
movq (%rdi), %r10
movq 0x8(%rdi), %r9
subq %r10, %r9
sarq $0x2, %r9
imulq %rax, %r9
addq $0xc, %r8
cmpq %r11, %r9
ja 0x9795
movl $0xffffffff, 0x1c(%rdi) # imm = 0xFFFFFFFF
addq $0x4, %r13
jmp 0x975f
movq 0x68(%rdx), %rdx
leaq (%r15,%r15,2), %rdi
movq (%rdx,%rdi,8), %r13
movq 0x8(%rdx,%rdi,8), %rbp
cmpq %rbp, %r13
je 0x98ca
movslq (%r13), %rdx
movq (%r14,%rdx,8), %rdi
cmpl %esi, 0x1c(%rdi)
jle 0x98c1
movq (%rdi), %r10
cmpq %r10, 0x8(%rdi)
je 0x98ba
movq (%rsp), %rdx
movl 0xa8(%rdx), %edx
movl $0x8, %r8d
xorl %r11d, %r11d
movslq -0x8(%r10,%r8), %r12
movb (%r10,%r8), %r9b
movslq -0x4(%r10,%r8), %r10
movq (%rcx,%r12,8), %r12
movq 0x18(%r12), %rbx
cmpl %esi, (%rbx,%r10,4)
jg 0x987c
movq 0x20(%r12), %rbx
cmpl $0x0, (%rbx,%r10,4)
jne 0x9894
incl 0x18(%rdi)
testl %edx, %edx
jne 0x9894
xorb $0x1, %r9b
movzbl %r9b, %edi
movq 0x28(%r12,%rdi,8), %rdi
incl (%rdi,%r10,4)
incq %r11
movslq (%r13), %rdi
movq (%r14,%rdi,8), %rdi
movq (%rdi), %r10
movq 0x8(%rdi), %r9
subq %r10, %r9
sarq $0x2, %r9
imulq %rax, %r9
addq $0xc, %r8
cmpq %r11, %r9
ja 0x9853
movl $0xffffffff, 0x1c(%rdi) # imm = 0xFFFFFFFF
addq $0x4, %r13
jmp 0x981d
movl $0xfffffff6, %edi       # imm = 0xFFFFFFF6
movq 0x20(%rsp), %r9
movl %edi, (%r9,%r15,4)
movq 0x30(%rsp), %rdx
movl $0x0, (%rdx,%r15,4)
movq 0x28(%rsp), %r8
movq 0x48(%r8), %rdx
movl %edi, (%rdx,%r15,4)
movl $0xffffffff, 0x4(%r8)   # imm = 0xFFFFFFFF
movl 0x8(%r8), %edx
incq %r15
movslq %edx, %rdi
cmpq %rdi, %r15
jl 0x9727
movq 0x8(%rsp), %rdi
incl %edi
movq %rdi, %rdx
movq %rdi, 0x8(%rsp)
cmpq %rdi, 0x10(%rsp)
ja 0x96f4
movq (%rsp), %rdi
movq 0x90(%rdi), %rdx
movq %rdx, %rcx
subq 0x88(%rdi), %rcx
sarq $0x2, %rcx
imulq %rax, %rcx
testl %ecx, %ecx
jle 0x99c5
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq 0x1(%rcx), %r14
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %r15
movq %r15, %r12
negq %r12
movq (%rdi), %rcx
movq 0x88(%rdi), %rax
movslq -0xc(%rax,%r15), %rsi
movq (%rcx,%rsi,8), %rcx
movq 0x20(%rcx), %rcx
movslq -0x8(%rax,%r15), %rsi
cmpl $0x0, (%rcx,%rsi,4)
jne 0x99b4
leaq (%rax,%r15), %rsi
cmpq %rdx, %rsi
je 0x99a9
leaq (%rax,%r15), %rdi
addq $-0xc, %rdi
subq %rax, %rdx
addq %r12, %rdx
callq 0x2350
movq (%rsp), %rdi
movq 0x90(%rdi), %rdx
addq $-0xc, %rdx
movq %rdx, 0x90(%rdi)
decq %r14
addq $-0xc, %r15
addq $0xc, %r12
cmpq $0x1, %r14
ja 0x9960
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq