// File: 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
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdx, -0x130(%rbp)
movq %rsi, %rax
movq -0x130(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq 0x10(%rbp), %rdx
movq %rdi, -0x10(%rbp)
movq %rax, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x53c0
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
movl -0x34(%rbp), %ecx
callq 0x113d0
movb %al, -0x109(%rbp)
jmp 0x10c27
movb -0x109(%rbp), %al
xorb $-0x1, %al
movb %al, -0x131(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x54b0
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x10c4d
jmp 0x113b4
leaq 0x8e19(%rip), %rdi      # 0x19a6d
xorl %eax, %eax
callq 0x2040
callq 0x2100
movq %rax, -0x68(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x14230
movl $0x40, %edi
callq 0x2170
movq %rax, -0x140(%rbp)
jmp 0x10c83
movq -0x140(%rbp), %rdi
callq 0x141f0
movq -0x140(%rbp), %rax
movq -0x130(%rbp), %rcx
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x6d40
jmp 0x10cb9
movq -0x98(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x14260
jmp 0x10cce
movq -0x30(%rbp), %rax
movl $0x0, 0x10(%rax)
leaq -0x90(%rbp), %rdi
callq 0x142b0
movb %al, -0x141(%rbp)
jmp 0x10ced
movb -0x141(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x10cfe
jmp 0x1135e
callq 0x2100
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
subq -0x68(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x82ec(%rip), %xmm1     # 0x19008
divsd %xmm1, %xmm0
movsd 0x8cd8(%rip), %xmm1     # 0x19a00
ucomisd %xmm1, %xmm0
jbe 0x10da2
movq 0x10(%rbp), %rax
movl $0x1, (%rax)
movq -0x98(%rbp), %rax
movq %rax, -0x150(%rbp)
cmpq $0x0, %rax
je 0x10d64
movq -0x150(%rbp), %rdi
callq 0x14210
movq -0x150(%rbp), %rdi
callq 0x2150
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x11398
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x54b0
jmp 0x113c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x113a6
leaq -0x90(%rbp), %rdi
callq 0x142d0
movq %rax, -0x158(%rbp)
jmp 0x10db7
movq -0x158(%rbp), %rsi
movq -0xa0(%rbp), %rdi
callq 0x9120
jmp 0x10dcc
leaq -0x90(%rbp), %rdi
callq 0x142f0
jmp 0x10dda
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0xa0(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x1118c
movl $0x0, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xa0(%rbp), %rax
movslq 0x8(%rax), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
addq $0x40, %rdi
callq 0x90e0
movq %rax, %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
jae 0x11187
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xa0(%rbp), %rax
movslq 0x8(%rax), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
addq $0x40, %rdi
movl -0xa8(%rbp), %eax
movl %eax, %esi
callq 0x9100
movl (%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xac(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movb 0x11(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x11171
movq -0x10(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movl -0xac(%rbp), %edx
callq 0x8660
movb %al, -0x161(%rbp)
jmp 0x10ec3
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x10ed2
jmp 0x11171
movl $0x40, %edi
callq 0x2170
movq %rax, -0x170(%rbp)
jmp 0x10ee5
movq -0x170(%rbp), %rdi
callq 0x141f0
movq -0x170(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
movl -0xac(%rbp), %ecx
callq 0x8420
jmp 0x10f1e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xb8(%rbp), %rcx
movslq 0x8(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x1106d
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl 0x8(%rsi), %r8d
callq 0xcb30
movsd %xmm0, -0x178(%rbp)
jmp 0x10f6f
movsd -0x178(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xc0(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x11011
movq -0x98(%rbp), %rax
movq %rax, -0x180(%rbp)
cmpq $0x0, %rax
je 0x10fc2
movq -0x180(%rbp), %rdi
callq 0x14210
movq -0x180(%rbp), %rdi
callq 0x2150
movq -0xb8(%rbp), %rax
movq %rax, -0x188(%rbp)
cmpq $0x0, %rax
je 0x10fee
movq -0x188(%rbp), %rdi
callq 0x14210
movq -0x188(%rbp), %rdi
callq 0x2150
movsd -0xc0(%rbp), %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x11398
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x11066
movq -0x18(%rbp), %rax
movb 0xc(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x11066
movq -0xb8(%rbp), %rax
movq %rax, -0x190(%rbp)
cmpq $0x0, %rax
je 0x11061
movq -0x190(%rbp), %rdi
callq 0x14210
movq -0x190(%rbp), %rdi
callq 0x2150
jmp 0x11173
jmp 0x11068
jmp 0x1116f
movq -0x10(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x11cc0
movb %al, -0x191(%rbp)
jmp 0x1108d
movb -0x191(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd 0x890c(%rip), %xmm1     # 0x199c0
ucomisd %xmm1, %xmm0
jne 0x110c1
jp 0x110c1
jmp 0x1116d
movsd -0xc8(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1116d
movsd -0xc8(%rbp), %xmm0
movq -0xb8(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movsd -0xc8(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0xb8(%rbp), %rax
movslq 0x8(%rax), %rdx
imulq $0x70, %rdx, %rdx
movsd 0x38(%rcx,%rdx), %xmm1
movsd 0x88eb(%rip), %xmm2     # 0x19a08
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
movq -0xb8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x14260
jmp 0x1113f
movq -0xb8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
cmpq $0x0, %rax
je 0x1116b
movq -0x1a0(%rbp), %rdi
callq 0x14210
movq -0x1a0(%rbp), %rdi
callq 0x2150
jmp 0x1116d
jmp 0x1116f
jmp 0x11171
jmp 0x11173
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x10e08
jmp 0x11359
leaq -0xe0(%rbp), %rdi
callq 0x53a0
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movq %rax, -0x1a8(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x28, %rdi
callq 0x90e0
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1123b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1b0(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x28, %rdi
movl -0xe4(%rbp), %eax
movl %eax, %esi
callq 0x9100
movq -0x1b0(%rbp), %rsi
movslq (%rax), %rax
shlq $0x5, %rax
addq %rax, %rsi
leaq -0xe0(%rbp), %rdi
callq 0x55f0
jmp 0x11214
jmp 0x11216
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x111a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1134b
movq -0x10(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x53c0
jmp 0x1125b
movq -0x1b8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x108(%rbp), %rsi
callq 0xce50
movsd %xmm0, -0x1c0(%rbp)
jmp 0x1127c
leaq -0x108(%rbp), %rdi
callq 0x54b0
movsd -0x1c0(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0xf0(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x11327
movq -0x98(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, %rax
je 0x112db
movq -0x1c8(%rbp), %rdi
callq 0x14210
movq -0x1c8(%rbp), %rdi
callq 0x2150
movq -0x28(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xd650
jmp 0x112ed
movsd -0xf0(%rbp), %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x11331
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x54b0
jmp 0x1134b
movl $0x0, -0xa4(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x54b0
movl -0xa4(%rbp), %eax
testl %eax, %eax
jne 0x11398
jmp 0x11349
jmp 0x11359
leaq -0xe0(%rbp), %rdi
callq 0x54b0
jmp 0x113a6
jmp 0x10cd9
movq -0x98(%rbp), %rax
movq %rax, -0x1d0(%rbp)
cmpq $0x0, %rax
je 0x1138a
movq -0x1d0(%rbp), %rdi
callq 0x14210
movq -0x1d0(%rbp), %rdi
callq 0x2150
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa4(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x14340
jmp 0x113b8
leaq -0x90(%rbp), %rdi
callq 0x14340
jmp 0x113c6
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x2240
nop