// File: /workspace/github_c_makefile_star2_O3/ranbenbasat[P]RHHH/check2.cpp
// Function: conditionedcount(std::map<unsigned long long, Counter, std::less<unsigned long long>, std::allocator<std::pair<unsigned long long const, Counter>>> const*, std::vector<std::pair<int, unsigned long long>, std::allocator<std::pair<int, unsigned long long>>> const&, unsigned long long, int)
int conditionedcount(const map<Item, Counter> * m, const vector<Pair> &p, Item item, int mask) {
	vector<Pair> descendants; //the direct descendants of item,mask
	for (vector<Pair>::const_iterator it = p.begin(); it != p.end(); ++it) {
		if ((masks[it->first] & masks[mask]) == masks[mask] && (it->second & masks[mask]) == item) {
			//it is a descendant, now eliminate non-direct descendants
			vector<Pair> newdescendants;
			for (vector<Pair>::const_iterator iter = descendants.begin(); iter != descendants.end(); ++iter) {
				if ((masks[iter->first] & masks[it->first]) != masks[it->first] || (iter->second & masks[it->first]) != it->second) {
					newdescendants.push_back(*iter);
				}
			}
			descendants = newdescendants;
			descendants.push_back(*it);
		}
	}
	
	map<Item, Counter>::const_iterator ci = m[mask].find(item);
	int s = (ci != m[mask].end() ? ci->second.get() : 0);
	for (vector<Pair>::const_iterator iter = descendants.begin(); iter != descendants.end(); ++iter) {
		map<Item, Counter>::const_iterator ci = m[iter->first].find(iter->second);
		if (ci != m[iter->first].end()) s -= ci->second.get();
	}
	for (vector<Pair>::const_iterator iter = descendants.begin(); iter != descendants.end(); ++iter) {
		for (vector<Pair>::const_iterator it = iter + 1; it != descendants.end(); ++it) {
			//compute glb of iter and it
			if ( (iter->second & masks[it->first]) != (it->second & masks[iter->first]) ) continue;
			int glbmask = 0; while (masks[glbmask] != (masks[it->first] | masks[iter->first])) glbmask++;
			//glb has been computed now check that there is no third parent
			int numparents = 0;
			for (vector<Pair>::const_iterator it3 = descendants.begin(); it3 != descendants.end(); ++it3) {
				if (((masks[it3->first] | masks[glbmask]) == masks[glbmask])
					&& (it3->second == ((it->second | iter->second) & masks[it3->first]))) numparents++;
			}
			if (numparents < 2) {
				printf("%d ", it->first); printip(it->second >> 32); printf(" "); printip(it->second); printf("\n");
				printf("%d ", iter->first); printip(iter->second >> 32); printf(" "); printip(iter->second); printf("\n");
				printf("%d\n", numparents);
				assert(false);
			}
			if (numparents == 2) {
				map<Item, Counter>::const_iterator ci = m[glbmask].find(it->second | iter->second);
				if (ci != m[glbmask].end()) s+= ci->second.get();
			}
		}
	}

	return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%rsi), %r12
movq %rsi, 0x8(%rsp)
movq 0x8(%rsi), %rax
movslq %ecx, %r15
cmpq %rax, %r12
je 0x145a
leaq 0x3d8c(%rip), %rbp      # 0x50f0
movslq (%r12), %rcx
movq (%rbp,%rcx,8), %rdx
movq (%rbp,%r15,8), %rcx
notq %rdx
testq %rdx, %rcx
jne 0x144d
andq 0x8(%r12), %rcx
cmpq %r14, %rcx
jne 0x144d
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x10(%rsp), %r13
cmpq 0x18(%rsp), %r13
je 0x13fd
movslq (%r13), %rax
movq (%rbp,%rax,8), %rcx
movslq (%r12), %rax
movq (%rbp,%rax,8), %rax
notq %rcx
testq %rcx, %rax
jne 0x13ce
andq 0x8(%r13), %rax
cmpq 0x8(%r12), %rax
je 0x13f7
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x13ea
movups (%r13), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x38(%rsp)
jmp 0x13f7
leaq 0x30(%rsp), %rdi
movq %r13, %rdx
callq 0x25b0
addq $0x10, %r13
jmp 0x13a2
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x23ea
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1428
movups (%r12), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x1435
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0x25b0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1444
callq 0x10c0
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
addq $0x10, %r12
cmpq %rax, %r12
jne 0x1364
leaq (%r15,%r15,2), %rax
shlq $0x4, %rax
movq 0x10(%rbx,%rax), %rcx
xorl %edi, %edi
testq %rcx, %rcx
je 0x149f
leaq (%rbx,%rax), %rdx
addq $0x8, %rdx
movq %rdx, %rax
xorl %esi, %esi
cmpq %r14, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x1479
cmpq %rdx, %rax
je 0x149f
cmpq %r14, 0x20(%rax)
ja 0x149f
movl 0x28(%rax), %edi
movl %edi, 0x8(%rsp)
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
cmpq %rax, %r15
je 0x1618
movq %r15, %rcx
movslq (%rcx), %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq 0x10(%rbx,%rdx), %rsi
testq %rsi, %rsi
je 0x150c
leaq (%rbx,%rdx), %r8
addq $0x8, %r8
movq 0x8(%rcx), %rdi
movq %r8, %rdx
xorl %r9d, %r9d
cmpq %rdi, 0x20(%rsi)
setb %r9b
cmovaeq %rsi, %rdx
movq 0x10(%rsi,%r9,8), %rsi
testq %rsi, %rsi
jne 0x14dd
cmpq %r8, %rdx
je 0x150c
cmpq 0x20(%rdx), %rdi
jb 0x150c
movl 0x8(%rsp), %esi
subl 0x28(%rdx), %esi
movl %esi, 0x8(%rsp)
addq $0x10, %rcx
cmpq %rax, %rcx
jne 0x14b9
cmpq %rax, %r15
je 0x1618
addq $-0x28, %rbx
leaq 0x3bc7(%rip), %rcx      # 0x50f0
movq %r15, %rdx
leaq 0x10(%rdx), %r12
cmpq %rax, %r12
je 0x1618
movq 0x8(%rdx), %r8
movq %rdx, 0x48(%rsp)
movslq (%rdx), %rsi
movq (%rcx,%rsi,8), %r9
movq %r12, 0x50(%rsp)
movslq (%r12), %rsi
movq (%rcx,%rsi,8), %r13
movq %r13, %rdi
andq %r8, %rdi
movq 0x8(%r12), %r10
movq %r9, %r11
andq %r10, %r11
cmpq %r11, %rdi
jne 0x15fa
orq %r9, %r13
movq %rcx, %rdi
movq %rbx, %r11
addq $0x30, %r11
leaq 0x8(%rdi), %r14
cmpq %r13, (%rdi)
movq %r14, %rdi
jne 0x1579
orq %r8, %r10
xorl %r14d, %r14d
notq %r13
movq %r15, %rdi
movslq (%rdi), %rbp
movq (%rcx,%rbp,8), %rbp
testq %rbp, %r13
jne 0x15b0
andq %r10, %rbp
xorl %edx, %edx
cmpq %rbp, 0x8(%rdi)
sete %dl
addl %edx, %r14d
addq $0x10, %rdi
cmpq %rax, %rdi
jne 0x1595
cmpl $0x2, %r14d
jl 0x1638
jne 0x15fa
movq 0x8(%r11), %rdi
testq %rdi, %rdi
je 0x15fa
movq %r11, %rsi
xorl %edx, %edx
cmpq %r10, 0x20(%rdi)
setb %dl
cmovaeq %rdi, %rsi
movq 0x10(%rdi,%rdx,8), %rdi
testq %rdi, %rdi
jne 0x15cd
cmpq %rsi, %r11
je 0x15fa
cmpq 0x20(%rsi), %r10
jb 0x15fa
movl 0x8(%rsp), %edx
addl 0x28(%rsi), %edx
movl %edx, 0x8(%rsp)
addq $0x10, %r12
cmpq %rax, %r12
jne 0x154e
movq 0x50(%rsp), %rsi
movq %rsi, %rdx
cmpq %rax, %rsi
jne 0x152c
testq %r15, %r15
je 0x1625
movq %r15, %rdi
callq 0x10c0
movl 0x8(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19fd(%rip), %rbx      # 0x303c
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1030
movl 0xc(%r12), %edi
movq 0x397b(%rip), %r13      # 0x4fd0
movq (%r13), %rsi
callq 0x12ec
movl $0x20, %edi
callq 0x1150
movq 0x8(%r12), %rdi
movq (%r13), %rsi
callq 0x12ec
movl $0xa, %edi
callq 0x1150
movq 0x48(%rsp), %r15
movl (%r15), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1030
movl 0xc(%r15), %edi
movq (%r13), %rsi
callq 0x12ec
movl $0x20, %edi
callq 0x1150
movq 0x8(%r15), %rdi
movq (%r13), %rsi
callq 0x12ec
movl $0xa, %edi
callq 0x1150
leaq 0x1ae3(%rip), %rdi      # 0x31aa
movl %r14d, %esi
xorl %eax, %eax
callq 0x1030
leaq 0x1968(%rip), %rdi      # 0x3040
leaq 0x1967(%rip), %rsi      # 0x3046
leaq 0x196b(%rip), %rcx      # 0x3051
movl $0x67, %edx
callq 0x1090
jmp 0x16f2
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1704
callq 0x10c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1713
callq 0x10c0
movq %rbx, %rdi
callq 0x11a0