// 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*>>&)
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 0x6091
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 0x62d6
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 0x5f93
movq 0x28(%r15), %rdi
leaq -0x70(%rbp), %rsi
movl %eax, (%rsi)
movl 0x4(%r14), %eax
movl %eax, 0x4(%rsi)
leaq -0x60(%rbp), %rdx
callq 0x5f17
movl 0x4(%r14), %eax
cmpl %r12d, %eax
jbe 0x5fb5
movq 0x20(%r15), %rdi
movl (%r14), %ecx
leaq -0x68(%rbp), %rsi
movl %ecx, (%rsi)
movl %eax, 0x4(%rsi)
leaq -0x40(%rbp), %rdx
callq 0x5f17
movq -0x60(%rbp), %r14
movq -0x58(%rbp), %r15
cmpq %r15, %r14
je 0x605a
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x6055
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 0x603b
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 0x6075
cmpq %r15, %r14
jne 0x6067
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
cmpq %r15, %r14
je 0x6075
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x62d6
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x6083
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x6091
callq 0x2130
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x60a0
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x60b1
callq 0x2130
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x60bf
callq 0x2130
movq %rbx, %rdi
callq 0x2240