// File: /workspace/github_cpp_makefile_star2_O2/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, %ebx
movq %r8, -0x30(%rbp)
movq %rcx, -0x68(%rbp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r15
leaq -0x80(%rbp), %r14
movq %r14, %rdi
movq %rdx, %rsi
callq 0x3fbc
movq %r15, %rdi
movq %r13, -0x60(%rbp)
movq %r13, %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x7cfc
movl %eax, %r13d
leaq -0x80(%rbp), %rdi
callq 0x4092
testb %r13b, %r13b
jne 0x7c81
leaq 0x2e75(%rip), %rdi      # 0xaa4c
callq 0x21a0
callq 0x20c0
movq %rax, -0x58(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
pushq $0x40
popq %rdi
callq 0x2110
movq %rax, %r14
xorpd %xmm0, %xmm0
movupd %xmm0, 0x28(%rax)
andq $0x0, 0x38(%rax)
movq %r15, %rdi
movq %rax, %rsi
movl %ebx, %edx
movq %r12, %rcx
callq 0x47ac
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x889e
movq -0x30(%rbp), %rax
andl $0x0, 0x10(%rax)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x7c64
callq 0x20c0
subq -0x58(%rbp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x2400(%rip), %xmm0     # 0xa050
ucomisd 0x2d50(%rip), %xmm0     # 0xa9a8
jbe 0x7c93
movq 0x10(%rbp), %rax
movl $0x1, (%rax)
movq %r14, %rdi
addq $0x28, %rdi
callq 0x5924
movq %r14, %rdi
callq 0x20f0
leaq -0x50(%rbp), %rdi
callq 0x8ab0
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x50(%rbp), %rsi
callq 0x57ee
leaq -0x50(%rbp), %rdi
callq 0x88be
movq -0x30(%rbp), %rax
incl 0x10(%rax)
movq -0x68(%rbp), %rbx
movq -0x60(%rbp), %r14
movq %r15, %rdi
callq 0x5480
movq %r15, %rdi
callq 0x5303
movq %r15, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x689b
jmp 0x7cb4
jmp 0x7cd6
jmp 0x7ceb
jmp 0x7ce8
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x4092
jmp 0x7cf4
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x8ab0
movq %rbx, %rdi
callq 0x2200