// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq (%rdi), %r12
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r15
subq %r12, %r15
sarq $0x3, %r15
cmpq $0x2, %r15
jb 0x9787
movl $0x1, %edx
movl $0x1, %eax
movq (%r12,%rax,8), %rdi
cmpl $0x0, 0x8(%rdi)
jle 0x9779
movq 0x18(%rdi), %r8
movslq %edx, %r9
movq 0x8(%rsp), %rax
movq 0x18(%rax), %r10
xorl %r11d, %r11d
cmpl %esi, (%r8,%r11,4)
jle 0x9769
movq 0x20(%rdi), %rax
cmpl $-0x1, (%rax,%r11,4)
je 0x9718
movq (%r12,%r9,8), %rax
movq 0x68(%rax), %rcx
leaq (%r11,%r11,2), %rbx
movq (%rcx,%rbx,8), %rax
movq 0x8(%rcx,%rbx,8), %rcx
cmpq %rcx, %rax
je 0x9769
movq 0x8(%rsp), %rbx
movl 0xa8(%rbx), %ebp
movq (%rbx), %r14
movslq (%rax), %rbx
movq (%r10,%rbx,8), %rbx
cmpl $-0x1, 0x1c(%rbx)
jne 0x970d
incl 0x18(%rbx)
testl %ebp, %ebp
jne 0x970d
movq (%r14,%r9,8), %rbx
movq 0x30(%rbx), %rbx
incl (%rbx,%r11,4)
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x96ed
jmp 0x9769
movq (%r12,%r9,8), %rax
movq 0x60(%rax), %rcx
leaq (%r11,%r11,2), %rbx
movq (%rcx,%rbx,8), %rax
movq 0x8(%rcx,%rbx,8), %rcx
cmpq %rcx, %rax
je 0x9769
movq 0x8(%rsp), %rbx
movl 0xa8(%rbx), %ebp
movq (%rbx), %r14
movslq (%rax), %rbx
movq (%r10,%rbx,8), %rbx
cmpl $-0x1, 0x1c(%rbx)
jne 0x9760
incl 0x18(%rbx)
testl %ebp, %ebp
jne 0x9760
movq (%r14,%r9,8), %rbx
movq 0x28(%rbx), %rbx
incl (%rbx,%r11,4)
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x9740
incq %r11
movslq 0x8(%rdi), %rax
cmpq %rax, %r11
jl 0x96ac
incl %edx
movq %rdx, %rax
cmpq %rdx, %r15
ja 0x968b
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
cmpq $0x2, %r15
jb 0x9a14
movl $0x1, %eax
movq %rax, 0x10(%rsp)
movl $0x1, %eax
movq %r12, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movq (%r12,%rax,8), %rdi
cmpl $0x0, 0x8(%rdi)
jle 0x99f7
movq 0x18(%rdi), %r8
movslq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %r14
xorl %r15d, %r15d
movq %rdi, 0x38(%rsp)
movq %r8, 0x30(%rsp)
cmpl %esi, (%r8,%r15,4)
jle 0x99e7
movq 0x20(%rdi), %rax
cmpl $-0x1, (%rax,%r15,4)
movq %rax, 0x40(%rsp)
je 0x98de
movq 0x18(%rsp), %rax
movq (%r12,%rax,8), %rax
movq 0x60(%rax), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %r13
movq 0x8(%rax,%rcx,8), %rbp
cmpq %rbp, %r13
je 0x99b3
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movslq (%r13), %rax
movq (%r14,%rax,8), %r8
cmpl %esi, 0x1c(%r8)
jle 0x98cc
movq (%r8), %r10
cmpq %r10, 0x8(%r8)
je 0x98c4
movq 0x8(%rsp), %rax
movl 0xa8(%rax), %edi
movl $0x8, %r11d
xorl %eax, %eax
movslq -0x8(%r10,%r11), %r9
movb (%r10,%r11), %bl
movslq -0x4(%r10,%r11), %r10
movq (%rcx,%r9,8), %r12
movq 0x18(%r12), %r9
cmpl %esi, (%r9,%r10,4)
jg 0x9886
movq 0x20(%r12), %r9
cmpl $0x0, (%r9,%r10,4)
jne 0x989e
incl 0x18(%r8)
testl %edi, %edi
jne 0x989e
xorb $0x1, %bl
movzbl %bl, %r8d
movq 0x28(%r12,%r8,8), %r8
incl (%r8,%r10,4)
incq %rax
movslq (%r13), %r8
movq (%r14,%r8,8), %r8
movq (%r8), %r10
movq 0x8(%r8), %r9
subq %r10, %r9
sarq $0x2, %r9
imulq %rdx, %r9
addq $0xc, %r11
cmpq %rax, %r9
ja 0x985d
movl $0xffffffff, 0x1c(%r8)  # imm = 0xFFFFFFFF
addq $0x4, %r13
cmpq %rbp, %r13
jne 0x982f
jmp 0x99b3
movq 0x18(%rsp), %rax
movq (%r12,%rax,8), %rax
movq 0x68(%rax), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %r13
movq 0x8(%rax,%rcx,8), %rbp
cmpq %rbp, %r13
je 0x99b3
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movslq (%r13), %rax
movq (%r14,%rax,8), %r8
cmpl %esi, 0x1c(%r8)
jle 0x99a6
movq (%r8), %r10
cmpq %r10, 0x8(%r8)
je 0x999e
movq 0x8(%rsp), %rax
movl 0xa8(%rax), %edi
movl $0x8, %r11d
xorl %eax, %eax
movslq -0x8(%r10,%r11), %r12
movb (%r10,%r11), %bl
movslq -0x4(%r10,%r11), %r10
movq (%rcx,%r12,8), %r12
movq 0x18(%r12), %r9
cmpl %esi, (%r9,%r10,4)
jg 0x9960
movq 0x20(%r12), %r9
cmpl $0x0, (%r9,%r10,4)
jne 0x9978
incl 0x18(%r8)
testl %edi, %edi
jne 0x9978
xorb $0x1, %bl
movzbl %bl, %r8d
movq 0x28(%r12,%r8,8), %r8
incl (%r8,%r10,4)
incq %rax
movslq (%r13), %r8
movq (%r14,%r8,8), %r8
movq (%r8), %r10
movq 0x8(%r8), %r9
subq %r10, %r9
sarq $0x2, %r9
imulq %rdx, %r9
addq $0xc, %r11
cmpq %rax, %r9
ja 0x9937
movl $0xffffffff, 0x1c(%r8)  # imm = 0xFFFFFFFF
addq $0x4, %r13
cmpq %rbp, %r13
jne 0x9909
movl $0xfffffff6, %ecx       # imm = 0xFFFFFFF6
movq 0x30(%rsp), %r8
movl %ecx, (%r8,%r15,4)
movq 0x40(%rsp), %rax
movl $0x0, (%rax,%r15,4)
movq 0x38(%rsp), %rdi
movq 0x48(%rdi), %rax
movl %ecx, (%rax,%r15,4)
movl $0xffffffff, 0x4(%rdi)  # imm = 0xFFFFFFFF
movq 0x28(%rsp), %r12
incq %r15
movslq 0x8(%rdi), %rax
cmpq %rax, %r15
jl 0x97e6
movq 0x10(%rsp), %rcx
incl %ecx
movq %rcx, %rax
movq 0x20(%rsp), %r15
movq %rcx, 0x10(%rsp)
cmpq %rcx, %r15
ja 0x97b4
movq 0x8(%rsp), %rcx
movq 0x90(%rcx), %rax
subq 0x88(%rcx), %rax
sarq $0x2, %rax
imulq %rdx, %rax
testl %eax, %eax
jle 0x9abb
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq 0x1(%rax), %r14
shlq $0x2, %rax
leaq (%rax,%rax,2), %r15
movq %r15, %r12
negq %r12
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq 0x88(%rax), %rax
movslq -0xc(%rax,%r15), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x20(%rcx), %rcx
movslq -0x8(%rax,%r15), %rdx
cmpl $0x0, (%rcx,%rdx,4)
jne 0x9aaa
leaq (%rax,%r15), %rsi
movq 0x8(%rsp), %rcx
movq 0x90(%rcx), %rdx
cmpq %rdx, %rsi
je 0x9a9d
leaq (%rax,%r15), %rdi
addq $-0xc, %rdi
subq %rax, %rdx
addq %r12, %rdx
callq 0x2350
movq 0x8(%rsp), %rax
addq $-0xc, 0x90(%rax)
decq %r14
addq $-0xc, %r15
addq $0xc, %r12
cmpq $0x1, %r14
jg 0x9a4e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq