// File: /workspace/github_cpp_makefile_star2_O1/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
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
xorl %eax, %eax
movq %rax, -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 %rax, -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 (%rdi), %r15
movq %rdi, -0x68(%rbp)
cmpq 0x8(%rdi), %r15
je 0x3a1c
movq -0x60(%rbp), %rax
cmpq %rax, -0x58(%rbp)
je 0x3807
movq %rax, -0x58(%rbp)
leaq -0xa0(%rbp), %rbx
leaq -0x100(%rbp), %r13
xorl %r12d, %r12d
movq (%r15), %rax
movq 0x8(%rax,%r12), %rcx
movq 0x10(%rax,%r12), %rdx
movq (%r14,%r12), %rax
cmpq %rax, %rcx
cmovaq %rcx, %rax
movq 0x8(%r14,%r12), %rcx
cmpq %rcx, %rdx
cmovbq %rdx, %rcx
movq (%rbx), %rdx
cmpq %rdx, 0x8(%rbx)
je 0x3849
movq %rdx, 0x8(%rbx)
movl %eax, -0x70(%rbp)
movl %ecx, -0x6c(%rbp)
movq (%r15), %rcx
movq %r13, %rdi
leaq -0x70(%rbp), %rsi
movq %rbx, %rdx
callq 0x5c28
addq $0x10, %r12
addq $0x30, %r13
addq $0x18, %rbx
cmpq $0x10, %r12
je 0x3818
movq -0xa0(%rbp), %rbx
movq -0x98(%rbp), %r13
cmpq %r13, %rbx
je 0x38b3
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 0x559d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5681
movq -0x88(%rbp), %rbx
movq -0x80(%rbp), %r13
cmpq %r13, %rbx
je 0x38f0
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 0x559d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5681
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
leaq -0x60(%rbp), %r8
callq 0x5936
movq -0x60(%rbp), %r13
movq -0x58(%rbp), %r12
cmpq %r12, %r13
je 0x39e7
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 0x3965
cmpl $0x5, %ecx
je 0x3a0a
addq $0x8, %r13
cmpq %r12, %r13
jne 0x3926
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
jne 0x39f1
leaq -0x40(%rbp), %rdi
movq %r15, %rdx
callq 0x59be
jmp 0x3a0a
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x39fe
movq (%r15), %rax
movq %rax, (%rsi)
addq $0x8, -0x38(%rbp)
jmp 0x3a0a
leaq -0x40(%rbp), %rdi
movq %r15, %rdx
callq 0x59be
addq $0x8, %r15
movq -0x68(%rbp), %rax
cmpq 0x8(%rax), %r15
jne 0x37f9
movq -0xd8(%rbp), %rdi
callq 0x5bc7
movq -0xe0(%rbp), %rdi
callq 0x5bc7
movq -0xa8(%rbp), %rdi
callq 0x5bc7
movq -0xb0(%rbp), %rdi
callq 0x5bc7
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 0x3a83
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3a91
callq 0x2130
movl $0x18, %ebx
movq -0xa0(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x3aa8
callq 0x2130
addq $-0x18, %rbx
cmpq $-0x18, %rbx
jne 0x3a96
movl $0x38, %ebx
movq -0x100(%rbp,%rbx), %rdi
testq %rdi, %rdi
je 0x3ac9
callq 0x2130
addq $-0x30, %rbx
cmpq $-0x28, %rbx
jne 0x3ab7
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x3ae1
callq 0x2130
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3af9
jmp 0x3af9
jmp 0x3af9
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x3b0a
callq 0x2130
movl $0x18, %r14d
movq -0xa0(%rbp,%r14), %rdi
testq %rdi, %rdi
je 0x3b22
callq 0x2130
addq $-0x18, %r14
cmpq $-0x18, %r14
jne 0x3b10
movl $0x38, %r14d
movq -0x100(%rbp,%r14), %rdi
testq %rdi, %rdi
je 0x3b44
callq 0x2130
addq $-0x30, %r14
cmpq $-0x28, %r14
jne 0x3b32
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x3b5c
callq 0x2130
movq %rbx, %rdi
callq 0x2240