// File: /workspace/github_cpp_makefile_star2_O3/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, 0x70(%rsp)
callq 0xabf8
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd966
movl $0x0, (%rax)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
leaq 0x48(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x10(%rsp), %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
leaq 0x50(%rsp), %rdi
callq 0xd9cc
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xacf8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0xda30
movq (%r15), %rax
movq 0x70(%rsp), %rcx
movq 0x18(%rcx), %rcx
shlq $0x5, %rax
leaq (%rcx,%rax), %r12
movq (%rcx,%rax), %r13
cmpq %r12, %r13
je 0xad49
leaq 0x50(%rsp), %r14
leaq 0x10(%rsp), %r15
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xda8c
movq (%r13), %r13
cmpq %r12, %r13
jne 0xad2c
movq 0x50(%rsp), %rdi
cmpq 0x58(%rsp), %rdi
je 0xb0e7
movq 0xd270(%rip), %r12      # 0x17fd0
leaq 0x48(%rsp), %r13
cmpb $0x1, 0xd50d(%rip)      # 0x18279
jne 0xadaf
movl $0xe, %edx
movq %r12, %rdi
leaq 0x78fe(%rip), %rsi      # 0x1267b
callq 0x32a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0xadd1
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0xade0
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x98d4
cmpb $0x1, 0xd492(%rip)      # 0x18279
jne 0xae34
movl $0xb, %edx
movq %r12, %rdi
leaq 0x7744(%rip), %rsi      # 0x1253c
callq 0x32a0
movq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x3190
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x50(%rsp), %rdi
callq 0xdae8
movq 0x10(%rsp), %rax
movq 0x70(%rsp), %rcx
movq 0x18(%rcx), %rcx
shlq $0x5, %rax
leaq (%rcx,%rax), %r15
movq (%rcx,%rax), %rbp
cmpq %r15, %rbp
je 0xb0d7
cmpb $0x1, 0xd411(%rip)      # 0x18279
jne 0xaea6
movl $0x1f, %edx
movq %r12, %rdi
leaq 0x76cf(%rip), %rsi      # 0x12548
callq 0x32a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x10(%rbp), %rax
movq %rax, 0x48(%rsp)
movq 0x18(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2ssl (%rax), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0xe596
cmpq 0x38(%rsp), %rax
jne 0xb0ce
cmpb $0x1, 0xd395(%rip)      # 0x18279
jne 0xaf22
movl $0x1b, %edx
movq %r12, %rdi
leaq 0x7673(%rip), %rsi      # 0x12568
callq 0x32a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xd966
movss (%rax), %xmm0
addss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
cmpb $0x1, 0xd333(%rip)      # 0x18279
jne 0xaff6
movl $0xb, %edx
movq %r12, %rdi
leaq 0x7629(%rip), %rsi      # 0x12584
callq 0x32a0
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movq %r12, %rdi
callq 0x3350
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0x760d(%rip), %rsi      # 0x12590
callq 0x32a0
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xd966
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
movq %r14, %rdi
callq 0x3350
movq %rax, %r14
movl $0x5, %edx
movq %rax, %rdi
leaq 0x75e5(%rip), %rsi      # 0x1259b
callq 0x32a0
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rsp), %xmm0
movq %r14, %rdi
callq 0x3350
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd966
movss (%rax), %xmm0
ucomiss 0x8(%rsp), %xmm0
jbe 0xb0ce
cmpb $0x1, 0xd262(%rip)      # 0x18279
jne 0xb085
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movq %r12, %rdi
callq 0x3350
movq %rax, %r14
movl $0x10, %edx
movq %rax, %rdi
leaq 0x7565(%rip), %rsi      # 0x125a1
callq 0x32a0
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd966
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
movq %r14, %rdi
callq 0x3350
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd966
movss 0x8(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0x48(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xda8c
movq 0x10(%rsp), %r14
movq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0xdb2e
movq %r14, (%rax)
movq (%rbp), %rbp
jmp 0xae58
movq 0x50(%rsp), %rdi
cmpq 0x58(%rsp), %rdi
jne 0xad65
testq %rdi, %rdi
je 0xb0f9
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xb110
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb14e
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xb168
movq 0x20(%rsp), %rsi
jmp 0xb160
movq %rax, %r14
jmp 0xb17f
jmp 0xb14e
jmp 0xb14e
jmp 0xb14e
jmp 0xb14e
jmp 0xb14e
jmp 0xb14e
jmp 0xb14e
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xb168
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xb17f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x8b50
movq %r14, %rdi
callq 0x3400