// File: derekzwy[P]an-optimal-tcam-encoding-algorithm-for-packet-classification/cps-tss.cc
// Function: remove_redund_pkg(std::vector<pc_rule, std::allocator<pc_rule>>&, std::vector<pc_rule, std::allocator<pc_rule>>&)
vector<pc_rule*> remove_redund_pkg(vector<pc_rule> &pc, vector<pc_rule> &pc_prefix) 
{
    rule_boundary rb;
    init_boundary(rb);
    
    //pc_prefix = pc;
    
    vector<pc_rule*> pcr;
    for_each(pc.begin(), pc.end(), [&pcr](pc_rule &r){pcr.push_back(&r);});
    cout<<"Orignal ruleset "<<pc.size()<<endl;

    remove_redund_rt(pcr, rb, false);
    extend_rules(pcr, pc_prefix);
    
    cout<<"After prefix explanation: "<< pc_prefix.size()<<endl;

    vector<pc_rule*> pc_pprefix;
    for_each(pc_prefix.begin(), pc_prefix.end(), [&pc_pprefix](pc_rule &r){pc_pprefix.push_back(&r);});

    return move(pc_pprefix);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x110(%rbp)
movq %rdi, %rax
movq %rax, -0x108(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x32b0
movq -0x100(%rbp), %rdi
callq 0x5fc0
leaq -0x80(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x3300
movq -0x10(%rbp), %rdi
callq 0x3320
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3350
movq %rax, %rcx
movq -0xf8(%rbp), %rax
movq %rcx, -0x90(%rbp)
movq %rax, -0x98(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x26f0
movq %rax, -0xf0(%rbp)
jmp 0x2528
movq -0xf0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0xfa9b(%rip), %rdi      # 0x11fd8
leaq 0xaadc(%rip), %rsi      # 0xd020
callq 0x2110
movq %rax, -0x118(%rbp)
jmp 0x2552
movq -0x10(%rbp), %rdi
callq 0x3380
movq -0x118(%rbp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, -0x120(%rbp)
jmp 0x2573
movq -0x120(%rbp), %rdi
movq 0xfa3f(%rip), %rsi      # 0x11fc0
callq 0x2150
jmp 0x2588
leaq -0x80(%rbp), %rdi
leaq -0x68(%rbp), %rsi
xorl %edx, %edx
callq 0x6930
jmp 0x2599
movq -0x18(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x80c0
jmp 0x25a8
movq 0xfa29(%rip), %rdi      # 0x11fd8
leaq 0xaa7b(%rip), %rsi      # 0xd031
callq 0x2110
movq %rax, -0x128(%rbp)
jmp 0x25c4
movq -0x18(%rbp), %rdi
callq 0x3380
movq -0x128(%rbp), %rdi
movq %rax, %rsi
callq 0x2060
movq %rax, -0x130(%rbp)
jmp 0x25e5
movq -0x130(%rbp), %rdi
movq 0xf9cd(%rip), %rsi      # 0x11fc0
callq 0x2150
jmp 0x25fa
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x3300
movq -0x18(%rbp), %rdi
callq 0x3320
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3350
movq %rax, %rcx
movq -0x140(%rbp), %rax
movq %rcx, -0xd8(%rbp)
movq %rax, -0xe0(%rbp)
movq -0xd0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
callq 0x2750
movq %rax, -0x138(%rbp)
jmp 0x2661
movq -0x110(%rbp), %rdi
movq -0x138(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0xc8(%rbp), %rsi
callq 0x33b0
leaq -0xc8(%rbp), %rdi
callq 0x33e0
leaq -0x80(%rbp), %rdi
callq 0x33e0
movq -0x108(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x26d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x33e0
leaq -0x80(%rbp), %rdi
callq 0x33e0
movq -0xa0(%rbp), %rdi
callq 0x2220
nop