// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, 0x78(%rsp)
movq %rdx, %r15
movq %rdi, %rbx
movq %rsi, 0x38(%rsp)
callq 0x9766
movq %rbx, %rdi
movq %r15, %rsi
callq 0xaf02
andl $0x0, (%rax)
xorps %xmm0, %xmm0
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
leaq 0x30(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x58(%rsp), %rdi
callq 0xaf52
leaq 0x10(%rsp), %rdi
callq 0x7e16
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0xafa0
movq (%r15), %r14
shlq $0x5, %r14
movq 0x38(%rsp), %rax
addq 0x18(%rax), %r14
leaq 0x58(%rsp), %r15
leaq 0x10(%rsp), %r12
movq %r14, %r13
movq (%r13), %r13
cmpq %r14, %r13
je 0x9899
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xafba
jmp 0x987a
movq 0xd728(%rip), %r12      # 0x16fc8
leaq 0x30(%rsp), %rbp
movq 0x58(%rsp), %rax
cmpq 0x60(%rsp), %rax
je 0x9afc
cmpb $0x1, 0xd9d5(%rip)      # 0x17291
jne 0x98da
movq %r12, %rdi
leaq 0x61c1(%rip), %rsi      # 0xfa89
callq 0x3270
movq %rax, %rdi
callq 0x3140
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x802a
cmpb $0x1, 0xd999(%rip)      # 0x17291
jne 0x991e
movq %r12, %rdi
leaq 0x6046(%rip), %rsi      # 0xf94a
callq 0x3270
movq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3140
leaq 0x58(%rsp), %rdi
callq 0xafd4
movq 0x10(%rsp), %r13
shlq $0x5, %r13
movq 0x38(%rsp), %rax
addq 0x18(%rax), %r13
movq %r13, %r15
movq (%r15), %r15
cmpq %r13, %r15
je 0x98a5
cmpb $0x1, 0xd941(%rip)      # 0x17291
jne 0x9969
movq %r12, %rdi
leaq 0x5ffa(%rip), %rsi      # 0xf956
callq 0x3270
movq %rax, %rdi
callq 0x3140
movq 0x10(%r15), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%r15), %rax
cvtsi2ssl (%rax), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rbp, %rdx
callq 0xbba0
cmpq 0x48(%rsp), %rax
jne 0x993d
cmpb $0x1, 0xd8f1(%rip)      # 0x17291
jne 0x99b9
movq %r12, %rdi
leaq 0x5fca(%rip), %rsi      # 0xf976
callq 0x3270
movq %rax, %rdi
callq 0x3140
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xaf02
movss (%rax), %xmm0
addss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
cmpb $0x1, 0xd8b4(%rip)      # 0x17291
jne 0x9a4c
movq %r12, %rdi
leaq 0x5fa9(%rip), %rsi      # 0xf992
callq 0x3270
movq %rax, %rdi
movss 0x8(%rsp), %xmm0
callq 0x3200
movq %rax, %rdi
leaq 0x5f98(%rip), %rsi      # 0xf99e
callq 0x3270
movq %rax, %r14
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xaf02
movss (%rax), %xmm0
movq %r14, %rdi
callq 0x3200
movq %rax, %rdi
leaq 0x5f78(%rip), %rsi      # 0xf9a9
callq 0x3270
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
callq 0x3200
movq %rax, %rdi
callq 0x3140
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xaf02
movss (%rax), %xmm0
ucomiss 0x8(%rsp), %xmm0
jbe 0x993d
cmpb $0x1, 0xd824(%rip)      # 0x17291
jne 0x9aae
movq %r12, %rdi
movss 0x8(%rsp), %xmm0
callq 0x3200
movq %rax, %rdi
leaq 0x5f28(%rip), %rsi      # 0xf9af
callq 0x3270
movq %rax, %r14
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xaf02
movss (%rax), %xmm0
movq %r14, %rdi
callq 0x3200
movq %rax, %rdi
callq 0x3140
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xaf02
movss 0x8(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0x30(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xafba
movq 0x10(%rsp), %r14
movq 0x78(%rsp), %rdi
movq %rbp, %rsi
callq 0xaff0
movq %r14, (%rax)
jmp 0x993d
leaq 0x58(%rsp), %rdi
callq 0x7e16
leaq 0x40(%rsp), %rdi
callq 0x7e16
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9b44
movq %rax, %r14
leaq 0x10(%rsp), %rdi
jmp 0x9b4c
movq %rax, %r14
jmp 0x9b5b
jmp 0x9b44
jmp 0x9b44
jmp 0x9b44
jmp 0x9b44
jmp 0x9b44
jmp 0x9b44
jmp 0x9b44
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0x7e16
leaq 0x40(%rsp), %rdi
callq 0x7e16
movq %rbx, %rdi
callq 0x70ae
movq %r14, %rdi
callq 0x3420