// File: jkeys-ecg-nmsu[P]graph-with-search-algorithms/Dijkstra.cpp
// Function: Dijkstra_heap(Graph&, Node&)
void Dijkstra_heap(Graph & g, Node & s) {
	HeapPriorityQueue q(g);
	
	g.resetAllDist();	
	g.setDist(s, 0); //s is the root 
	
	q.insert(g, s);
	
	while ( !q.empty() ) {
		Node u = q.remove_min(g);
		
		//instead of using a decrease-key operation on the heap, 
		//we will simply insert redundant nodes and skip visited nodes;
		//this means more nodes will be inserted, but since heap is already logarithmic,
		//the increase in runtime will not be significant		
		if (g.visited(u)) continue; //skip already visited nodes
		
		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++) {
			int edgeWeight = findEdgeWeight(*v, uEdges);

			if(g.dist(*v) > g.dist(u) + edgeWeight || g.dist(*v) == M_INFINITY) {
				g.setDist(*v, g.dist(u) + edgeWeight);	
				q.insert(g, *v);						
			}
		} //end adjNodes loop
	} //end while		
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0xfd30
movq -0x8(%rbp), %rdi
callq 0x6810
jmp 0x1514b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorps %xmm0, %xmm0
callq 0x5d50
jmp 0x1515d
movq -0x8(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x2b50
jmp 0x1517a
movq -0x2c8(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0xb8(%rbp), %rdx
callq 0xfdf0
jmp 0x15193
leaq -0xb8(%rbp), %rdi
callq 0x2bd0
leaq -0x28(%rbp), %rdi
callq 0x16240
movb %al, -0x2c9(%rbp)
jmp 0x151b0
movb -0x2c9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x151c1
jmp 0x155e0
movq -0x8(%rbp), %rdx
leaq -0x138(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xfe50
jmp 0x151d7
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5fa0
movb %al, -0x2ca(%rbp)
jmp 0x151ef
movb -0x2ca(%rbp), %al
testb $0x1, %al
jne 0x151fb
jmp 0x15249
movl $0x2, -0x13c(%rbp)
jmp 0x15598
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x155f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x2bd0
jmp 0x155f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x155d2
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5c70
jmp 0x1525b
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x62e0
movq %rax, -0x2d8(%rbp)
jmp 0x15274
movq -0x2d8(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0x8750
jmp 0x15289
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x6360
movq %rax, -0x2e0(%rbp)
jmp 0x152a2
movq -0x2e0(%rbp), %rsi
leaq -0x188(%rbp), %rdi
callq 0x8870
jmp 0x152b7
leaq -0x170(%rbp), %rdi
callq 0x8780
movq %rax, -0x190(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x87e0
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x87b0
testb $0x1, %al
jne 0x152f9
jmp 0x15576
leaq -0x190(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x220(%rbp), %rdi
callq 0x2b50
jmp 0x15316
leaq -0x238(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x8870
jmp 0x1532b
leaq -0x220(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x14bb0
movsd %xmm0, -0x2e8(%rbp)
jmp 0x15348
movsd -0x2e8(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2fc(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x30b0
leaq -0x220(%rbp), %rdi
callq 0x2bd0
movl -0x2fc(%rbp), %eax
movl %eax, -0x19c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2f8(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x8810
movq -0x2f8(%rbp), %rdi
movq %rax, %rsi
callq 0x5fe0
movsd %xmm0, -0x2f0(%rbp)
jmp 0x153ae
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5fe0
movsd %xmm0, -0x308(%rbp)
jmp 0x153c8
movsd -0x2f0(%rbp), %xmm0
movsd -0x308(%rbp), %xmm1
cvtsi2sdl -0x19c(%rbp), %xmm2
addsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
ja 0x1543a
movq -0x8(%rbp), %rax
movq %rax, -0x318(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x8810
movq -0x318(%rbp), %rdi
movq %rax, %rsi
callq 0x5fe0
movsd %xmm0, -0x310(%rbp)
jmp 0x1541a
movsd -0x310(%rbp), %xmm0
movsd 0x4c3e(%rip), %xmm1     # 0x1a068
ucomisd %xmm1, %xmm0
jne 0x1555a
jp 0x1555a
movq -0x8(%rbp), %rax
movq %rax, -0x330(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x8810
movq %rax, -0x328(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5fe0
movsd %xmm0, -0x320(%rbp)
jmp 0x15472
movq -0x328(%rbp), %rsi
movq -0x330(%rbp), %rdi
movsd -0x320(%rbp), %xmm0
cvtsi2sdl -0x19c(%rbp), %xmm1
addsd %xmm1, %xmm0
callq 0x5d50
jmp 0x1549b
movq -0x8(%rbp), %rax
movq %rax, -0x338(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x8810
movq %rax, %rsi
leaq -0x2b8(%rbp), %rdi
callq 0x2b50
jmp 0x154c3
movq -0x338(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x2b8(%rbp), %rdx
callq 0xfdf0
jmp 0x154dc
leaq -0x2b8(%rbp), %rdi
callq 0x2bd0
jmp 0x1555a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x155c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x155ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x15532
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x30b0
leaq -0x220(%rbp), %rdi
callq 0x2bd0
jmp 0x155ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x2bd0
jmp 0x155ba
jmp 0x1555c
leaq -0x190(%rbp), %rdi
xorl %esi, %esi
callq 0x8830
movq %rax, -0x2c0(%rbp)
jmp 0x152ca
leaq -0x188(%rbp), %rdi
callq 0x30b0
leaq -0x170(%rbp), %rdi
callq 0x3530
movl $0x0, -0x13c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x2bd0
movl -0x13c(%rbp), %eax
testl %eax, %eax
je 0x155b5
jmp 0x155b0
jmp 0x1519f
jmp 0x1519f
leaq -0x188(%rbp), %rdi
callq 0x30b0
leaq -0x170(%rbp), %rdi
callq 0x3530
leaq -0x138(%rbp), %rdi
callq 0x2bd0
jmp 0x155f2
leaq -0x28(%rbp), %rdi
callq 0x16260
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x16260
movq -0x30(%rbp), %rdi
callq 0x23e0
nopw %cs:(%rax,%rax)