// File: /workspace/github_cpp_makefile_star2_O2/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 $0x248, %rsp            # imm = 0x248
movq %rsi, %r12
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0xa0(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x110(%rbp), %rdi
movaps %xmm0, 0x50(%rdi)
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
leaq -0x80(%rbp), %rax
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, (%rax)
leaq -0x40(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
callq 0x354d
movq %rbx, -0x48(%rbp)
movq (%rbx), %r15
leaq 0x8(%r12), %r14
movq %r12, -0xa8(%rbp)
movq -0x48(%rbp), %rax
cmpq 0x8(%rax), %r15
je 0x3798
movq -0x40(%rbp), %rax
cmpq %rax, -0x38(%rbp)
je 0x360e
movq %rax, -0x38(%rbp)
leaq -0x80(%rbp), %rbx
leaq -0x110(%rbp), %r13
xorl %r12d, %r12d
cmpq $0x20, %r12
je 0x3676
movq (%r15), %rcx
movq 0x8(%rcx,%r12), %rdx
movq 0x10(%rcx,%r12), %rsi
movq -0x8(%r14,%r12), %rax
cmpq %rax, %rdx
cmovaq %rdx, %rax
movq (%r14,%r12), %rdx
cmpq %rdx, %rsi
cmovbq %rsi, %rdx
movq (%rbx), %rsi
cmpq %rsi, 0x8(%rbx)
je 0x3653
movq %rsi, 0x8(%rbx)
movl %eax, -0x50(%rbp)
movl %edx, -0x4c(%rbp)
movq %r13, %rdi
leaq -0x50(%rbp), %rsi
movq %rbx, %rdx
callq 0x55ca
addq $0x10, %r12
addq $0x30, %r13
addq $0x18, %rbx
jmp 0x361c
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x4e43
movq -0xa8(%rbp), %r12
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x4e43
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq -0x60(%rbp), %rcx
leaq -0x40(%rbp), %r8
callq 0x52b7
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %r13
cmpq %r13, %rbx
je 0x376f
cmpq %r13, %rbx
je 0x3780
movq (%rbx), %rsi
movl $0x88, %edx
leaq -0x270(%rbp), %rdi
callq 0x20f0
movq (%r15), %rsi
movl $0x88, %edx
leaq -0x1e8(%rbp), %rdi
callq 0x20f0
pushq $0xa
popq %rcx
leaq -0x160(%rbp), %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
xorl %ecx, %ecx
xorl %eax, %eax
cmpq $0x50, %rcx
je 0x3760
movq -0x160(%rbp,%rcx), %rdx
movq -0x158(%rbp,%rcx), %rsi
movq -0x1e0(%rbp,%rcx), %rdi
cmpq %rdx, %rdi
cmovaq %rdi, %rdx
movq -0x1d8(%rbp,%rcx), %rdi
cmpq %rsi, %rdi
cmovbq %rdi, %rsi
cmpq %rdx, -0x268(%rbp,%rcx)
setbe %dl
cmpq %rsi, -0x260(%rbp,%rcx)
setae %sil
andb %dl, %sil
movzbl %sil, %edx
addl %edx, %eax
addq $0x10, %rcx
jmp 0x3706
addq $0x8, %rbx
cmpl $0x5, %eax
jne 0x36c1
jmp 0x378f
leaq -0xa0(%rbp), %rdi
movq %r15, %rsi
callq 0x4c7a
jmp 0x378f
leaq -0xa0(%rbp), %rdi
movq %r15, %rsi
callq 0x4c7a
addq $0x8, %r15
jmp 0x35f2
movq -0xe8(%rbp), %rdi
callq 0x5570
movq -0xf0(%rbp), %rdi
callq 0x5570
movq -0xb8(%rbp), %rdi
callq 0x5570
movq -0xc0(%rbp), %rdi
callq 0x5570
leaq -0xa0(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x53dc
leaq -0x40(%rbp), %rdi
callq 0x2c06
pushq $0x18
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0x80, %rdi
callq 0x2c06
addq $-0x18, %rbx
cmpq $-0x18, %rbx
jne 0x37e4
pushq $0x38
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0x110, %rdi           # imm = 0xFEF0
callq 0x2c06
addq $-0x30, %rbx
cmpq $-0x28, %rbx
jne 0x37fe
leaq -0xa0(%rbp), %rdi
callq 0x2c06
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x383c
jmp 0x383c
jmp 0x383c
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x2c06
pushq $0x18
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0x80, %rdi
callq 0x2c06
addq $-0x18, %r14
cmpq $-0x18, %r14
jne 0x384c
pushq $0x38
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0x110, %rdi           # imm = 0xFEF0
callq 0x2c06
addq $-0x30, %r14
cmpq $-0x28, %r14
jne 0x3867
leaq -0xa0(%rbp), %rdi
callq 0x2c06
movq %rbx, %rdi
callq 0x2230