// File: /workspace/github_cpp_makefile_star2_O3/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
testq %rsi, %rsi
je 0x8b57
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)
cmpb $0x1, (%r14)
je 0x8adb
movss (%r15), %xmm0
ucomiss %xmm0, %xmm7
jb 0x8973
movss 0xc(%r15), %xmm1
ucomiss %xmm2, %xmm1
jb 0x8973
ucomiss 0x4(%r15), %xmm6
jb 0x8973
movss 0x10(%r15), %xmm1
ucomiss %xmm3, %xmm1
jb 0x8973
ucomiss 0x8(%r15), %xmm5
jb 0x8973
movss 0x14(%r15), %xmm1
ucomiss %xmm4, %xmm1
jae 0x8b66
ucomiss %xmm0, %xmm2
jb 0x8b57
movss 0xc(%r15), %xmm0
ucomiss %xmm7, %xmm0
jb 0x8b57
ucomiss 0x4(%r15), %xmm3
jb 0x8b57
movss 0x10(%r15), %xmm0
ucomiss %xmm6, %xmm0
jb 0x8b57
ucomiss 0x8(%r15), %xmm4
jb 0x8b57
movss 0x14(%r15), %xmm0
ucomiss %xmm5, %xmm0
jb 0x8b57
movslq %ebp, %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
cmpl $0x2, %eax
je 0x8a20
cmpl $0x1, %eax
movss %xmm5, 0x20(%rsp)
je 0x8a09
testl %eax, %eax
movss %xmm6, 0x1c(%rsp)
jne 0x8a3d
movss 0x4(%r14), %xmm2
movaps %xmm4, %xmm0
movaps %xmm3, %xmm1
movss %xmm2, 0x18(%rsp)
jmp 0x8a49
movss %xmm7, 0x18(%rsp)
movss 0x4(%r14), %xmm1
movaps %xmm4, %xmm0
movss %xmm1, 0x1c(%rsp)
jmp 0x8a49
movss %xmm7, 0x18(%rsp)
movss %xmm6, 0x1c(%rsp)
movss 0x4(%r14), %xmm0
movaps %xmm3, %xmm1
movss %xmm0, 0x20(%rsp)
jmp 0x8a49
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 0x88c8
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)
testq %r14, %r14
movss 0x2c(%rsp), %xmm2
movss 0x28(%rsp), %xmm3
movss 0x24(%rsp), %xmm4
jne 0x892c
jmp 0x8b57
movq 0x30(%r12), %rcx
movslq 0x4(%r14), %rax
movq %rax, %rdx
shlq $0x4, %rdx
movss (%rcx,%rdx), %xmm0
ucomiss (%r15), %xmm0
jb 0x8b57
movss 0xc(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x8b57
leaq (,%rax,4), %rdx
leal 0x1(%rdx), %esi
movslq %esi, %rsi
movss (%rcx,%rsi,4), %xmm0
ucomiss 0x4(%r15), %xmm0
jb 0x8b57
movss 0x10(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x8b57
orl $0x2, %edx
movslq %edx, %rdx
movss (%rcx,%rdx,4), %xmm0
ucomiss 0x8(%r15), %xmm0
jb 0x8b57
movss 0x14(%r15), %xmm1
ucomiss %xmm0, %xmm1
jb 0x8b57
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x8b92
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
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 0x8bb0
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 0x8bb0
addq $0x4, %r14
movq %rbx, %rdi
movq %r14, %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8112
nop