// File: Proudc[P]CTSS/src/ContinuousQuery/Frechet.cpp
// Function: dfdDistBetweenTwoPaths(Graph*, TraversingPath*, ReferencePath*, std::vector<Edge, std::allocator<Edge>>&, int)
double dfdDistBetweenTwoPaths(Graph* myGraph, TraversingPath* temPath, ReferencePath* referencePath, std::vector<Edge>& lastPath, int finalVertexID)
{
	// printf("Start calculating the dfd between a half path and the reference path...\n");
	std::vector<Edge> finalPath;
	for (unsigned int i = 0; i < temPath->edges.size(); i++)
	{
		finalPath.push_back(myGraph->edgesVector[temPath->edges[i]]);
	}
	int pos;
	for (int i = (referencePath->edges.size()) - 1; i >= 0; i--)
	{
		int firstVertexID = referencePath->edges[i].firstVertexID;
		int secVertexID   = referencePath->edges[i].secVertexID;
		if ((firstVertexID == finalVertexID) || (secVertexID == finalVertexID))
		{
			pos = i;
			break;
		}
	}
	for (unsigned int i = pos; i < referencePath->edges.size(); i++)
	{
		finalPath.push_back(referencePath->edges[i]);
	}

	lastPath = finalPath;

	std::vector<Point> temPointList = creatTrajPoint(myGraph, finalPath, referencePath->initialVertex);
	Point p[temPointList.size()];
	for (unsigned int i = 0; i < temPointList.size(); i++)
	{
		p[i].x = temPointList[i].x;
		p[i].y = temPointList[i].y;
	}
	double temDist = dfdDist(temPointList.size(), referencePath->numOfReferPoint, p, referencePath->pointOfRefer);
	return temDist;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x53a0
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0x90e0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq %rcx, %rax
jae 0xcbe0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
movl -0x44(%rbp), %eax
movl %eax, %esi
callq 0x9100
movq -0xb0(%rbp), %rsi
movslq (%rax), %rax
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x55f0
jmp 0xcbc2
jmp 0xcbc4
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xcb5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xce31
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0x5360
subq $0x1, %rax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0xcc4d
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x5380
movl 0x4(%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x5380
movl 0x8(%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0xcc38
movl -0x64(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0xcc40
movl -0x5c(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0xcc4d
jmp 0xcc42
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xcbf4
movl -0x58(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0x5360
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
jae 0xcca6
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
movl -0x68(%rbp), %eax
movl %eax, %esi
callq 0x5380
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x55f0
jmp 0xcc99
jmp 0xcc9b
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xcc53
movq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xd650
jmp 0xccb5
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq -0x80(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0xb430
jmp 0xccce
leaq -0x80(%rbp), %rdi
callq 0xb970
movq %rax, %rdx
movq %rdx, %rax
movq %rsp, %rcx
movq %rcx, -0x88(%rbp)
shlq $0x4, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xc0(%rbp)
movq %rcx, %rsp
movq %rax, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq %rax, -0xc8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xb970
movq %rax, %rcx
movq -0xc8(%rbp), %rax
cmpq %rcx, %rax
jae 0xcda7
movl -0x94(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0xb990
movq %rax, %rcx
movq -0xc0(%rbp), %rax
movsd (%rcx), %xmm0
movl -0x94(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, (%rax)
movl -0x94(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0xb990
movq %rax, %rcx
movq -0xc0(%rbp), %rax
movsd 0x8(%rcx), %xmm0
movl -0x94(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xcd0c
leaq -0x80(%rbp), %rdi
callq 0xb970
movq -0xc0(%rbp), %rdx
movl %eax, %edi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
movq 0x10(%rax), %rcx
callq 0xc5b0
movsd %xmm0, -0xd0(%rbp)
jmp 0xcdd3
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x88(%rbp), %rax
movq %rax, %rsp
leaq -0x80(%rbp), %rdi
callq 0xb910
leaq -0x40(%rbp), %rdi
callq 0x54b0
movsd -0xd8(%rbp), %xmm0
movq %rbp, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xb910
leaq -0x40(%rbp), %rdi
callq 0x54b0
movq -0x50(%rbp), %rdi
callq 0x2240
nopw %cs:(%rax,%rax)