// File: flastest[P]HeterogeneousParallelDijkstra/BGL_Dijkstra.cc
// Function: dijkstra_shortest_paths_swag_version(boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS> const&, unsigned long const&, std::map<unsigned long, unsigned long, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, unsigned long>>>&)
distance_map_t dijkstra_shortest_paths_swag_version(
						const graph_t &graph, 
						const vertex_descriptor &source, 
						predecessor_map_t& predecessors)
{

	distance_map_t distances = initialize_distances_from_source(graph);



	//for using BGL's graph_t (adjacency table):
	//https://www.boost.org/doc/libs/1_60_0/libs/graph/doc/adjacency_list.html


	//set the source node's distance from source to zero
	distances[source] = 0;

	//this will keep track of all the vectors that have already found
	//a path to source
	vector<vertex_descriptor> finalized;


	//pq holds all the unchecked nodes
	std::priority_queue<vertex_descriptor, std::vector<vertex_descriptor>, VertexComparator> pq(VertexComparator{distances});

	//	priority_queue<vertex_descriptor, vector<vertex_descriptor>, compareFunctor(&distances)> pq;

	//now to enqueue source's neighbors in the pqueue
	pq.push(source);
	auto [start, finish] = out_edges(source,graph);
	for(;start != finish; start++)
	{
		pq.push(target(*start,graph));
	}


	const auto weight = get(edge_weight, graph);


	while (!pq.empty()){
		if (DEBUG) cout<<"pq isn't empty"<<endl;
		vertex_descriptor closest = pq.top();
		finalized.push_back(closest);
		if (DEBUG) cout<< "closest is " << closest << endl;
		pq.pop();
		

		//check all neighbors of current node
		auto [start, finish] = out_edges(closest,graph);

		for(;start != finish; start++)
		{
			if (DEBUG) cout<< "iterating through the out edges"<<endl;

			vertex_descriptor neighbor = target(*start, graph);
			



			//https://www.boost.org/doc/libs/1_60_0/libs/graph/doc/graph_concepts.html

			float weight_of_edge = get(weight, *start); //get edge weight here



			//if neighbor isn't in finalized
			if (find(finalized.cbegin(),finalized.cend(),neighbor) == finalized.cend())
			
			{
				if (DEBUG) cout<<"neighbor isn't in finalized"<<std::endl;
				//then determine if its value needs to be updated
				
				float newDist = distances[closest] + weight_of_edge;
				if (DEBUG) cout<<"newdist is " << newDist << " which is " << distances[closest] << " and " << weight_of_edge << endl;

				if (newDist < distances[neighbor])
				{
					if (DEBUG) std::cout<< newDist << " is closer than " << distances[neighbor] << std::endl;
					distances[neighbor] = newDist;
					pq.push(vertex(neighbor,graph));


					// if the new distance is better than the old heuristic,
					// then update the pqueue
					predecessors[neighbor] = closest;					
				}
			}
		}
	}

	return distances;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x1c0(%rbp)
movq %rdi, %rax
movq %rax, -0x1c8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movq -0x10(%rbp), %rsi
callq 0x1abd0
movq -0x1c0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1da20
movq %rax, -0x1b8(%rbp)
jmp 0x1acf2
movq -0x1b8(%rbp), %rax
movl $0x0, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x110d0
movq -0x1c0(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x1db00
jmp 0x1ad1a
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
leaq -0x90(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x110d0
movq -0x1d0(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x1db20
jmp 0x1ad55
leaq -0x90(%rbp), %rdi
callq 0xb4d0
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x1dbb0
jmp 0x1ad70
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x12390
jmp 0x1ad89
leaq -0xb0(%rbp), %rdi
callq 0x1dc20
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x1dc40
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x124b0
movb %al, -0x1d1(%rbp)
jmp 0x1adca
movb -0x1d1(%rbp), %al
testb $0x1, %al
jne 0x1add9
jmp 0x1aec1
movq -0xb8(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x12510
jmp 0x1adee
movq -0x10(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x124f0
movq %rax, -0x1e0(%rbp)
jmp 0x1ae07
movq -0x1e0(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x1dc60
jmp 0x1ae27
jmp 0x1ae29
movq -0xb8(%rbp), %rdi
xorl %esi, %esi
callq 0x1dcd0
movq %rdx, -0x1f0(%rbp)
movq %rax, -0x1e8(%rbp)
jmp 0x1ae47
movq -0x1f0(%rbp), %rax
movq -0x1e8(%rbp), %rcx
movq %rcx, -0xf0(%rbp)
movq %rax, -0xe8(%rbp)
jmp 0x1adaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x1b501
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x1b4da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xb4d0
jmp 0x1b4da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x1df40
jmp 0x1b4da
movq -0x10(%rbp), %rsi
xorl %edi, %edi
callq 0x15570
movl %eax, -0x1f4(%rbp)
jmp 0x1aed4
movl -0x1f4(%rbp), %eax
movl %eax, -0xf4(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x1dd10
movb %al, -0x1f5(%rbp)
jmp 0x1aef1
movb -0x1f5(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1af02
jmp 0x1b4bc
testb $0x1, 0x23438(%rip)     # 0x3e341
je 0x1af3e
movq 0x230b6(%rip), %rdi     # 0x3dfc8
leaq 0xfaaf(%rip), %rsi      # 0x2a9c8
callq 0x4310
movq %rax, -0x200(%rbp)
jmp 0x1af27
movq -0x200(%rbp), %rdi
movq 0x23063(%rip), %rsi     # 0x3df98
callq 0x4370
jmp 0x1af3c
jmp 0x1af3e
leaq -0x70(%rbp), %rdi
callq 0x1dd30
movq %rax, -0x208(%rbp)
jmp 0x1af50
movq -0x208(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x100(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x12b00
jmp 0x1af73
testb $0x1, 0x233c7(%rip)     # 0x3e341
je 0x1afcb
movq 0x23045(%rip), %rdi     # 0x3dfc8
leaq 0xf8ff(%rip), %rsi      # 0x2a889
callq 0x4310
movq %rax, -0x210(%rbp)
jmp 0x1af98
movq -0x210(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x40b0
movq %rax, -0x218(%rbp)
jmp 0x1afb4
movq -0x218(%rbp), %rdi
movq 0x22fd6(%rip), %rsi     # 0x3df98
callq 0x4370
jmp 0x1afc9
jmp 0x1afcb
leaq -0x70(%rbp), %rdi
callq 0x1dd50
jmp 0x1afd6
movq -0x100(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x120(%rbp), %rdi
callq 0x12390
jmp 0x1afef
leaq -0x120(%rbp), %rdi
callq 0x1dc20
movq %rax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x1dc40
movq %rax, -0x130(%rbp)
movq -0x128(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x124b0
movb %al, -0x219(%rbp)
jmp 0x1b030
movb -0x219(%rbp), %al
testb $0x1, %al
jne 0x1b03f
jmp 0x1b4b7
testb $0x1, 0x232fb(%rip)     # 0x3e341
je 0x1b07b
movq 0x22f79(%rip), %rdi     # 0x3dfc8
leaq 0xf83f(%rip), %rsi      # 0x2a895
callq 0x4310
movq %rax, -0x228(%rbp)
jmp 0x1b064
movq -0x228(%rbp), %rdi
movq 0x22f26(%rip), %rsi     # 0x3df98
callq 0x4370
jmp 0x1b079
jmp 0x1b07b
movq -0x128(%rbp), %rsi
leaq -0x150(%rbp), %rdi
callq 0x12510
jmp 0x1b090
movq -0x10(%rbp), %rsi
leaq -0x150(%rbp), %rdi
callq 0x124f0
movq %rax, -0x230(%rbp)
jmp 0x1b0a9
movq -0x230(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x128(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0x12510
jmp 0x1b0cc
leaq -0xf4(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x13f50
movq %rax, -0x238(%rbp)
jmp 0x1b0e8
movq -0x238(%rbp), %rax
cvtsi2ssl (%rax), %xmm0
movss %xmm0, -0x154(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x1de00
movq -0x248(%rbp), %rdi
movq %rax, -0x180(%rbp)
callq 0x1de30
movq %rax, -0x188(%rbp)
movq -0x180(%rbp), %rdi
movq -0x188(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x1ddb0
movq %rax, -0x240(%rbp)
jmp 0x1b148
movq -0x240(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1de30
movq %rax, -0x190(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x133e0
testb $0x1, %al
jne 0x1b182
jmp 0x1b476
testb $0x1, 0x231b8(%rip)     # 0x3e341
je 0x1b1be
movq 0x22e36(%rip), %rdi     # 0x3dfc8
leaq 0xf71c(%rip), %rsi      # 0x2a8b5
callq 0x4310
movq %rax, -0x250(%rbp)
jmp 0x1b1a7
movq -0x250(%rbp), %rdi
movq 0x22de3(%rip), %rsi     # 0x3df98
callq 0x4370
jmp 0x1b1bc
jmp 0x1b1be
movq -0x1c0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x1da20
movq %rax, -0x258(%rbp)
jmp 0x1b1da
movq -0x258(%rbp), %rax
movss (%rax), %xmm0
addss -0x154(%rbp), %xmm0
movss %xmm0, -0x194(%rbp)
testb $0x1, 0x23145(%rip)     # 0x3e341
je 0x1b2e3
movq 0x22dbf(%rip), %rdi     # 0x3dfc8
leaq 0xf6c1(%rip), %rsi      # 0x2a8d1
callq 0x4310
movq %rax, -0x260(%rbp)
jmp 0x1b21e
movq -0x260(%rbp), %rdi
movss -0x194(%rbp), %xmm0
callq 0x4280
movq %rax, -0x268(%rbp)
jmp 0x1b23b
movq -0x268(%rbp), %rdi
leaq 0xf694(%rip), %rsi      # 0x2a8dd
callq 0x4310
movq %rax, -0x270(%rbp)
jmp 0x1b257
movq -0x1c0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x1da20
movq %rax, -0x278(%rbp)
jmp 0x1b273
movq -0x270(%rbp), %rdi
movq -0x278(%rbp), %rax
movss (%rax), %xmm0
callq 0x4280
movq %rax, -0x280(%rbp)
jmp 0x1b293
movq -0x280(%rbp), %rdi
leaq 0xf647(%rip), %rsi      # 0x2a8e8
callq 0x4310
movq %rax, -0x288(%rbp)
jmp 0x1b2af
movq -0x288(%rbp), %rdi
movss -0x154(%rbp), %xmm0
callq 0x4280
movq %rax, -0x290(%rbp)
jmp 0x1b2cc
movq -0x290(%rbp), %rdi
movq 0x22cbe(%rip), %rsi     # 0x3df98
callq 0x4370
jmp 0x1b2e1
jmp 0x1b2e3
movq -0x1c0(%rbp), %rdi
movss -0x194(%rbp), %xmm0
movss %xmm0, -0x29c(%rbp)
leaq -0x138(%rbp), %rsi
callq 0x1da20
movq %rax, -0x298(%rbp)
jmp 0x1b30f
movss -0x29c(%rbp), %xmm1
movq -0x298(%rbp), %rax
movss (%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1b474
testb $0x1, 0x2300f(%rip)     # 0x3e341
je 0x1b3c4
movss -0x194(%rbp), %xmm0
movq 0x22c81(%rip), %rdi     # 0x3dfc8
callq 0x4280
movq %rax, -0x2a8(%rbp)
jmp 0x1b355
movq -0x2a8(%rbp), %rdi
leaq 0xf58b(%rip), %rsi      # 0x2a8ee
callq 0x4310
movq %rax, -0x2b0(%rbp)
jmp 0x1b371
movq -0x1c0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x1da20
movq %rax, -0x2b8(%rbp)
jmp 0x1b38d
movq -0x2b0(%rbp), %rdi
movq -0x2b8(%rbp), %rax
movss (%rax), %xmm0
callq 0x4280
movq %rax, -0x2c0(%rbp)
jmp 0x1b3ad
movq -0x2c0(%rbp), %rdi
movq 0x22bdd(%rip), %rsi     # 0x3df98
callq 0x4370
jmp 0x1b3c2
jmp 0x1b3c4
movq -0x1c0(%rbp), %rdi
movss -0x194(%rbp), %xmm0
movss %xmm0, -0x2cc(%rbp)
leaq -0x138(%rbp), %rsi
callq 0x1da20
movq %rax, -0x2c8(%rbp)
jmp 0x1b3f0
movq -0x2c8(%rbp), %rax
movss -0x2cc(%rbp), %xmm0
movss %xmm0, (%rax)
movq -0x138(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xb230
movq %rax, -0x2d8(%rbp)
jmp 0x1b41c
movq -0x2d8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x1dc60
jmp 0x1b43c
movq -0x100(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x1de60
movq %rax, -0x2e0(%rbp)
jmp 0x1b463
movq -0x2e0(%rbp), %rax
movq -0x2e8(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x1b476
jmp 0x1b478
movq -0x128(%rbp), %rdi
xorl %esi, %esi
callq 0x1dcd0
movq %rdx, -0x2f8(%rbp)
movq %rax, -0x2f0(%rbp)
jmp 0x1b496
movq -0x2f8(%rbp), %rax
movq -0x2f0(%rbp), %rcx
movq %rcx, -0x1b0(%rbp)
movq %rax, -0x1a8(%rbp)
jmp 0x1b015
jmp 0x1aee0
movb $0x1, -0x21(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x1df40
leaq -0x50(%rbp), %rdi
callq 0xb4d0
testb $0x1, -0x21(%rbp)
jne 0x1b4f1
jmp 0x1b4e5
leaq -0x50(%rbp), %rdi
callq 0xb4d0
jmp 0x1b501
movq -0x1c0(%rbp), %rdi
callq 0xb400
movq -0x1c8(%rbp), %rax
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
movq -0x1c0(%rbp), %rdi
callq 0xb400
movq -0x30(%rbp), %rdi
callq 0x4520
nopw %cs:(%rax,%rax)