// File: /workspace/github_cpp_makefile_star2_O2/jkeys-ecg-nmsu[P]graph-with-search-algorithms/Dijkstra.cpp
// Function: Dijkstra_tmg(Graph&, Node&, Node&)
void Dijkstra_tmg(Graph & g, Node & s, Node & e) {
	HeapPriorityQueue q(g);
	list<int> path;
	
	g.resetAllDist();	
	g.setDist(s, 0); //s is the root 
	
	q.insert(g, s);
	
	while ( !q.empty() ) {
		Node u = q.remove_min(g);
		
		if (g.visited(u)) continue; //skip previously visited nodes		
		if (g.visited(e)) break;	//don't bother continuing once we've hit destination
		
		g.setVisited(u);
		
		set<Node> uAdjNodes = g.getAdjNodes(u);
		list<Edge> uEdges = g.getEdges(u);
		
		// for every adjacent node v: (u)--->(v)
		for(set<Node>::iterator v = uAdjNodes.begin(); v != uAdjNodes.end(); v++) {
			double edgeWeight = findEdgeWeight(*v, uEdges);

			if(g.dist(*v) > g.dist(u) + edgeWeight || g.dist(*v) == M_INFINITY) {
				g.setDist(*v, g.dist(u) + edgeWeight);								
				g.setParent(*v, u.id());
				q.insert(g, *v);						
			}
		} //end adjNodes loop
	} //end while		
		
	/**** dijkstra has been run on source waypoint, check if destination visited ****/
	
	if(!g.visited(e)) {
		cout << "No path from start waypoint to destination waypoint." << endl; 
		return; //print error and return 
	}
	
	/**** path has been found ****/
		
	cout << "Path found!\nStart waypoint id: " << s.id() << " name:" << s.name() << endl;
	cout << "End waypoint id:   " << e.id() << " name:" << e.name() << endl;
	
	int rover_prev;
	Node rover = g.getNode(e.id());
	
	
	while( rover.parent() != -1) {
		rover_prev = g.parent(rover);	
		
		path.push_front(rover.id());	
		
		if(rover_prev == -1 || rover_prev == rover.id()) 
			break;
		
		rover = g.getNode(rover_prev);	
	}
		 
	// cin.ignore();		
	cout << "Origin: " << endl;		
	for(list<int>::iterator i = path.begin(); i != path.end(); i++) {
		Node n = g.getNode(*i);
		if(n.name() == e.name()) cout << "Destination: " << endl;	
		
		cout << n.edgeRoads() << endl;
		cout << n.name() << " " << n.latitude() << " " << n.longitude() << endl;
	}
	
	cout << "Total distance: " << g.dist(e) << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdx, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdi, %r14
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x6ee6
leaq -0x78(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x45f0
xorpd %xmm0, %xmm0
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x3fba
leaq -0x230(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x28ba
leaq -0x58(%rbp), %rdi
leaq -0x230(%rbp), %rdx
movq %r14, %rsi
callq 0x6f48
leaq -0x230(%rbp), %rdi
callq 0x2918
leaq -0x118(%rbp), %rbx
leaq -0x130(%rbp), %r13
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x949c
movq %rbx, %rdi
leaq -0x58(%rbp), %rsi
movq %r14, %rdx
callq 0x6f72
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40e0
testb %al, %al
jne 0x9483
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x40e0
testb %al, %al
jne 0x9490
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3f40
movq %r14, %rdi
movq %rbx, %rsi
callq 0x428a
leaq -0x1b0(%rbp), %rdi
movq %rax, %rsi
callq 0x5516
movq %r14, %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42ce
leaq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x53ec
movq -0x198(%rbp), %rbx
leaq -0x1a8(%rbp), %rax
cmpq %rax, %rbx
je 0x9461
leaq 0x20(%rbx), %r12
leaq -0x330(%rbp), %rdi
movq %r12, %rsi
callq 0x28ba
movq %r13, %rdi
leaq -0x98(%rbp), %rsi
callq 0x53ec
movq %r13, %r14
leaq -0x330(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x8c54
movsd %xmm0, -0x40(%rbp)
movq %r14, %rdi
callq 0x2a4a
movq %r13, %rdi
callq 0x2918
movq %r15, %rdi
movq %r12, %rsi
callq 0x4106
movsd %xmm0, -0x60(%rbp)
movq %r14, %r13
movq %r15, %rdi
leaq -0x118(%rbp), %rsi
callq 0x4106
addsd -0x40(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x93e4
movq %r15, %rdi
movq %r12, %rsi
callq 0x4106
ucomisd 0x1c88(%rip), %xmm0     # 0xb068
jne 0x9451
jp 0x9451
movq %r15, %rdi
leaq -0x118(%rbp), %rsi
callq 0x4106
movsd -0x40(%rbp), %xmm1
addsd %xmm0, %xmm1
movq %r15, %rdi
movq %r12, %rsi
movapd %xmm1, %xmm0
callq 0x3fba
leaq -0x118(%rbp), %rdi
callq 0x6ac0
movq %r15, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x4014
leaq -0x2b0(%rbp), %rdi
movq %r12, %rsi
callq 0x28ba
leaq -0x58(%rbp), %rdi
movq %r15, %rsi
leaq -0x2b0(%rbp), %r14
movq %r14, %rdx
callq 0x6f48
movq %r14, %rdi
callq 0x2918
movq %rbx, %rdi
callq 0x2260
movq %rax, %rbx
jmp 0x933f
leaq -0x98(%rbp), %rdi
callq 0x2a4a
leaq -0x1b0(%rbp), %rdi
callq 0x2aa8
leaq -0x118(%rbp), %rbx
movq %r15, %r14
movq %rbx, %rdi
callq 0x2918
jmp 0x92b2
leaq -0x118(%rbp), %rdi
callq 0x2918
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x40e0
testb %al, %al
je 0x95ef
movq 0x8b19(%rip), %rdi      # 0x11fd0
leaq 0x2098(%rip), %rsi      # 0xb556
callq 0x2200
movq %rax, %rbx
movq -0x38(%rbp), %rdi
callq 0x6ac0
movq %rbx, %rdi
movl %eax, %esi
callq 0x2360
leaq 0x2096(%rip), %rsi      # 0xb576
movq %rax, %rdi
callq 0x2200
movq %rax, %rbx
movq -0x38(%rbp), %rdi
callq 0x6aca
movq %rbx, %rdi
movq %rax, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2120
movq 0x8ac2(%rip), %rdi      # 0x11fd0
leaq 0x2068(%rip), %rsi      # 0xb57d
callq 0x2200
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x6ac0
movq %rbx, %rdi
movl %eax, %esi
callq 0x2360
leaq 0x203f(%rip), %rsi      # 0xb576
movq %rax, %rdi
callq 0x2200
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x6aca
movq %rbx, %rdi
movq %rax, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2120
movq -0x30(%rbp), %rdi
callq 0x6ac0
movslq %eax, %rsi
movq %r14, %rdi
callq 0x36ce
leaq -0x118(%rbp), %rdi
movq %rax, %rsi
callq 0x28ba
leaq -0x118(%rbp), %rbx
leaq -0x1b0(%rbp), %r15
movq %rbx, %rdi
callq 0x6aac
cmpl $-0x1, %eax
je 0x960f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4250
movl %eax, %r12d
movq %rbx, %rdi
callq 0x6ac0
movl %eax, -0x1b0(%rbp)
leaq -0x78(%rbp), %rdi
movq %r15, %rsi
callq 0x9864
cmpl $-0x1, %r12d
je 0x960f
movq %rbx, %rdi
callq 0x6ac0
cmpl %eax, %r12d
je 0x960f
movslq %r12d, %rsi
movq %r14, %rdi
callq 0x36ce
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4ee6
jmp 0x958f
movq 0x89da(%rip), %rdi      # 0x11fd0
leaq 0x1f24(%rip), %rsi      # 0xb521
callq 0x2200
movq %rax, %rdi
callq 0x2120
jmp 0x977e
movq 0x89ba(%rip), %rdi      # 0x11fd0
leaq 0x1f74(%rip), %rsi      # 0xb591
callq 0x2200
movq %rax, %rdi
callq 0x2120
leaq -0x1b0(%rbp), %r12
leaq -0x98(%rbp), %r15
leaq -0x78(%rbp), %r13
movq (%r13), %r13
leaq -0x78(%rbp), %rax
cmpq %rax, %r13
je 0x9740
movslq 0x10(%r13), %rsi
movq %r14, %rdi
callq 0x36ce
movq %r12, %rdi
movq %rax, %rsi
callq 0x28ba
movq %r12, %rdi
callq 0x6aca
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x6aca
movq %rbx, %rdi
movq %rax, %rsi
callq 0x9874
testb %al, %al
je 0x96a2
movq 0x8942(%rip), %rdi      # 0x11fd0
leaq 0x1f05(%rip), %rsi      # 0xb59a
callq 0x2200
movq %rax, %rdi
callq 0x2120
movq %r15, %rdi
leaq -0x150(%rbp), %rsi
callq 0x22b0
movq 0x8918(%rip), %rdi      # 0x11fd0
movq %r15, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2120
movq %r15, %rdi
callq 0x2110
movq %r12, %rdi
callq 0x6aca
movq 0x88f1(%rip), %rdi      # 0x11fd0
movq %rax, %rsi
callq 0x21e0
movq %rax, %rdi
leaq 0x1e9e(%rip), %rsi      # 0xb58f
callq 0x2200
movq %rax, %rbx
movq %r12, %rdi
callq 0x6b08
movq %rbx, %rdi
callq 0x2320
movq %rax, %rdi
leaq 0x1e7c(%rip), %rsi      # 0xb58f
callq 0x2200
movq %rax, %rbx
movq %r12, %rdi
callq 0x6b14
movq %rbx, %rdi
callq 0x2320
movq %rax, %rdi
callq 0x2120
movq %r12, %rdi
callq 0x2918
jmp 0x963c
movq 0x8889(%rip), %rdi      # 0x11fd0
leaq 0x1e5a(%rip), %rsi      # 0xb5a8
callq 0x2200
movq %rax, %rbx
movq %r14, %rdi
movq -0x30(%rbp), %rsi
callq 0x4106
movq %rbx, %rdi
callq 0x2320
movq %rax, %rdi
callq 0x2120
leaq -0x118(%rbp), %rdi
callq 0x2918
leaq -0x78(%rbp), %rdi
callq 0x9898
leaq -0x58(%rbp), %rdi
callq 0x29d0
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x230(%rbp), %rdi
jmp 0x9845
jmp 0x97c2
jmp 0x97df
jmp 0x97df
jmp 0x97c2
jmp 0x97e4
movq %rax, %rbx
jmp 0x9832
jmp 0x97df
movq %rax, %rbx
jmp 0x984a
jmp 0x97df
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x2110
jmp 0x97e7
jmp 0x97df
movq %rax, %rbx
jmp 0x983e
movq %rax, %rbx
leaq -0x1b0(%rbp), %rdi
callq 0x2918
jmp 0x983e
movq %rax, %rbx
leaq -0x2b0(%rbp), %rdi
jmp 0x981c
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x2a4a
jmp 0x9815
movq %rax, %rbx
leaq -0x330(%rbp), %rdi
callq 0x2918
jmp 0x9826
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x2a4a
leaq -0x1b0(%rbp), %rdi
callq 0x2aa8
leaq -0x118(%rbp), %rdi
callq 0x2918
leaq -0x78(%rbp), %rdi
callq 0x9898
leaq -0x58(%rbp), %rdi
callq 0x29d0
movq %rbx, %rdi
callq 0x2370