// File: 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
subq $0x5f0, %rsp            # imm = 0x5F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xfd30
leaq -0x48(%rbp), %rdi
callq 0x16280
movq -0x8(%rbp), %rdi
callq 0x6810
jmp 0x15648
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorps %xmm0, %xmm0
callq 0x5d50
jmp 0x1565a
movq -0x8(%rbp), %rax
movq %rax, -0x430(%rbp)
movq -0x10(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x2b50
jmp 0x15677
movq -0x430(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0xfdf0
jmp 0x15690
leaq -0xd8(%rbp), %rdi
callq 0x2bd0
leaq -0x30(%rbp), %rdi
callq 0x16240
movb %al, -0x431(%rbp)
jmp 0x156ad
movb -0x431(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x156be
jmp 0x15b62
movq -0x8(%rbp), %rdx
leaq -0x158(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xfe50
jmp 0x156d4
movq -0x8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x5fa0
movb %al, -0x432(%rbp)
jmp 0x156ec
movb -0x432(%rbp), %al
testb $0x1, %al
jne 0x156f8
jmp 0x15746
movl $0x2, -0x15c(%rbp)
jmp 0x15b03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x161b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x2bd0
jmp 0x161b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x15b51
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5fa0
movb %al, -0x433(%rbp)
jmp 0x1575b
movb -0x433(%rbp), %al
testb $0x1, %al
jne 0x15767
jmp 0x15776
movl $0x3, -0x15c(%rbp)
jmp 0x15b03
movq -0x8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x5c70
jmp 0x15788
movq -0x8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x62e0
movq %rax, -0x440(%rbp)
jmp 0x157a1
movq -0x440(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x8750
jmp 0x157b6
movq -0x8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x6360
movq %rax, -0x448(%rbp)
jmp 0x157cf
movq -0x448(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x8870
jmp 0x157e4
leaq -0x190(%rbp), %rdi
callq 0x8780
movq %rax, -0x1b0(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x87e0
movq %rax, -0x1b8(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x87b0
testb $0x1, %al
jne 0x15826
jmp 0x15ae1
leaq -0x1b0(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x240(%rbp), %rdi
callq 0x2b50
jmp 0x15843
leaq -0x258(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x8870
jmp 0x15858
leaq -0x240(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x14bb0
movsd %xmm0, -0x450(%rbp)
jmp 0x15875
leaq -0x258(%rbp), %rdi
callq 0x30b0
leaq -0x240(%rbp), %rdi
callq 0x2bd0
movsd -0x450(%rbp), %xmm0
movsd %xmm0, -0x1c0(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x460(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x8810
movq -0x460(%rbp), %rdi
movq %rax, %rsi
callq 0x5fe0
movsd %xmm0, -0x458(%rbp)
jmp 0x158cd
movq -0x8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x5fe0
movsd %xmm0, -0x468(%rbp)
jmp 0x158e7
movsd -0x458(%rbp), %xmm0
movsd -0x468(%rbp), %xmm1
addsd -0x1c0(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x15955
movq -0x8(%rbp), %rax
movq %rax, -0x478(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x8810
movq -0x478(%rbp), %rdi
movq %rax, %rsi
callq 0x5fe0
movsd %xmm0, -0x470(%rbp)
jmp 0x15935
movsd -0x470(%rbp), %xmm0
movsd 0x4723(%rip), %xmm1     # 0x1a068
ucomisd %xmm1, %xmm0
jne 0x15ac5
jp 0x15ac5
movq -0x8(%rbp), %rax
movq %rax, -0x490(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x8810
movq %rax, -0x488(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x5fe0
movsd %xmm0, -0x480(%rbp)
jmp 0x1598d
movq -0x488(%rbp), %rsi
movq -0x490(%rbp), %rdi
movsd -0x480(%rbp), %xmm0
movsd -0x1c0(%rbp), %xmm1
addsd %xmm1, %xmm0
callq 0x5d50
jmp 0x159b6
movq -0x8(%rbp), %rax
movq %rax, -0x4a8(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x8810
movq %rax, -0x4a0(%rbp)
leaq -0x158(%rbp), %rdi
callq 0xed80
movl %eax, -0x494(%rbp)
jmp 0x159e8
movl -0x494(%rbp), %edx
movq -0x4a0(%rbp), %rsi
movq -0x4a8(%rbp), %rdi
callq 0x5df0
jmp 0x15a03
movq -0x8(%rbp), %rax
movq %rax, -0x4b0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x2d8(%rbp), %rdi
callq 0x2b50
jmp 0x15a2b
movq -0x4b0(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x2d8(%rbp), %rdx
callq 0xfdf0
jmp 0x15a44
leaq -0x2d8(%rbp), %rdi
callq 0x2bd0
jmp 0x15ac5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x15b45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x15b39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x15a9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x30b0
leaq -0x240(%rbp), %rdi
callq 0x2bd0
jmp 0x15b39
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x2bd0
jmp 0x15b39
jmp 0x15ac7
leaq -0x1b0(%rbp), %rdi
xorl %esi, %esi
callq 0x8830
movq %rax, -0x2e0(%rbp)
jmp 0x157f7
leaq -0x1a8(%rbp), %rdi
callq 0x30b0
leaq -0x190(%rbp), %rdi
callq 0x3530
movl $0x0, -0x15c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x2bd0
movl -0x15c(%rbp), %eax
movl %eax, -0x4b4(%rbp)
testl %eax, %eax
je 0x15b34
jmp 0x15b21
movl -0x4b4(%rbp), %eax
subl $0x2, %eax
je 0x1569c
jmp 0x15b32
jmp 0x15b62
jmp 0x1569c
leaq -0x1a8(%rbp), %rdi
callq 0x30b0
leaq -0x190(%rbp), %rdi
callq 0x3530
leaq -0x158(%rbp), %rdi
callq 0x2bd0
jmp 0x161b6
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5fa0
movb %al, -0x4b5(%rbp)
jmp 0x15b77
movb -0x4b5(%rbp), %al
testb $0x1, %al
jne 0x15bc3
jmp 0x15b83
movq 0x11446(%rip), %rdi     # 0x26fd0
leaq 0x4988(%rip), %rsi      # 0x1a519
callq 0x2240
movq %rax, -0x4c0(%rbp)
jmp 0x15b9f
movq -0x4c0(%rbp), %rdi
movq 0x11413(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x15bb4
movl $0x1, -0x15c(%rbp)
jmp 0x1618f
movq 0x11406(%rip), %rdi     # 0x26fd0
leaq 0x497d(%rip), %rsi      # 0x1a54e
callq 0x2240
movq %rax, -0x4c8(%rbp)
jmp 0x15bdf
movq -0x10(%rbp), %rdi
callq 0xed80
movl %eax, -0x4cc(%rbp)
jmp 0x15bf0
movl -0x4cc(%rbp), %esi
movq -0x4c8(%rbp), %rdi
callq 0x23d0
movq %rax, -0x4d8(%rbp)
jmp 0x15c0b
movq -0x4d8(%rbp), %rdi
leaq 0x4955(%rip), %rsi      # 0x1a56e
callq 0x2240
movq %rax, -0x4e0(%rbp)
jmp 0x15c27
movq -0x10(%rbp), %rdi
callq 0xeda0
movq %rax, -0x4e8(%rbp)
jmp 0x15c39
movq -0x4e8(%rbp), %rsi
movq -0x4e0(%rbp), %rdi
callq 0x2220
movq %rax, -0x4f0(%rbp)
jmp 0x15c55
movq -0x4f0(%rbp), %rdi
movq 0x1135d(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x15c6a
movq 0x1135f(%rip), %rdi     # 0x26fd0
leaq 0x48fd(%rip), %rsi      # 0x1a575
callq 0x2240
movq %rax, -0x4f8(%rbp)
jmp 0x15c86
movq -0x18(%rbp), %rdi
callq 0xed80
movl %eax, -0x4fc(%rbp)
jmp 0x15c97
movl -0x4fc(%rbp), %esi
movq -0x4f8(%rbp), %rdi
callq 0x23d0
movq %rax, -0x508(%rbp)
jmp 0x15cb2
movq -0x508(%rbp), %rdi
leaq 0x48ae(%rip), %rsi      # 0x1a56e
callq 0x2240
movq %rax, -0x510(%rbp)
jmp 0x15cce
movq -0x18(%rbp), %rdi
callq 0xeda0
movq %rax, -0x518(%rbp)
jmp 0x15ce0
movq -0x518(%rbp), %rsi
movq -0x510(%rbp), %rdi
callq 0x2220
movq %rax, -0x520(%rbp)
jmp 0x15cfc
movq -0x520(%rbp), %rdi
movq 0x112b6(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x15d11
movq -0x8(%rbp), %rax
movq %rax, -0x530(%rbp)
movq -0x18(%rbp), %rdi
callq 0xed80
movl %eax, -0x524(%rbp)
jmp 0x15d2d
movq -0x530(%rbp), %rdi
movl -0x524(%rbp), %eax
movslq %eax, %rsi
callq 0x5040
movq %rax, -0x538(%rbp)
jmp 0x15d4b
movq -0x538(%rbp), %rsi
leaq -0x368(%rbp), %rdi
callq 0x2b50
jmp 0x15d60
jmp 0x15d62
leaq -0x368(%rbp), %rdi
callq 0xed40
movl %eax, -0x53c(%rbp)
jmp 0x15d76
movl -0x53c(%rbp), %eax
cmpl $-0x1, %eax
je 0x15e5a
movq -0x8(%rbp), %rdi
leaq -0x368(%rbp), %rsi
callq 0x6240
movl %eax, -0x540(%rbp)
jmp 0x15d9d
movl -0x540(%rbp), %eax
movl %eax, -0x2e4(%rbp)
leaq -0x368(%rbp), %rdi
callq 0xed80
movl %eax, -0x544(%rbp)
jmp 0x15dbd
movl -0x544(%rbp), %eax
movl %eax, -0x36c(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x36c(%rbp), %rsi
callq 0x162a0
jmp 0x15ddb
cmpl $-0x1, -0x2e4(%rbp)
je 0x15e14
movl -0x2e4(%rbp), %eax
movl %eax, -0x54c(%rbp)
leaq -0x368(%rbp), %rdi
callq 0xed80
movl %eax, -0x548(%rbp)
jmp 0x15e04
movl -0x54c(%rbp), %eax
movl -0x548(%rbp), %ecx
cmpl %ecx, %eax
jne 0x15e27
jmp 0x15e5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x161aa
movq -0x8(%rbp), %rdi
movslq -0x2e4(%rbp), %rsi
callq 0x5040
movq %rax, -0x558(%rbp)
jmp 0x15e40
movq -0x558(%rbp), %rsi
leaq -0x368(%rbp), %rdi
callq 0x7b50
jmp 0x15e55
jmp 0x15d62
movq 0x1116f(%rip), %rdi     # 0x26fd0
leaq 0x4721(%rip), %rsi      # 0x1a589
callq 0x2240
movq %rax, -0x560(%rbp)
jmp 0x15e76
movq -0x560(%rbp), %rdi
movq 0x1113c(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x15e8b
leaq -0x48(%rbp), %rdi
callq 0x162e0
movq %rax, -0x378(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x16340
movq %rax, -0x380(%rbp)
leaq -0x378(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x16310
testb $0x1, %al
jne 0x15ec7
jmp 0x16114
movq -0x8(%rbp), %rax
movq %rax, -0x570(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x16370
movq -0x570(%rbp), %rdi
movslq (%rax), %rsi
callq 0x5040
movq %rax, -0x568(%rbp)
jmp 0x15ef6
movq -0x568(%rbp), %rsi
leaq -0x400(%rbp), %rdi
callq 0x2b50
jmp 0x15f0b
leaq -0x400(%rbp), %rdi
callq 0xeda0
movq %rax, -0x578(%rbp)
jmp 0x15f20
movq -0x18(%rbp), %rdi
callq 0xeda0
movq %rax, -0x580(%rbp)
jmp 0x15f32
movq -0x580(%rbp), %rsi
movq -0x578(%rbp), %rdi
callq 0x16390
testb $0x1, %al
jne 0x15f4b
jmp 0x15f8f
movq 0x1107e(%rip), %rdi     # 0x26fd0
leaq 0x4639(%rip), %rsi      # 0x1a592
callq 0x2240
movq %rax, -0x588(%rbp)
jmp 0x15f67
movq -0x588(%rbp), %rdi
movq 0x1104b(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x15f7c
jmp 0x15f8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x16103
leaq -0x420(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x7ce0
jmp 0x15fa4
movq 0x11025(%rip), %rdi     # 0x26fd0
leaq -0x420(%rbp), %rsi
callq 0x2220
movq %rax, -0x590(%rbp)
jmp 0x15fc0
movq -0x590(%rbp), %rdi
movq 0x10ff2(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x15fd5
leaq -0x420(%rbp), %rdi
callq 0x2170
leaq -0x400(%rbp), %rdi
callq 0xeda0
movq %rax, -0x598(%rbp)
jmp 0x15ff6
movq -0x598(%rbp), %rsi
movq 0x10fcc(%rip), %rdi     # 0x26fd0
callq 0x2220
movq %rax, -0x5a0(%rbp)
jmp 0x16012
movq -0x5a0(%rbp), %rdi
leaq 0x4567(%rip), %rsi      # 0x1a587
callq 0x2240
movq %rax, -0x5a8(%rbp)
jmp 0x1602e
leaq -0x400(%rbp), %rdi
callq 0xee50
movsd %xmm0, -0x5b0(%rbp)
jmp 0x16044
movsd -0x5b0(%rbp), %xmm0
movq -0x5a8(%rbp), %rdi
callq 0x2430
movq %rax, -0x5b8(%rbp)
jmp 0x16061
movq -0x5b8(%rbp), %rdi
leaq 0x4518(%rip), %rsi      # 0x1a587
callq 0x2240
movq %rax, -0x5c0(%rbp)
jmp 0x1607d
leaq -0x400(%rbp), %rdi
callq 0xee70
movsd %xmm0, -0x5c8(%rbp)
jmp 0x16093
movsd -0x5c8(%rbp), %xmm0
movq -0x5c0(%rbp), %rdi
callq 0x2430
movq %rax, -0x5d0(%rbp)
jmp 0x160b0
movq -0x5d0(%rbp), %rdi
movq 0x10f02(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x160c5
leaq -0x400(%rbp), %rdi
callq 0x2bd0
leaq -0x378(%rbp), %rdi
xorl %esi, %esi
callq 0x16420
movq %rax, -0x428(%rbp)
jmp 0x15e9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x2170
leaq -0x400(%rbp), %rdi
callq 0x2bd0
jmp 0x161aa
movq 0x10eb5(%rip), %rdi     # 0x26fd0
leaq 0x447e(%rip), %rsi      # 0x1a5a0
callq 0x2240
movq %rax, -0x5d8(%rbp)
jmp 0x16130
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5fe0
movsd %xmm0, -0x5e0(%rbp)
jmp 0x16147
movsd -0x5e0(%rbp), %xmm0
movq -0x5d8(%rbp), %rdi
callq 0x2430
movq %rax, -0x5e8(%rbp)
jmp 0x16164
movq -0x5e8(%rbp), %rdi
movq 0x10e4e(%rip), %rsi     # 0x26fc0
callq 0x2280
jmp 0x16179
leaq -0x368(%rbp), %rdi
callq 0x2bd0
movl $0x0, -0x15c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x16450
leaq -0x30(%rbp), %rdi
callq 0x16260
addq $0x5f0, %rsp            # imm = 0x5F0
popq %rbp
retq
leaq -0x368(%rbp), %rdi
callq 0x2bd0
leaq -0x48(%rbp), %rdi
callq 0x16450
leaq -0x30(%rbp), %rdi
callq 0x16260
movq -0x50(%rbp), %rdi
callq 0x23e0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)