// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movl %r8d, %ebp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, 0x28(%rsp)
leaq 0xb0(%rsp), %r13
leaq 0xc(%r13), %rbx
testq %r14, %r14
je 0x8b68
cmpb $0x1, (%r14)
je 0x8ae5
movss (%r13), %xmm4
movss (%r15), %xmm1
ucomiss %xmm1, %xmm4
jb 0x8951
movss 0xc(%r15), %xmm0
ucomiss 0xc(%r13), %xmm0
jb 0x8951
movss 0x4(%r13), %xmm0
ucomiss 0x4(%r15), %xmm0
jb 0x8951
movss 0x10(%r15), %xmm0
ucomiss 0x10(%r13), %xmm0
jb 0x8951
movss 0x8(%r13), %xmm0
ucomiss 0x8(%r15), %xmm0
jb 0x8951
movss 0x14(%r15), %xmm0
ucomiss 0x14(%r13), %xmm0
jae 0x8b77
movss 0xc(%r13), %xmm0
ucomiss %xmm1, %xmm0
jb 0x8b68
movss 0xc(%r15), %xmm1
ucomiss %xmm4, %xmm1
jb 0x8b68
movss 0x10(%r13), %xmm1
ucomiss 0x4(%r15), %xmm1
jb 0x8b68
movss 0x4(%r13), %xmm5
movss 0x10(%r15), %xmm2
ucomiss %xmm5, %xmm2
jb 0x8b68
movss 0x14(%r13), %xmm2
ucomiss 0x8(%r15), %xmm2
jb 0x8b68
movss 0x8(%r13), %xmm6
movss 0x14(%r15), %xmm3
ucomiss %xmm6, %xmm3
jb 0x8b68
movslq %ebp, %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rsi
shrq $0x3f, %rsi
shrq $0x20, %rcx
addl %esi, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
cmpl $0x2, %eax
je 0x8a13
cmpl $0x1, %eax
movss %xmm6, 0x24(%rsp)
je 0x89ff
testl %eax, %eax
movss %xmm5, 0x20(%rsp)
jne 0x8a2d
movss 0x4(%r14), %xmm0
movss %xmm0, 0x1c(%rsp)
jmp 0x8a33
movss %xmm4, 0x1c(%rsp)
movss 0x4(%r14), %xmm1
movss %xmm1, 0x20(%rsp)
jmp 0x8a33
movss %xmm5, 0x20(%rsp)
movss %xmm4, 0x1c(%rsp)
movss 0x4(%r14), %xmm2
movss %xmm2, 0x24(%rsp)
jmp 0x8a33
movss %xmm4, 0x1c(%rsp)
movq 0x8(%r14), %rsi
movl 0x8(%r13), %eax
movl %eax, 0x50(%rsp)
movq (%r13), %rax
movq %rax, 0x48(%rsp)
movss %xmm0, 0x54(%rsp)
movss %xmm1, 0x58(%rsp)
movss %xmm2, 0x5c(%rsp)
incl %ebp
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x48(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x28(%rsp), %rdi
movq %r12, %rdx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x88be
movq 0x10(%r14), %r14
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0x30(%rsp)
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
movss 0x24(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
movq (%rbx), %rax
movq %rax, 0x3c(%rsp)
movl 0x8(%rbx), %eax
movl %eax, 0x44(%rsp)
movups 0x30(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x70(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%r13)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%r13)
jmp 0x88e9
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rcx
movslq 0x4(%r14), %rax
movq %rax, %rsi
shlq $0x4, %rsi
movss (%rcx,%rsi), %xmm0
ucomiss (%r15), %xmm0
jb 0x8b68
movss 0xc(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x8b68
leaq (,%rax,4), %rdi
leal 0x1(%rdi), %esi
movslq %esi, %rsi
movss (%rcx,%rsi,4), %xmm0
ucomiss 0x4(%r15), %xmm0
jb 0x8b68
movss 0x10(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x8b68
orl $0x2, %edi
movslq %edi, %rsi
movss (%rcx,%rsi,4), %xmm0
ucomiss 0x8(%r15), %xmm0
jb 0x8b68
movss 0x14(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x8b68
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x8ba8
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r12)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rsi
movq 0x28(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
callq 0x8bc6
movq 0x10(%r14), %rsi
movq %r15, %rdi
movq %r12, %rdx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8bc6
addq $0x4, %r14
movq %r12, %rdi
movq %r14, %rdx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x80de
nop