// 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*>>&)
void rt_query_or(rnode *n, rg r, vector<pc_rule*> &set) 
{
    if(!n){ 
        return;
    }
    vector<pc_rule*> set_left;
    vector<pc_rule*> set_right;
    

    copy(n->rlist.begin(), n->rlist.end(), back_inserter(set));
    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);
    }
    if(r.high > m) {
        rt_query_or(n->right, r, set_right);
    }

    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 %r12
pushq %rbx
subq $0x50, %rsp
testq %rdi, %rdi
je 0x6061
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
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), %rdi
movq 0x10(%r15), %rsi
callq 0x62aa
movl (%r15), %eax
movl 0x4(%r15), %ecx
subq %rax, %rcx
incq %rcx
shrq %rcx
leal (%rax,%rcx), %r12d
decl %r12d
movl (%r14), %eax
cmpl %r12d, %eax
ja 0x5f65
movq 0x28(%r15), %rdi
leaq -0x70(%rbp), %rsi
movl %eax, (%rsi)
movl 0x4(%r14), %eax
movl %eax, 0x4(%rsi)
leaq -0x60(%rbp), %rdx
callq 0x5ee9
movl 0x4(%r14), %eax
cmpl %r12d, %eax
jbe 0x5f87
movq 0x20(%r15), %rdi
movl (%r14), %ecx
leaq -0x68(%rbp), %rsi
movl %ecx, (%rsi)
movl %eax, 0x4(%rsi)
leaq -0x40(%rbp), %rdx
callq 0x5ee9
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r14
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
cmpq %r14, %r15
je 0x6030
cmpq %rsi, %rdi
je 0x6037
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 0x6018
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 0x6045
cmpq %rsi, %rdi
jne 0x603d
jmp 0x6049
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x62aa
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x6053
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x6061
callq 0x2130
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x6084
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x6084
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x6092
callq 0x2130
movq %rbx, %rdi
callq 0x2240