// File: /workspace/github_cpp_makefile_star2_O1/Proudc[P]CTSS/src/ContinuousQuery/Pruneline.cpp
// Function: roadSimpleQueryPath(Graph*, ReferencePath*, std::vector<Edge, std::allocator<Edge>>, std::vector<Edge, std::allocator<Edge>>&, Record*, int, int*, double*)
bool roadSimpleQueryPath(Graph* myGraph, ReferencePath* referencePath, std::vector<Edge> currentPath, 
	std::vector<Edge>& lastPath, Record* temRecord, int currentVertex, int* timeOutFlag, double* pathDistance)
{
	if (!BFS(myGraph, referencePath, currentPath, currentVertex))
	{
		printf("BFS search did not get results...\n");
		clock_t startTime, stopTime;
		startTime = clock();
		priority_queue<TraversingPath> priorityQueue;
		TraversingPath* firstPath = new TraversingPath;
		initializeFirstPath(myGraph, firstPath, currentVertex, currentPath);
		priorityQueue.push(*firstPath);
		temRecord->numOfOutPriQueue = 0;
		while (!priorityQueue.empty())																				  
		{
			TraversingPath* temPath;
			stopTime = clock();
			if (((double)(stopTime - startTime) / CLOCKS_PER_SEC) > 10)
			{
				(*timeOutFlag) = 1;
				delete firstPath;
				return false;
			}

			(*temPath) = (priorityQueue.top());
			priorityQueue.pop();
			temRecord->numOfOutPriQueue += 1;
			
			if (temPath->finalVertexID != referencePath->finalVertex)
			{
				for (unsigned int i = 0; i < (myGraph->vertexsVector[temPath->finalVertexID].adjVertexID.size()); i++)
				{
					int nextVertexID = myGraph->vertexsVector[temPath->finalVertexID].adjVertexID[i];
					if ((myGraph->vertexsVector[nextVertexID].locationFlag == true) && (checkIfAccess(myGraph, temPath, nextVertexID)))
					{
						TraversingPath* newPath = new TraversingPath;
						handleNewPath(myGraph, temPath, newPath, nextVertexID);

						if ((myGraph->vertexsVector[newPath->finalVertexID].referFlag == true))
						{
							double temDist = dfdDistBetweenTwoPaths(myGraph, newPath, referencePath, lastPath, newPath->finalVertexID);
							if (temDist <= (myGraph->delta))
							{
								delete firstPath;
								delete newPath;
								(*pathDistance) = temDist;
								return true;
							}
							else if ((newPath->finalVertexID == referencePath->finalVertex) && (referencePath->referDFDFlag == true))
							{
								delete newPath;
								continue;
							}
						}
						else
						{
							double lb = calculateLowerBound(myGraph, newPath, temRecord, referencePath);
							if ((lb != -1) && (lb < (myGraph->delta)))
							{
								newPath->eucDeltaOfTrue = lb;
								newPath->eucDelta = (100000 * lb + myGraph->vertexsVector[newPath->finalVertexID].traversalOrderWeights);
								priorityQueue.push(*newPath);
								delete(newPath);
							}
						}
					}
				}
			}
			else
			{
				std::vector<Edge> finalPath;
				for (unsigned int i = 0; i < temPath->edges.size(); i++)
				{
					finalPath.push_back(myGraph->edgesVector[temPath->edges[i]]);
				}

				double temDist = DFD(myGraph, finalPath, referencePath);
				if (temDist <= (myGraph->delta))
				{
					delete firstPath;
					lastPath = finalPath;
					(*pathDistance) = temDist;
					return true;
				}
			}
		}
		delete firstPath;
		return false;
	}
	else
	{
		return true;
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, %r12d
movq %r8, -0x60(%rbp)
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r14
leaq -0x78(%rbp), %r15
movq %r15, %rdi
movq %rdx, %rsi
callq 0x4bba
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %r12d, %ecx
callq 0x92e4
movl %eax, %ebx
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x91ae
callq 0x2130
testb %bl, %bl
jne 0x927e
leaq 0x38bf(%rip), %rdi      # 0xca7c
callq 0x21c0
callq 0x20d0
movq %rax, -0x58(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x40, %edi
callq 0x2150
movq %rax, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rax)
movq $0x0, 0x38(%rax)
movq %r14, %rdi
movq %rax, %rsi
movl %r12d, %edx
movq %r13, %rcx
callq 0x571d
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa536
movq %r15, %r14
addq $0x28, %r14
movq -0x60(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x9260
callq 0x20d0
subq -0x58(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x2e04(%rip), %xmm0     # 0xc050
ucomisd 0x3784(%rip), %xmm0     # 0xc9d8
jbe 0x928f
movq 0x10(%rbp), %rax
movl $0x1, (%rax)
movq (%r14), %rdi
testq %rdi, %rdi
je 0x926d
callq 0x2130
movq %r15, %rdi
callq 0x2130
leaq -0x50(%rbp), %rdi
callq 0xa85a
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x50(%rbp), %rsi
movq 0x20(%rsi), %rax
movq %rax, (%rax)
movupd (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups %xmm1, (%rax)
movupd %xmm0, (%rax)
addq $0x28, %rsi
callq 0x6dde
leaq -0x50(%rbp), %rdi
callq 0xa5cc
jmp 0x92d0
movq %rax, %rbx
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x92dc
callq 0x2130
jmp 0x92dc
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xa85a
movq %rbx, %rdi
callq 0x2220