// File: /workspace/github_cpp_makefile_star2_O3/derekzwy[P]an-optimal-tcam-encoding-algorithm-for-packet-classification/cps-tss.cc
// Function: tuples_num(std::vector<pc_rule*, std::allocator<pc_rule*>>&)
void tuples_num(vector<pc_rule*> &pc) 
{ 
    array<int, MAXDIMENSIONS> tuple;
    map<array<int, MAXDIMENSIONS>, int> tuple_map;


    for(auto rule = pc.begin(); rule != pc.end(); rule++) {
        for(int i = 0; i< MAXDIMENSIONS; i++) {
            int prefixlen;
            if(i == 0 || i == 1) 
                prefixlen = 32 - __builtin_popcount((*rule)->field[i].high - (*rule)->field[i].low);
            if(i == 2 || i == 3)
                prefixlen = 16 - __builtin_popcount((*rule)->field[i].high - (*rule)->field[i].low);
            if( i == 4) 
                prefixlen = 8 - __builtin_popcount((*rule)->field[i].high - (*rule)->field[i].low);
            tuple[i] = prefixlen;
        }

        tuple_map[tuple] ++;
    }

    cout <<"tuple numbers: "<< tuple_map.size()<< endl;

    /*for(auto tuple_pair = tuple_map.begin(); tuple_pair != tuple_map.end(); tuple_pair ++) {
        for_each(tuple_pair->first.begin(), tuple_pair->first.end(), [](int i ){cout<<i<<" ";});
        cout<< "  " << tuple_pair->second<<endl;
    }*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq -0x68(%rbp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq (%rdi), %r12
cmpq 0x8(%rdi), %r12
je 0x286b
movq %rdi, %rbx
movl $0x33333333, %r13d      # imm = 0x33333333
leaq -0x3c(%rbp), %r15
movl $0x4, %ecx
xorl %eax, %eax
cmpq $0x1, %rax
ja 0x27a4
movq (%r12), %rdx
movl (%rdx,%rcx,4), %esi
subl -0x8(%rdx,%rcx,4), %esi
notl %esi
movl %esi, %edx
shrl %edx
andl $0x55555555, %edx       # imm = 0x55555555
subl %edx, %esi
movl %esi, %edx
andl %r13d, %edx
shrl $0x2, %esi
andl %r13d, %esi
addl %edx, %esi
movl %esi, %edx
shrl $0x4, %edx
addl %esi, %edx
andl $0xf0f0f0f, %edx        # imm = 0xF0F0F0F
imull $0x1010101, %edx, %r14d # imm = 0x1010101
shrl $0x18, %r14d
movl %eax, %edx
andl $0x6, %edx
cmpl $0x2, %edx
jne 0x27f1
movq (%r12), %rdx
movl (%rdx,%rcx,4), %esi
subl -0x8(%rdx,%rcx,4), %esi
movl %esi, %edx
shrl %edx
andl $0x55555555, %edx       # imm = 0x55555555
subl %edx, %esi
movl %esi, %edx
andl %r13d, %edx
shrl $0x2, %esi
andl %r13d, %esi
addl %edx, %esi
movl %esi, %edx
shrl $0x4, %edx
addl %esi, %edx
andl $0xf0f0f0f, %edx        # imm = 0xF0F0F0F
imull $0x1010101, %edx, %edx  # imm = 0x1010101
shrl $0x18, %edx
movl $0x10, %r14d
subl %edx, %r14d
cmpq $0x4, %rax
je 0x2808
movl %r14d, -0x3c(%rbp,%rax,4)
incq %rax
addq $0x4, %rcx
jmp 0x2760
movq (%r12), %rcx
movl 0x50(%rcx), %edx
subl 0x48(%rcx), %edx
movl %edx, %ecx
shrl %ecx
andl $0x55555555, %ecx       # imm = 0x55555555
subl %ecx, %edx
movl %edx, %ecx
andl %r13d, %ecx
shrl $0x2, %edx
andl %r13d, %edx
addl %ecx, %edx
movl %edx, %ecx
shrl $0x4, %ecx
addl %edx, %ecx
andl $0xf0f0f0f, %ecx        # imm = 0xF0F0F0F
imull $0x1010101, %ecx, %ecx  # imm = 0x1010101
shrl $0x18, %ecx
movl $0x8, %r14d
subl %ecx, %r14d
movl %r14d, -0x3c(%rbp,%rax,4)
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x2ce0
incl (%rax)
addq $0x8, %r12
cmpq 0x8(%rbx), %r12
jne 0x2759
movq 0x7766(%rip), %rdi      # 0x9fd8
leaq 0x47d6(%rip), %rsi      # 0x704f
movl $0xf, %edx
callq 0x2190
movq -0x48(%rbp), %rsi
movq 0x774a(%rip), %rdi      # 0x9fd8
callq 0x20c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2140
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq -0x70(%rbp), %rdi
callq 0x2d8a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x28d7
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2d8a
movq %rbx, %rdi
callq 0x2240