// File: /workspace/github_cpp_makefile_star2_O3/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, -0x30(%rbp)
movq %rcx, -0x68(%rbp)
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %r15
leaq -0x80(%rbp), %rbx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x4bd6
movq %r15, %rdi
movq %r13, -0x60(%rbp)
movq %r13, %rsi
movq %rbx, %rdx
movl %r12d, %ecx
callq 0x9198
movl %eax, %r13d
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x902d
callq 0x2120
testb %r13b, %r13b
jne 0x90fe
leaq 0x3a3f(%rip), %rdi      # 0xca7c
callq 0x21b0
callq 0x20d0
movq %rax, -0x58(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x40, %edi
callq 0x2140
movq %rax, %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rax)
movq $0x0, 0x38(%rax)
movq %r15, %rdi
movq %rax, %rsi
movl %r12d, %edx
movq %r14, %rcx
callq 0x573d
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0xa36a
movq %rbx, %r14
addq $0x28, %r14
movq -0x30(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x90e0
callq 0x20d0
subq -0x58(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x2f84(%rip), %xmm0     # 0xc050
ucomisd 0x3904(%rip), %xmm0     # 0xc9d8
jbe 0x9110
movq 0x10(%rbp), %rax
movl $0x1, (%rax)
movq (%r14), %rdi
testq %rdi, %rdi
je 0x90ed
callq 0x2120
movq %rbx, %rdi
callq 0x2120
leaq -0x50(%rbp), %rdi
callq 0xa664
movl %r13d, %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 0x6cbc
leaq -0x50(%rbp), %rdi
callq 0xa400
movq -0x30(%rbp), %rax
incl 0x10(%rax)
movq -0x68(%rbp), %rbx
movq -0x60(%rbp), %r14
movq %r15, %rdi
callq 0x6844
movq %r15, %rdi
callq 0x64a3
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x7c40
jmp 0x914b
jmp 0x916d
jmp 0x9187
jmp 0x9184
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x9190
callq 0x2120
jmp 0x9190
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xa664
movq %rbx, %rdi
callq 0x2210