// File: /workspace/github_c_makefile_star2_O2/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 %rsi, %r15
movq %rdi, 0x8(%rsp)
movq %rdx, 0x28(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq (%rsi), %r12
movslq %ecx, %rbx
leaq 0x4dc8(%rip), %r14      # 0x60f0
leaq 0x30(%rsp), %r13
cmpq 0x8(%r15), %r12
je 0x13d1
movslq (%r12), %rax
movq (%r14,%rax,8), %rcx
movq (%r14,%rbx,8), %rax
notq %rcx
testq %rcx, %rax
jne 0x13c8
andq 0x8(%r12), %rax
cmpq 0x28(%rsp), %rax
jne 0x13c8
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movq 0x10(%rsp), %rbp
cmpq 0x18(%rsp), %rbp
je 0x13a5
movslq (%rbp), %rax
movq (%r14,%rax,8), %rcx
movslq (%r12), %rax
movq (%r14,%rax,8), %rax
notq %rcx
testq %rcx, %rax
jne 0x1394
andq 0x8(%rbp), %rax
cmpq 0x8(%r12), %rax
je 0x139f
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2120
addq $0x10, %rbp
jmp 0x136a
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x213e
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2120
movq %r13, %rdi
callq 0x2308
addq $0x10, %r12
jmp 0x132d
imulq $0x30, %rbx, %r15
movq 0x8(%rsp), %rbx
addq %rbx, %r15
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x2486
addq $0x8, %r15
cmpq %r15, %rax
je 0x13f8
movl 0x28(%rax), %ebp
jmp 0x13fa
xorl %ebp, %ebp
movq 0x10(%rsp), %r12
cmpq 0x18(%rsp), %r12
je 0x1438
movslq (%r12), %rax
imulq $0x30, %rax, %rdi
addq %rbx, %rdi
leaq 0x8(%r12), %rsi
callq 0x2486
movslq (%r12), %rcx
imulq $0x30, %rcx, %rcx
addq %rbx, %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0x1432
subl 0x28(%rax), %ebp
addq $0x10, %r12
jmp 0x13ff
movl %ebp, 0x4(%rsp)
movq 0x10(%rsp), %r13
leaq -0x28(%rbx), %rax
movq %rax, 0x50(%rsp)
addq $-0x30, %rbx
movq %rbx, 0x8(%rsp)
cmpq %r12, %r13
je 0x153a
leaq 0x10(%r13), %rbx
movq %rbx, 0x48(%rsp)
cmpq %r12, %rbx
je 0x1530
movq 0x8(%r13), %rdi
movslq (%rbx), %rsi
movq (%r14,%rsi,8), %rdx
movq %rdx, %r8
andq %rdi, %r8
movq 0x8(%rbx), %rax
movslq (%r13), %rcx
movq (%r14,%rcx,8), %rcx
movq %rcx, %r9
andq %rax, %r9
cmpq %r9, %r8
jne 0x1522
orq %rdx, %rcx
movq %r14, %rdx
xorl %ebp, %ebp
addq $-0x30, %rbp
leaq 0x8(%rdx), %r8
cmpq %rcx, (%rdx)
movq %r8, %rdx
jne 0x14a2
movq 0x10(%rsp), %rdx
orq %rdi, %rax
xorl %r15d, %r15d
cmpq %r12, %rdx
je 0x14eb
movslq (%rdx), %rdi
movq (%r14,%rdi,8), %rdi
movq %rcx, %r8
notq %r8
testq %rdi, %r8
jne 0x14e5
andq %rax, %rdi
xorl %r8d, %r8d
cmpq %rdi, 0x8(%rdx)
sete %r8b
addl %r8d, %r15d
addq $0x10, %rdx
jmp 0x14bd
cmpl $0x2, %r15d
jl 0x1557
jne 0x1522
movq 0x8(%rsp), %rdi
subq %rbp, %rdi
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rsi
callq 0x2486
movq 0x50(%rsp), %rcx
subq %rbp, %rcx
cmpq %rax, %rcx
je 0x1522
movl 0x4(%rsp), %ecx
addl 0x28(%rax), %ecx
movl %ecx, 0x4(%rsp)
addq $0x10, %rbx
movq 0x18(%rsp), %r12
jmp 0x1465
movq 0x48(%rsp), %r13
jmp 0x1453
leaq 0x10(%rsp), %rdi
callq 0x2308
movl 0x4(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ade(%rip), %rdi      # 0x303c
xorl %eax, %eax
callq 0x1030
movl 0xc(%rbx), %edi
movq 0x4a61(%rip), %r12      # 0x5fd0
movq (%r12), %rsi
callq 0x12bc
pushq $0x20
popq %rbp
movl %ebp, %edi
callq 0x1150
movq 0x8(%rbx), %rdi
movq (%r12), %rsi
callq 0x12bc
pushq $0xa
popq %r14
movl %r14d, %edi
callq 0x1150
movl (%r13), %esi
leaq 0x1a96(%rip), %rdi      # 0x303c
xorl %eax, %eax
callq 0x1030
movl 0xc(%r13), %edi
movq (%r12), %rsi
callq 0x12bc
movl %ebp, %edi
callq 0x1150
movq 0x8(%r13), %rdi
movq (%r12), %rsi
callq 0x12bc
movl %r14d, %edi
callq 0x1150
leaq 0x1bcd(%rip), %rdi      # 0x31aa
movl %r15d, %esi
xorl %eax, %eax
callq 0x1030
leaq 0x1a52(%rip), %rdi      # 0x3040
leaq 0x1a51(%rip), %rsi      # 0x3046
leaq 0x1a55(%rip), %rcx      # 0x3051
pushq $0x67
popq %rdx
callq 0x1090
jmp 0x161b
jmp 0x161b
jmp 0x160c
jmp 0x161b
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2308
jmp 0x161e
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2308
movq %rbx, %rdi
callq 0x11a0
movq %rax, %rdi
callq 0x2201