// File: /workspace/github_cpp_makefile_star2_O2/derekzwy[P]an-optimal-tcam-encoding-algorithm-for-packet-classification/rtrie.cc
// Function: rt_query_or(rnode*, rg, std::vector<pc_rule*, std::allocator<pc_rule*>>&, int, int)
void rt_query_or(rnode *n, rg r, vector<pc_rule*> &set, int l, int h) 
{
    if(!n){ 
        return;
    }
    vector<pc_rule*> set_left;
    vector<pc_rule*> set_right;
    

    copy_if(n->rlist.begin(), n->rlist.end(), back_inserter(set), [&l, &h](pc_rule *r){return r->priority >=l && r->priority < h;});
    uint32_t m = ((uint64_t)n->b.high -  (uint64_t)n->b.low + 1ULL)/2 + n->b.low - 1;

    if(r.low <= m) {
        rt_query_or(n->left, r, set_left, l,h);
    }
    if(r.high > m) {
        rt_query_or(n->right, r, set_right,l,h);
    }

    if(!set_left.empty() && !set_right.empty()) {
        sort(set_left.begin(), set_left.end());
        sort(set_right.begin(), set_right.end());

        set_union(set_left.begin(), set_left.end(),
                set_right.begin(), set_right.end(),
                back_inserter(set));
    }
    else if(!set_left.empty()) {
        copy(set_left.begin(), set_left.end(), back_inserter(set));
    }
    else if(!set_right.empty()) {
        copy(set_right.begin(), set_right.end(), back_inserter(set));
    }


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
testq %rdi, %rdi
je 0x5acc
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, %rbx
movq %rsi, -0x78(%rbp)
andq $0x0, -0x60(%rbp)
xorps %xmm0, %xmm0
andq $0x0, -0x40(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x50(%rbp)
movq 0x8(%rdi), %r12
movq %rdi, -0x30(%rbp)
movq 0x10(%rdi), %r13
cmpq %r13, %r12
je 0x59df
movq (%r12), %rax
movl (%rax), %eax
cmpl %r15d, %eax
setl %cl
cmpl %r14d, %eax
setge %al
orb %cl, %al
jne 0x59d9
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4c7a
addq $0x8, %r12
jmp 0x59b3
movq -0x30(%rbp), %rcx
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
subq %rax, %rcx
incq %rcx
shrq %rcx
leal (%rax,%rcx), %r12d
decl %r12d
movq -0x78(%rbp), %r13
movl (%r13), %eax
cmpl %r12d, %eax
ja 0x5a2c
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rdi
leaq -0x88(%rbp), %rsi
movl %eax, (%rsi)
movl 0x4(%r13), %eax
movl %eax, 0x4(%rsi)
leaq -0x70(%rbp), %rdx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x596b
movl 0x4(%r13), %eax
cmpl %r12d, %eax
jbe 0x5a59
movq -0x30(%rbp), %rcx
movq 0x20(%rcx), %rdi
movl (%r13), %ecx
leaq -0x80(%rbp), %rsi
movl %ecx, (%rsi)
movl %eax, 0x4(%rsi)
leaq -0x50(%rbp), %rdx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x596b
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %rax
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
cmpq %rax, %rcx
je 0x5aa5
cmpq %rsi, %rdi
je 0x5aac
movq %rcx, %rdi
movq %rax, %rsi
callq 0x4e43
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4e43
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %rbx, %r8
callq 0x5b3b
jmp 0x5aba
cmpq %rsi, %rdi
jne 0x5ab2
jmp 0x5aba
movq %rcx, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x5afa
leaq -0x50(%rbp), %rdi
callq 0x2c06
leaq -0x70(%rbp), %rdi
callq 0x2c06
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5add
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x2c06
leaq -0x70(%rbp), %rdi
callq 0x2c06
movq %rbx, %rdi
callq 0x2230