// File: Proudc[P]CTSS/src/ContinuousQuery/Pruneline.cpp
// Function: roadSimleQueryPathWithLoop(Graph*, ReferencePath*, std::vector<Edge, std::allocator<Edge>>, std::vector<Edge, std::allocator<Edge>>&, Record*, int, int*, double*)
bool roadSimleQueryPathWithLoop(Graph* myGraph, ReferencePath* referencePath, std::vector<Edge> currentPath, 
	std::vector<Edge>& lastPath, Record* temRecord, int currentVertex, int* timeOutFlag, double* pathDistance)
{
	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->edges.size() == 4990)
		{
			continue;
		}

		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 (checkIfAccess(myGraph, temPath, nextVertexID))
				{

					double maxEuc = 0;
					double beginEuc;
					double endEuc;
					for (unsigned int j = myGraph->vertexsVector[nextVertexID].minPos; j <= myGraph->vertexsVector[nextVertexID].maxPos; j++)
					{
						double x1 = myGraph->vertexsVector[nextVertexID].longitude;
						double y1 = myGraph->vertexsVector[nextVertexID].latitude;
						double x2 = referencePath->pointOfRefer[j].x;
						double y2 = referencePath->pointOfRefer[j].y;
						double eucDist = euc(x1, y1, x2, y2);
						if (j == myGraph->vertexsVector[nextVertexID].minPos)
						{
							beginEuc = eucDist;
						}
						if (j == myGraph->vertexsVector[nextVertexID].maxPos)
						{
							endEuc = eucDist;
						}
						if (eucDist <= (myGraph->delta))
						{
							maxEuc = (std::max)(eucDist, maxEuc);
						}
					}
					if ((abs(maxEuc - beginEuc) < 0.000001) || (abs(maxEuc - endEuc) < 0.000001))
					{
						continue;
					}

					if ((myGraph->vertexsVector[nextVertexID].locationFlag == true))
					{
						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;
			}
		}
	}
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdx, -0x148(%rbp)
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
callq 0x2100
movq %rax, -0x40(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x14230
movl $0x40, %edi
callq 0x2170
movq %rax, -0x140(%rbp)
jmp 0x12d27
movq -0x140(%rbp), %rdi
callq 0x141f0
movq -0x140(%rbp), %rax
movq -0x148(%rbp), %rcx
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x6d40
jmp 0x12d57
movq -0x70(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x14260
jmp 0x12d66
movq -0x30(%rbp), %rax
movl $0x0, 0x10(%rax)
leaq -0x68(%rbp), %rdi
callq 0x142b0
movb %al, -0x149(%rbp)
jmp 0x12d82
movb -0x149(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x12d93
jmp 0x13628
callq 0x2100
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
subq -0x40(%rbp), %rax
cvtsi2sd %rax, %xmm0
movsd 0x6257(%rip), %xmm1     # 0x19008
divsd %xmm1, %xmm0
movsd 0x6c43(%rip), %xmm1     # 0x19a00
ucomisd %xmm1, %xmm0
jbe 0x12e1a
movq 0x10(%rbp), %rax
movl $0x1, (%rax)
movq -0x70(%rbp), %rax
movq %rax, -0x158(%rbp)
cmpq $0x0, %rax
je 0x12df6
movq -0x158(%rbp), %rdi
callq 0x14210
movq -0x158(%rbp), %rdi
callq 0x2150
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x13636
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x1364d
leaq -0x68(%rbp), %rdi
callq 0x142d0
movq %rax, -0x160(%rbp)
jmp 0x12e2c
movq -0x160(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x9120
jmp 0x12e41
leaq -0x68(%rbp), %rdi
callq 0x142f0
jmp 0x12e4c
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x88(%rbp), %rdi
addq $0x28, %rdi
callq 0x90e0
cmpq $0x137e, %rax           # imm = 0x137E
jne 0x12e76
jmp 0x12d71
movq -0x88(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x13459
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
movq %rax, -0x168(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x88(%rbp), %rax
movslq 0x8(%rax), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
addq $0x40, %rdi
callq 0x90e0
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
jae 0x13454
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x88(%rbp), %rcx
movslq 0x8(%rcx), %rcx
imulq $0x70, %rcx, %rcx
leaq 0x40(%rax,%rcx), %rdi
movl -0x90(%rbp), %eax
movl %eax, %esi
callq 0x9100
movl (%rax), %eax
movl %eax, -0x94(%rbp)
movq -0x10(%rbp), %rdi
movq -0x88(%rbp), %rsi
movl -0x94(%rbp), %edx
callq 0x8660
movb %al, -0x169(%rbp)
jmp 0x12f29
movb -0x169(%rbp), %al
testb $0x1, %al
jne 0x12f38
jmp 0x1343e
xorps %xmm0, %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x94(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x94(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x13105
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x94(%rbp), %rcx
imulq $0x70, %rcx, %rcx
movsd 0x18(%rax,%rcx), %xmm0
movsd %xmm0, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x94(%rbp), %rcx
imulq $0x70, %rcx, %rcx
movsd 0x20(%rax,%rcx), %xmm0
movsd %xmm0, -0xc8(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xb4(%rbp), %ecx
shlq $0x4, %rcx
movsd (%rax,%rcx), %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0xb4(%rbp), %ecx
shlq $0x4, %rcx
movsd 0x8(%rax,%rcx), %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd -0xc8(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm3
callq 0x7780
movsd %xmm0, -0x178(%rbp)
jmp 0x13037
movsd -0x178(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movl -0xb4(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x94(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0x13078
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movl -0xb4(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x94(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0x130a9
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xe0(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x130ef
leaq -0xe0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x9020
movq %rax, -0x180(%rbp)
jmp 0x130dc
movq -0x180(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
jmp 0x130f1
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x12f62
movsd -0xa0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
subsd %xmm1, %xmm0
callq 0x14360
movsd %xmm0, -0x188(%rbp)
jmp 0x13128
movsd -0x188(%rbp), %xmm1
movsd 0x68d8(%rip), %xmm0     # 0x19a10
ucomisd %xmm1, %xmm0
ja 0x13177
movsd -0xa0(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
subsd %xmm1, %xmm0
callq 0x14360
movsd %xmm0, -0x190(%rbp)
jmp 0x13161
movsd -0x190(%rbp), %xmm1
movsd 0x689f(%rip), %xmm0     # 0x19a10
ucomisd %xmm1, %xmm0
jbe 0x1317c
jmp 0x13440
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x94(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movb 0x11(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x1343c
movl $0x40, %edi
callq 0x2170
movq %rax, -0x198(%rbp)
jmp 0x131b6
movq -0x198(%rbp), %rdi
callq 0x141f0
movq -0x198(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movl -0x94(%rbp), %ecx
callq 0x8420
jmp 0x131ef
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xe8(%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 0x1333b
movq -0x10(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl 0x8(%rsi), %r8d
callq 0xcb30
movsd %xmm0, -0x1a0(%rbp)
jmp 0x13240
movsd -0x1a0(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0xf0(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x132df
movq -0x70(%rbp), %rax
movq %rax, -0x1a8(%rbp)
cmpq $0x0, %rax
je 0x13290
movq -0x1a8(%rbp), %rdi
callq 0x14210
movq -0x1a8(%rbp), %rdi
callq 0x2150
movq -0xe8(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpq $0x0, %rax
je 0x132bc
movq -0x1b0(%rbp), %rdi
callq 0x14210
movq -0x1b0(%rbp), %rdi
callq 0x2150
movsd -0xf0(%rbp), %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x13636
movq -0xe8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x13334
movq -0x18(%rbp), %rax
movb 0xc(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x13334
movq -0xe8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
je 0x1332f
movq -0x1b8(%rbp), %rdi
callq 0x14210
movq -0x1b8(%rbp), %rdi
callq 0x2150
jmp 0x13440
jmp 0x13336
jmp 0x1343a
movq -0x10(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x18(%rbp), %rcx
callq 0x11cc0
movb %al, -0x1b9(%rbp)
jmp 0x1335b
movb -0x1b9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd 0x663e(%rip), %xmm1     # 0x199c0
ucomisd %xmm1, %xmm0
jne 0x1338f
jp 0x1338f
jmp 0x13438
movsd -0xf8(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x13438
movsd -0xf8(%rbp), %xmm0
movq -0xe8(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movsd -0xf8(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0xe8(%rbp), %rax
movslq 0x8(%rax), %rdx
imulq $0x70, %rdx, %rdx
movsd 0x38(%rcx,%rdx), %xmm1
movsd 0x661d(%rip), %xmm2     # 0x19a08
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
movq -0xe8(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x14260
jmp 0x1340a
movq -0xe8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, %rax
je 0x13436
movq -0x1c8(%rbp), %rdi
callq 0x14210
movq -0x1c8(%rbp), %rdi
callq 0x2150
jmp 0x13438
jmp 0x1343a
jmp 0x1343c
jmp 0x1343e
jmp 0x13440
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x12e97
jmp 0x13623
leaq -0x110(%rbp), %rdi
callq 0x53a0
movl $0x0, -0x114(%rbp)
movl -0x114(%rbp), %eax
movq %rax, -0x1d0(%rbp)
movq -0x88(%rbp), %rdi
addq $0x28, %rdi
callq 0x90e0
movq %rax, %rcx
movq -0x1d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x13508
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1d8(%rbp)
movq -0x88(%rbp), %rdi
addq $0x28, %rdi
movl -0x114(%rbp), %eax
movl %eax, %esi
callq 0x9100
movq -0x1d8(%rbp), %rsi
movslq (%rax), %rax
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x110(%rbp), %rdi
callq 0x55f0
jmp 0x134e1
jmp 0x134e3
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x1346f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x13615
movq -0x10(%rbp), %rax
movq %rax, -0x1e0(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x53c0
jmp 0x13528
movq -0x1e0(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x138(%rbp), %rsi
callq 0xce50
movsd %xmm0, -0x1e8(%rbp)
jmp 0x13549
leaq -0x138(%rbp), %rdi
callq 0x54b0
movsd -0x1e8(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
movsd -0x120(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
ucomisd %xmm1, %xmm0
jb 0x135f1
movq -0x70(%rbp), %rax
movq %rax, -0x1f0(%rbp)
cmpq $0x0, %rax
je 0x135a5
movq -0x1f0(%rbp), %rdi
callq 0x14210
movq -0x1f0(%rbp), %rdi
callq 0x2150
movq -0x28(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xd650
jmp 0x135b7
movsd -0x120(%rbp), %xmm0
movq 0x18(%rbp), %rax
movsd %xmm0, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x135fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x54b0
jmp 0x13615
movl $0x0, -0x8c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x54b0
movl -0x8c(%rbp), %eax
testl %eax, %eax
jne 0x13636
jmp 0x13613
jmp 0x13623
leaq -0x110(%rbp), %rdi
callq 0x54b0
jmp 0x1364d
jmp 0x12d71
movb $0x0, -0x1(%rbp)
movl $0x1, -0x8c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x14340
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x14340
movq -0x78(%rbp), %rdi
callq 0x2240
nop