// File: 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
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rsi, -0x128(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0xbeda
jmp 0xc2bc
leaq -0x30(%rbp), %rdi
callq 0x3300
leaq -0x48(%rbp), %rdi
callq 0x3300
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x3460
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
callq 0x34d0
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9350
movq %rax, -0x130(%rbp)
jmp 0xbf20
movq -0x130(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0xc8a0
movq %rax, -0x138(%rbp)
jmp 0xbf45
movq -0x128(%rbp), %rax
movq -0x138(%rbp), %rcx
movq %rcx, -0x78(%rbp)
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %ecx
movq -0x8(%rbp), %rdx
movl (%rdx), %edx
subq %rdx, %rcx
addq $0x1, %rcx
shrq %rcx
movq -0x8(%rbp), %rdx
movl (%rdx), %edx
addq %rdx, %rcx
subq $0x1, %rcx
movl %ecx, -0x7c(%rbp)
movl (%rax), %eax
cmpl -0x7c(%rbp), %eax
ja 0xbfe7
movq -0x128(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x140(%rbp)
leaq -0x84(%rbp), %rdi
callq 0xc870
jmp 0xbfa9
movq -0x140(%rbp), %rdi
leaq -0x84(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0xbeb0
jmp 0xbfc2
jmp 0xbfe7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x33e0
leaq -0x30(%rbp), %rdi
callq 0x33e0
jmp 0xc2c5
movq -0x128(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x7c(%rbp), %eax
jbe 0xc035
movq -0x128(%rbp), %rsi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x148(%rbp)
leaq -0x8c(%rbp), %rdi
callq 0xc870
jmp 0xc01a
movq -0x148(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0xbeb0
jmp 0xc033
jmp 0xc035
leaq -0x30(%rbp), %rdi
callq 0x9380
testb $0x1, %al
jne 0xc18d
leaq -0x48(%rbp), %rdi
callq 0x9380
testb $0x1, %al
jne 0xc18d
leaq -0x30(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x3460
movq -0x150(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x34d0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x92a0
jmp 0xc096
leaq -0x48(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x3460
movq -0x158(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0x34d0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x92a0
jmp 0xc0d5
leaq -0x30(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x3460
movq -0x170(%rbp), %rdi
movq %rax, -0xb8(%rbp)
callq 0x34d0
movq %rax, -0xc0(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x3460
movq -0x168(%rbp), %rdi
movq %rax, -0xc8(%rbp)
callq 0x34d0
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9350
movq %rax, -0x160(%rbp)
jmp 0xc13b
movq -0x160(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movq -0xd0(%rbp), %rcx
movq -0xd8(%rbp), %r8
callq 0xc910
movq %rax, -0x178(%rbp)
jmp 0xc17a
movq -0x178(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0xc2aa
leaq -0x30(%rbp), %rdi
callq 0x9380
testb $0x1, %al
jne 0xc21e
leaq -0x30(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x3460
movq -0x188(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x34d0
movq %rax, -0xf0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9350
movq %rax, -0x180(%rbp)
jmp 0xc1da
movq -0x180(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movq -0xf8(%rbp), %rdx
callq 0xc8a0
movq %rax, -0x190(%rbp)
jmp 0xc20b
movq -0x190(%rbp), %rax
movq %rax, -0x100(%rbp)
jmp 0xc2a8
leaq -0x48(%rbp), %rdi
callq 0x9380
testb $0x1, %al
jne 0xc2a6
leaq -0x48(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x3460
movq -0x1a0(%rbp), %rdi
movq %rax, -0x108(%rbp)
callq 0x34d0
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9350
movq %rax, -0x198(%rbp)
jmp 0xc267
movq -0x198(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rsi
movq -0x118(%rbp), %rdx
callq 0xc8a0
movq %rax, -0x1a8(%rbp)
jmp 0xc298
movq -0x1a8(%rbp), %rax
movq %rax, -0x120(%rbp)
jmp 0xc2a8
jmp 0xc2aa
leaq -0x48(%rbp), %rdi
callq 0x33e0
leaq -0x30(%rbp), %rdi
callq 0x33e0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x2220
nop