// File: /workspace/github_cpp_makefile_star2_O1/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 0x629e
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 0x614f
movq (%r12), %rax
movl (%rax), %ecx
cmpl %r15d, %ecx
setl %dl
cmpl %r14d, %ecx
setge %cl
orb %dl, %cl
jne 0x6149
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x613e
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x6149
movq %rbx, %rdi
movq %r12, %rdx
callq 0x59be
addq $0x8, %r12
jmp 0x610f
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 0x6199
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 0x60c7
movq -0x68(%rbp), %rdx
movl 0x4(%r13), %eax
cmpl %r12d, %eax
jbe 0x61c2
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 0x60c7
movq -0x60(%rbp), %r14
movq -0x58(%rbp), %r15
cmpq %r15, %r14
je 0x6267
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x6262
movq %r15, %rax
subq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x559d
movq %r14, %rdi
movq %r15, %rsi
callq 0x5681
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
cmpq %r15, %r14
je 0x6248
movq %r15, %rax
subq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x559d
movq %r14, %rdi
movq %r15, %rsi
callq 0x5681
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq %rbx, %r8
callq 0x6335
jmp 0x6282
cmpq %r15, %r14
jne 0x6274
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
cmpq %r15, %r14
je 0x6282
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x62d6
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x6290
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x629e
callq 0x2130
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x62af
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x62c0
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x62ce
callq 0x2130
movq %rbx, %rdi
callq 0x2240