// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
testq %rdi, %rdi
je 0x626f
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, %rbx
movq %rsi, -0x70(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
xorl %eax, %eax
movq %rax, -0x50(%rbp)
movq %rax, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movq 0x8(%rdi), %r12
movq %rdi, -0x68(%rbp)
movq 0x10(%rdi), %r13
cmpq %r13, %r12
je 0x6122
movq (%r12), %rax
movl (%rax), %ecx
cmpl %r15d, %ecx
setl %dl
cmpl %r14d, %ecx
setge %cl
orb %dl, %cl
jne 0x611c
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x6111
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x611c
movq %rbx, %rdi
movq %r12, %rdx
callq 0x5964
addq $0x8, %r12
jmp 0x60e2
movq -0x68(%rbp), %rdx
movl (%rdx), %eax
movl 0x4(%rdx), %ecx
subq %rax, %rcx
incq %rcx
shrq %rcx
leal (%rax,%rcx), %r12d
decl %r12d
movq -0x70(%rbp), %r13
movl (%r13), %eax
cmpl %r12d, %eax
ja 0x616c
movq 0x28(%rdx), %rdi
leaq -0x80(%rbp), %rsi
movl %eax, (%rsi)
movl 0x4(%r13), %eax
movl %eax, 0x4(%rsi)
leaq -0x60(%rbp), %rdx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x609a
movq -0x68(%rbp), %rdx
movl 0x4(%r13), %eax
cmpl %r12d, %eax
jbe 0x6195
movq 0x20(%rdx), %rdi
movl (%r13), %ecx
leaq -0x78(%rbp), %rsi
movl %ecx, (%rsi)
movl %eax, 0x4(%rsi)
leaq -0x40(%rbp), %rdx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x609a
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r14
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
cmpq %r14, %r15
je 0x623e
cmpq %rsi, %rdi
je 0x6245
movq %r14, %rax
subq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5567
movq %r15, %rdi
movq %r14, %rsi
callq 0x564b
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r14
cmpq %r14, %r15
je 0x6226
movq %r14, %rax
subq %r15, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x5567
movq %r15, %rdi
movq %r14, %rsi
callq 0x564b
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r14
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %r15, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x6309
jmp 0x6253
cmpq %rsi, %rdi
jne 0x624b
jmp 0x6257
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x62aa
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x6261
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x626f
callq 0x2130
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x6294
callq 0x2130
jmp 0x6294
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x62a2
callq 0x2130
movq %rbx, %rdi
callq 0x2240