// File: /workspace/github_cpp_makefile_star2_O3/derekzwy[P]an-optimal-tcam-encoding-algorithm-for-packet-classification/rulesutils.cc
// Function: remove_redund_rt(std::vector<pc_rule*, std::allocator<pc_rule*>>&, rule_boundary&, bool)
void remove_redund_rt(vector<pc_rule*> &pr, rule_boundary &b, bool large) 
{
    vector<pc_rule*> rulelist;
    
    range br;
    
    rnode rt[2];
    vector<pc_rule*> set[2];
    //map<int, int> sect;
    vector<pc_rule*> sect;

    init_rnode(rt, b);
    //int count = 0;

    for(auto rule = pr.begin(); rule != pr.end(); ++ rule) {
        sect.clear();
        for(int i = 0; i < 2; i++) {
            br = range_in_boundary_1D((*rule)->field[i], b.field[i]); 
            set[i].clear();
            rt_qry_insert(rt+i, rg(br.low, 
                    br.high), set[i], (*rule));
        }

        sort(set[0].begin(), set[0].end());
        sort(set[1].begin(), set[1].end());
        set_intersection(set[0].begin(), set[0].end(),
                set[1].begin(), set[1].end(),
                back_inserter(sect));

        if(sect.empty()) {
            rulelist.push_back(*rule);
        }
        else {
            bool found = false;
            for(auto check_rule = sect.begin();
                    check_rule != sect.end();
                    check_rule++) {
                if(is_equal(**check_rule, **rule, b)) {
                    found = true;
                    //count++;
                    //cout<<(*rule)->priority<<" was hide by " <<*check_rule<<endl;
                    break;
                }
            }

            if(!found) {
                rulelist.push_back(*rule);
            }
        }

    }

    rt_destory(rt[0].left);
    rt_destory(rt[0].right);
    rt_destory(rt[1].left);
    rt_destory(rt[1].right);

    pr = move(rulelist);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rsi, %r14
movq %rdi, %r8
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
xorl %edi, %edi
movq %rdi, -0x30(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
movaps %xmm0, -0xf0(%rbp)
movaps %xmm0, -0x100(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movq %rdi, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movl (%rsi), %eax
movq 0x8(%rsi), %rcx
movl 0x10(%rsi), %edx
movq 0x18(%rsi), %rsi
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, -0x100(%rbp)
shlq $0x20, %rsi
orq %rdx, %rsi
movq %rsi, -0xd0(%rbp)
movq (%r8), %r15
movq %r8, -0x68(%rbp)
cmpq 0x8(%r8), %r15
je 0x39e7
leaq -0xd0(%rbp), %r12
leaq -0x88(%rbp), %r13
movq -0x60(%rbp), %rax
cmpq %rax, -0x58(%rbp)
je 0x37b3
movq %rax, -0x58(%rbp)
movb $0x1, %bl
leaq -0xa0(%rbp), %rdx
leaq -0x100(%rbp), %rdi
xorl %eax, %eax
movq (%r15), %rcx
shlq $0x4, %rax
movq 0x8(%rcx,%rax), %r8
movq 0x10(%rcx,%rax), %r9
movq (%r14,%rax), %rsi
cmpq %rsi, %r8
cmovaq %r8, %rsi
movq 0x8(%r14,%rax), %rax
cmpq %rax, %r9
cmovbq %r9, %rax
movq (%rdx), %r8
cmpq %r8, 0x8(%rdx)
je 0x37fa
movq %r8, 0x8(%rdx)
movl %esi, -0x70(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x70(%rbp), %rsi
callq 0x5be7
movl $0x1, %eax
movq %r13, %rdx
movq %r12, %rdi
testb $0x1, %bl
movl $0x0, %ebx
jne 0x37c5
movq -0xa0(%rbp), %rbx
movq -0x98(%rbp), %r13
cmpq %r13, %rbx
je 0x385e
movq %r13, %rax
subq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5567
movq %rbx, %rdi
movq %r13, %rsi
callq 0x564b
movq -0x88(%rbp), %r13
movq -0x80(%rbp), %rbx
cmpq %rbx, %r13
je 0x38a6
movq %rbx, %rax
subq %r13, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x5567
movq %r13, %rdi
movq %rbx, %rsi
callq 0x564b
movq -0x88(%rbp), %r13
movq -0x80(%rbp), %rbx
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq %r13, %rdx
movq %rbx, %rcx
leaq -0x60(%rbp), %r8
callq 0x58dc
movq -0x60(%rbp), %r13
movq -0x58(%rbp), %r12
cmpq %r12, %r13
je 0x398f
movq (%r15), %rbx
movq (%r13), %rsi
movl $0x88, %edx
leaq -0x260(%rbp), %rdi
callq 0x2100
movl $0x88, %edx
leaq -0x1d8(%rbp), %rdi
movq %rbx, %rsi
callq 0x2100
movl $0xa, %ecx
leaq -0x150(%rbp), %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %eax, %eax
xorl %ecx, %ecx
movq -0x150(%rbp,%rax), %rdx
movq -0x148(%rbp,%rax), %rsi
movq -0x1d0(%rbp,%rax), %rdi
cmpq %rdx, %rdi
cmovaq %rdi, %rdx
movq -0x1c8(%rbp,%rax), %rdi
cmpq %rsi, %rdi
cmovbq %rdi, %rsi
cmpq %rdx, -0x258(%rbp,%rax)
setbe %dl
cmpq %rsi, -0x250(%rbp,%rax)
setae %sil
andb %dl, %sil
movzbl %sil, %edx
addl %edx, %ecx
addq $0x10, %rax
cmpq $0x50, %rax
jne 0x3916
cmpl $0x5, %ecx
je 0x39c0
addq $0x8, %r13
cmpq %r12, %r13
jne 0x38d7
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x39b4
movq %rbx, (%rsi)
jmp 0x399f
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x39a6
movq (%r15), %rax
movq %rax, (%rsi)
addq $0x8, -0x38(%rbp)
jmp 0x39c0
leaq -0x40(%rbp), %rdi
movq %r15, %rdx
callq 0x5964
jmp 0x39c0
leaq -0x40(%rbp), %rdi
movq %r15, %rdx
callq 0x5964
addq $0x8, %r15
movq -0x68(%rbp), %rax
cmpq 0x8(%rax), %r15
leaq -0xd0(%rbp), %r12
leaq -0x88(%rbp), %r13
jne 0x37a5
movq -0xd8(%rbp), %rdi
callq 0x5b86
movq -0xe0(%rbp), %rdi
callq 0x5b86
movq -0xa8(%rbp), %rdi
callq 0x5b86
movq -0xb0(%rbp), %rdi
callq 0x5b86
movq -0x68(%rbp), %rcx
movq (%rcx), %rdi
movq -0x40(%rbp), %rax
movq %rax, (%rcx)
movq -0x38(%rbp), %rax
movq %rax, 0x8(%rcx)
movq -0x30(%rbp), %rax
movq %rax, 0x10(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
testq %rdi, %rdi
je 0x3a47
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3a55
callq 0x2130
movl $0x18, %ebx
movq -0xa0(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x3a6c
callq 0x2130
addq $-0x18, %rbx
cmpq $-0x18, %rbx
jne 0x3a5a
movl $0x38, %ebx
movq -0x100(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x3a8d
callq 0x2130
addq $-0x30, %rbx
cmpq $-0x28, %rbx
jne 0x3a7b
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x3aa5
callq 0x2130
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3abd
jmp 0x3abd
jmp 0x3abd
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3ace
callq 0x2130
movl $0x18, %r14d
movq -0xa0(%rbp,%r14), %rdi
testq %rdi, %rdi
je 0x3ae6
callq 0x2130
addq $-0x18, %r14
cmpq $-0x18, %r14
jne 0x3ad4
movl $0x38, %r14d
movq -0x100(%rbp,%r14), %rdi
testq %rdi, %rdi
je 0x3b08
callq 0x2130
addq $-0x30, %r14
cmpq $-0x28, %r14
jne 0x3af6
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x3b20
callq 0x2130
movq %rbx, %rdi
callq 0x2240