// File: akinanop[P]mvl-solver/src/Formula.cc
// Function: Formula::resolve(Clause*, Literal, Clause*)
Clause* Formula::resolve ( Clause* clause, Literal literal, Clause* reason ) {

	//  Performs extended resolution on clause and reason wrt literal.
	// (See pp.47-50 of Jain: https://github.com/akinanop/mvl-solver/blob/master/literature/Jain_thesis.pdf)

	Clause * resolvent = new Clause();

	Literal neg_lit = literal;
	neg_lit.EQUAL = !literal.EQUAL;

	// Add literals L' from the clause that are satisfied by at least one interpretation that does not satisfy the resolution literal L, i.e., doesn't falsify NOT L.
	for ( unsigned int i = 0; i < clause -> ATOM_LIST.size(); i++ ) {

		Literal c_atom = clause -> ATOM_LIST[i];

		if ( ! falsifies ( c_atom, neg_lit ) ) resolvent -> addAtom ( c_atom );

	}

	// Add literals L' from the reason clause that are satisfied by at least one interpretation that also satisfies the resolution literal L, i.e., doesn't falsify L.
	for ( unsigned int  i = 0; i < reason -> ATOM_LIST.size(); i++ ) {

		Literal r_atom = reason -> ATOM_LIST[i];

		if ( ! falsifies ( r_atom, literal ) && ! hasAtom ( resolvent, r_atom ) ) resolvent -> addAtom ( r_atom );

	}

	return resolvent;
}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movb %cl, %al
movq %rdx, 0x148(%rsp)
movb %al, 0x150(%rsp)
movl 0x150(%rsp), %eax
movl %eax, 0x160(%rsp)
movq 0x148(%rsp), %rax
movq %rax, 0x158(%rsp)
movq %rdi, 0x140(%rsp)
movq %rsi, 0x138(%rsp)
movq %r8, 0x130(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x38, %edi
callq 0x2230
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
callq 0xb420
jmp 0xefa7
movq 0x20(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x158(%rsp), %rax
movq %rax, 0x110(%rsp)
movl 0x160(%rsp), %eax
movl %eax, 0x118(%rsp)
movb 0x160(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x118(%rsp)
movl $0x0, 0x10c(%rsp)
movl 0x10c(%rsp), %eax
movq %rax, 0x10(%rsp)
movq 0x138(%rsp), %rdi
callq 0xb890
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0xf18c
movq 0x138(%rsp), %rdi
movl 0x10c(%rsp), %eax
movl %eax, %esi
callq 0xb8b0
movq 0x18(%rsp), %rdi
movq (%rax), %rcx
movq %rcx, 0x100(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x108(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0xf4(%rsp)
movl 0x108(%rsp), %eax
movl %eax, 0xfc(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0xe8(%rsp)
movl 0x118(%rsp), %eax
movl %eax, 0xf0(%rsp)
movq 0xf4(%rsp), %rax
movq %rax, 0xd8(%rsp)
movl 0xfc(%rsp), %eax
movl %eax, 0xe0(%rsp)
movq 0xd8(%rsp), %rsi
movb 0xe0(%rsp), %al
movq 0xe8(%rsp), %rcx
movq %rcx, 0xc8(%rsp)
movl 0xf0(%rsp), %ecx
movl %ecx, 0xd0(%rsp)
movq 0xc8(%rsp), %rcx
movzbl %al, %edx
movzbl 0xd0(%rsp), %r8d
callq 0xf350
testb $0x1, %al
jne 0xf174
movq 0x128(%rsp), %rdi
movq 0x100(%rsp), %rax
movq %rax, 0xbc(%rsp)
movl 0x108(%rsp), %eax
movl %eax, 0xc4(%rsp)
movq 0xbc(%rsp), %rax
movq %rax, 0xac(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, 0xb4(%rsp)
movq 0xac(%rsp), %rsi
movzbl 0xb4(%rsp), %edx
callq 0xb5b0
jmp 0xf174
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
movl $0x38, %esi
callq 0x2240
jmp 0xf334
jmp 0xf176
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0xefef
movl $0x0, 0xa8(%rsp)
movl 0xa8(%rsp), %eax
movq %rax, 0x8(%rsp)
movq 0x130(%rsp), %rdi
callq 0xb890
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0xf324
movq 0x130(%rsp), %rdi
movl 0xa8(%rsp), %eax
movl %eax, %esi
callq 0xb8b0
movq 0x18(%rsp), %rdi
movq (%rax), %rcx
movq %rcx, 0x9c(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0xa4(%rsp)
movq 0x9c(%rsp), %rax
movq %rax, 0x90(%rsp)
movl 0xa4(%rsp), %eax
movl %eax, 0x98(%rsp)
movq 0x158(%rsp), %rax
movq %rax, 0x84(%rsp)
movl 0x160(%rsp), %eax
movl %eax, 0x8c(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x74(%rsp)
movl 0x98(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0x74(%rsp), %rsi
movb 0x7c(%rsp), %al
movq 0x84(%rsp), %rcx
movq %rcx, 0x64(%rsp)
movl 0x8c(%rsp), %ecx
movl %ecx, 0x6c(%rsp)
movq 0x64(%rsp), %rcx
movzbl %al, %edx
movzbl 0x6c(%rsp), %r8d
callq 0xf350
testb $0x1, %al
jne 0xf30c
movq 0x18(%rsp), %rdi
movq 0x128(%rsp), %rsi
movq 0x9c(%rsp), %rax
movq %rax, 0x58(%rsp)
movl 0xa4(%rsp), %eax
movl %eax, 0x60(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x50(%rsp)
movq 0x48(%rsp), %rdx
movzbl 0x50(%rsp), %ecx
callq 0xee80
testb $0x1, %al
jne 0xf30c
movq 0x128(%rsp), %rdi
movq 0x9c(%rsp), %rax
movq %rax, 0x3c(%rsp)
movl 0xa4(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x3c(%rsp), %rax
movq %rax, 0x2c(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x2c(%rsp), %rsi
movzbl 0x34(%rsp), %edx
callq 0xb5b0
jmp 0xf30e
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0xf197
movq 0x128(%rsp), %rax
addq $0x168, %rsp            # imm = 0x168
retq
movq 0x120(%rsp), %rdi
callq 0x2410
nopw %cs:(%rax,%rax)