// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%rsi), %r12
movslq %ecx, %rbx
cmpq 0x8(%rsi), %r12
je 0x144f
movq %rsi, %r15
leaq 0x3d8f(%rip), %rbp      # 0x50f0
movslq (%r12), %rax
movq (%rbp,%rax,8), %rcx
movq (%rbp,%rbx,8), %rax
notq %rcx
testq %rcx, %rax
jne 0x1441
andq 0x8(%r12), %rax
cmpq %r14, %rax
jne 0x1441
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x10(%rsp), %r13
cmpq 0x18(%rsp), %r13
je 0x13fa
movslq (%r13), %rax
movq (%rbp,%rax,8), %rcx
movslq (%r12), %rax
movq (%rbp,%rax,8), %rax
notq %rcx
testq %rcx, %rax
jne 0x13cb
andq 0x8(%r13), %rax
cmpq 0x8(%r12), %rax
je 0x13f4
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x13e7
movups (%r13), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x38(%rsp)
jmp 0x13f4
leaq 0x30(%rsp), %rdi
movq %r13, %rdx
callq 0x25d0
addq $0x10, %r13
jmp 0x139f
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x240a
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1425
movups (%r12), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x1432
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0x25d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1441
callq 0x10c0
addq $0x10, %r12
cmpq 0x8(%r15), %r12
jne 0x1361
leaq (%rbx,%rbx,2), %rax
shlq $0x4, %rax
movq 0x8(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq 0x8(%rax), %rdx
movq %rax, %rcx
testq %rdx, %rdx
je 0x148a
movq %rax, %rcx
xorl %esi, %esi
cmpq %r14, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x1472
movq %rax, %rdx
cmpq %rax, %rcx
je 0x149d
cmpq %r14, 0x20(%rcx)
cmovaq %rax, %rcx
movq %rcx, %rdx
cmpq %rax, %rdx
je 0x14a7
movl 0x28(%rdx), %ebp
jmp 0x14a9
xorl %ebp, %ebp
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
cmpq %rax, %r15
je 0x1526
movq %r15, %rcx
movslq (%rcx), %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq 0x8(%rsp), %rsi
addq %rsi, %rdx
addq $0x8, %rdx
movq 0x8(%rdx), %rdi
movq %rdx, %rsi
testq %rdi, %rdi
je 0x14fe
movq 0x8(%rcx), %r8
movq %rdx, %rsi
xorl %r9d, %r9d
cmpq %r8, 0x20(%rdi)
setb %r9b
cmovaeq %rdi, %rsi
movq 0x10(%rdi,%r9,8), %rdi
testq %rdi, %rdi
jne 0x14e5
movq %rdx, %rdi
cmpq %rdx, %rsi
je 0x1515
movq 0x8(%rcx), %rdi
cmpq 0x20(%rsi), %rdi
cmovbq %rdx, %rsi
movq %rsi, %rdi
cmpq %rdx, %rdi
je 0x151d
subl 0x28(%rdi), %ebp
addq $0x10, %rcx
cmpq %rax, %rcx
jne 0x14bb
cmpq %rax, %r15
je 0x1632
addq $-0x28, 0x8(%rsp)
leaq 0x3bb4(%rip), %rcx      # 0x50f0
movq %r15, %rdx
leaq 0x10(%rdx), %r12
cmpq %rax, %r12
movq %r12, 0x50(%rsp)
je 0x1624
movq 0x8(%rdx), %r8
movq %rdx, 0x48(%rsp)
movslq (%rdx), %rsi
movq (%rcx,%rsi,8), %r9
movslq (%r12), %rsi
movq (%rcx,%rsi,8), %rdi
movq %rdi, %r11
andq %r8, %r11
movq 0x8(%r12), %r10
movq %r9, %rbx
andq %r10, %rbx
cmpq %rbx, %r11
jne 0x1617
orq %r9, %rdi
movq %rcx, %r14
movq 0x8(%rsp), %r11
movq (%r14), %r13
addq $0x30, %r11
addq $0x8, %r14
cmpq %rdi, %r13
jne 0x158e
orq %r8, %r10
xorl %r14d, %r14d
notq %r13
movq %r15, %rdi
movslq (%rdi), %rbx
movq (%rcx,%rbx,8), %rbx
testq %rbx, %r13
jne 0x15c5
andq %r10, %rbx
xorl %edx, %edx
cmpq %rbx, 0x8(%rdi)
sete %dl
addl %edx, %r14d
addq $0x10, %rdi
cmpq %rax, %rdi
jne 0x15aa
cmpl $0x2, %r14d
jl 0x1650
jne 0x1617
movq 0x8(%r11), %rdi
movq %r11, %rsi
testq %rdi, %rdi
je 0x15fc
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 0x15e5
movq %r11, %rdi
cmpq %rsi, %r11
je 0x160f
cmpq 0x20(%rsi), %r10
cmovbq %r11, %rsi
movq %rsi, %rdi
cmpq %rdi, %r11
je 0x1617
addl 0x28(%rdi), %ebp
addq $0x10, %r12
cmpq %rax, %r12
jne 0x1561
movq 0x50(%rsp), %rdx
cmpq %rax, %rdx
jne 0x153f
testq %r15, %r15
je 0x163f
movq %r15, %rdi
callq 0x10c0
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19e5(%rip), %rbx      # 0x303c
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1030
movl 0xc(%r12), %edi
movq 0x3963(%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 0x1acb(%rip), %rdi      # 0x31aa
movl %r14d, %esi
xorl %eax, %eax
callq 0x1030
leaq 0x1950(%rip), %rdi      # 0x3040
leaq 0x194f(%rip), %rsi      # 0x3046
leaq 0x1953(%rip), %rcx      # 0x3051
movl $0x67, %edx
callq 0x1090
jmp 0x170a
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x171c
callq 0x10c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x172b
callq 0x10c0
movq %rbx, %rdi
callq 0x11a0