// File: /workspace/github_cpp_makefile_star2_O2/jingdao[P]PointCloudApp/kdtree.cpp
// Function: KdTree::searchNode(KdTree::KdTreeNode*, std::vector<int, std::allocator<int>>*, KdTree::Cube*, KdTree::Cube, int)
void KdTree::searchNode(KdTreeNode* node,std::vector<int> *indices,Cube* range,Cube cell,int depth){
	if (!node) return; //nothing here
	if (node->isLeaf) {
		float x = float_data[node->index * 4];
		float y = float_data[node->index * 4 + 1];
		float z = float_data[node->index * 4 + 2];
		if (x >= range->x1 && x <= range->x2 && 
			y >= range->y1 && y <= range->y2 && 
			z >= range->z1 && z <= range->z2)
			indices->push_back(node->index);
	} else {
		if (cell.x1 >= range->x1 && cell.x2 <= range->x2 &&
			cell.y1 >= range->y1 && cell.y2 <= range->y2 &&
			cell.z1 >= range->z1 && cell.z2 <= range->z2) {
			//region fully contained in range
			getIndexFromSubTree(node->left,indices);
			getIndexFromSubTree(node->right,indices);
		} else if ((cell.x2 >= range->x1 && cell.x1 <= range->x2) &&
			(cell.y2 >= range->y1 && cell.y1 <= range->y2) &&
			(cell.z2 >= range->z1 && cell.z1 <= range->z2)) {
			//region intersects range
			int dimension = depth % 3;
			Cube leftCell = cell;
			Cube rightCell = cell;
			//trim cells according to splitting plane
			switch (dimension) {
				case 0:
					leftCell.x2 = node->value;
					rightCell.x1 = node->value;
					break;
				case 1:
					leftCell.y2 = node->value;
					rightCell.y1 = node->value;
					break;
				case 2:
					leftCell.z2 = node->value;
					rightCell.z1 = node->value;
					break;
			}
			searchNode(node->left,indices,range,leftCell,depth+1);
			searchNode(node->right,indices,range,rightCell,depth+1);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %ebp
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
leaq 0x80(%rsp), %r13
movss 0xc(%r13), %xmm2
movss 0x10(%r13), %xmm3
movss 0x14(%r13), %xmm4
movss (%r13), %xmm7
movss 0x4(%r13), %xmm6
movss 0x8(%r13), %xmm5
movss %xmm2, 0x2c(%rsp)
movss %xmm3, 0x28(%rsp)
movss %xmm4, 0x24(%rsp)
testq %r14, %r14
je 0x7cab
cmpb $0x1, (%r14)
je 0x7c47
movss (%r15), %xmm0
ucomiss %xmm0, %xmm7
jb 0x7af9
movss 0xc(%r15), %xmm1
ucomiss %xmm2, %xmm1
jb 0x7af9
ucomiss 0x4(%r15), %xmm6
jb 0x7af9
movss 0x10(%r15), %xmm1
ucomiss %xmm3, %xmm1
jb 0x7af9
ucomiss 0x8(%r15), %xmm5
jb 0x7af9
movss 0x14(%r15), %xmm1
ucomiss %xmm4, %xmm1
jae 0x7cba
ucomiss %xmm0, %xmm2
jb 0x7cab
movss 0xc(%r15), %xmm0
ucomiss %xmm7, %xmm0
jb 0x7cab
ucomiss 0x4(%r15), %xmm3
jb 0x7cab
movss 0x10(%r15), %xmm0
ucomiss %xmm6, %xmm0
jb 0x7cab
ucomiss 0x8(%r15), %xmm4
jb 0x7cab
movss 0x14(%r15), %xmm0
ucomiss %xmm5, %xmm0
jb 0x7cab
movl %ebp, %eax
cltd
pushq $0x3
popq %rcx
idivl %ecx
cmpl $0x2, %edx
je 0x7b92
cmpl $0x1, %edx
movss %xmm5, 0x20(%rsp)
je 0x7b7b
testl %edx, %edx
movss %xmm6, 0x1c(%rsp)
jne 0x7baf
movss 0x4(%r14), %xmm2
movaps %xmm4, %xmm0
movaps %xmm3, %xmm1
movss %xmm2, 0x18(%rsp)
jmp 0x7bbb
movss %xmm7, 0x18(%rsp)
movss 0x4(%r14), %xmm1
movaps %xmm4, %xmm0
movss %xmm1, 0x1c(%rsp)
jmp 0x7bbb
movss %xmm7, 0x18(%rsp)
movss %xmm6, 0x1c(%rsp)
movss 0x4(%r14), %xmm0
movaps %xmm3, %xmm1
movss %xmm0, 0x20(%rsp)
jmp 0x7bbb
movss %xmm7, 0x18(%rsp)
movaps %xmm4, %xmm0
movaps %xmm3, %xmm1
movq 0x8(%r14), %rsi
movl 0x8(%r13), %eax
movl %eax, 0x38(%rsp)
movq (%r13), %rax
movq %rax, 0x30(%rsp)
movss %xmm2, 0x3c(%rsp)
movss %xmm1, 0x40(%rsp)
movss %xmm0, 0x44(%rsp)
incl %ebp
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
movq %rbx, %rdx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x7a4e
movq 0x10(%r14), %r14
movss 0x18(%rsp), %xmm7
movss %xmm7, (%r13)
movss 0x1c(%rsp), %xmm6
movss %xmm6, 0x4(%r13)
movss 0x20(%rsp), %xmm5
movss %xmm5, 0x8(%r13)
movss 0x2c(%rsp), %xmm2
movss 0x28(%rsp), %xmm3
movss 0x24(%rsp), %xmm4
jmp 0x7aa9
movq 0x30(%r12), %rax
movslq 0x4(%r14), %rcx
movq %rcx, %rdx
shlq $0x4, %rdx
movss (%rax,%rdx), %xmm0
ucomiss (%r15), %xmm0
jb 0x7cab
movss 0xc(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x7cab
shlq $0x2, %rcx
leal 0x1(%rcx), %edx
movslq %edx, %rdx
movss (%rax,%rdx,4), %xmm0
ucomiss 0x4(%r15), %xmm0
jb 0x7cab
movss 0x10(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x7cab
orl $0x2, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss 0x8(%r15), %xmm0
jb 0x7cab
movss 0x14(%r15), %xmm1
ucomiss %xmm0, %xmm1
jae 0x7ce6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rsi
movq %r12, %rdi
movq %rbx, %rdx
callq 0x7d04
movq 0x10(%r14), %rsi
movq %r12, %rdi
movq %rbx, %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7d04
addq $0x4, %r14
movq %rbx, %rdi
movq %r14, %rsi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6d04
nop