// File: /workspace/github_cpp_makefile_star2_O1/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 0xae54
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdbd2
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 0xdc38
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xaf54
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0xdca4
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 0xafa5
leaq 0x50(%rsp), %r14
leaq 0x10(%rsp), %r15
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xdd00
movq (%r13), %r13
cmpq %r12, %r13
jne 0xaf88
movq 0x50(%rsp), %rdi
cmpq 0x58(%rsp), %rdi
je 0xb343
movq 0xd014(%rip), %r12      # 0x17fd0
leaq 0x48(%rsp), %r13
cmpb $0x1, 0xd2b1(%rip)      # 0x18279
jne 0xb006
movl $0xe, %edx
movq %r12, %rdi
leaq 0x7662(%rip), %rsi      # 0x1263b
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), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0xb02d
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0xb03c
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x9a3e
cmpb $0x1, 0xd236(%rip)      # 0x18279
jne 0xb090
movl $0xb, %edx
movq %r12, %rdi
leaq 0x74a8(%rip), %rsi      # 0x124fc
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 0xdd5c
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 0xb333
cmpb $0x1, 0xd1b5(%rip)      # 0x18279
jne 0xb102
movl $0x1f, %edx
movq %r12, %rdi
leaq 0x7433(%rip), %rsi      # 0x12508
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 0xe82e
cmpq 0x38(%rsp), %rax
jne 0xb32a
cmpb $0x1, 0xd139(%rip)      # 0x18279
jne 0xb17e
movl $0x1b, %edx
movq %r12, %rdi
leaq 0x73d7(%rip), %rsi      # 0x12528
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 0xdbd2
movss (%rax), %xmm0
addss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
cmpb $0x1, 0xd0d7(%rip)      # 0x18279
jne 0xb252
movl $0xb, %edx
movq %r12, %rdi
leaq 0x738d(%rip), %rsi      # 0x12544
callq 0x32a0
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movq %r12, %rdi
callq 0x3350
movq %rax, %r14
movl $0xa, %edx
movq %rax, %rdi
leaq 0x7371(%rip), %rsi      # 0x12550
callq 0x32a0
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xdbd2
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
movq %r14, %rdi
callq 0x3350
movq %rax, %r14
movl $0x5, %edx
movq %rax, %rdi
leaq 0x7349(%rip), %rsi      # 0x1255b
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 0xdbd2
movss (%rax), %xmm0
ucomiss 0x8(%rsp), %xmm0
jbe 0xb32a
cmpb $0x1, 0xd006(%rip)      # 0x18279
jne 0xb2e1
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movq %r12, %rdi
callq 0x3350
movq %rax, %r14
movl $0x10, %edx
movq %rax, %rdi
leaq 0x72c9(%rip), %rsi      # 0x12561
callq 0x32a0
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdbd2
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 0xdbd2
movss 0x8(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0x48(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xdd00
movq 0x10(%rsp), %r14
movq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0xdd9c
movq %r14, (%rax)
movq (%rbp), %rbp
jmp 0xb0b4
movq 0x50(%rsp), %rdi
cmpq 0x58(%rsp), %rdi
jne 0xafc1
testq %rdi, %rdi
je 0xb355
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xb36c
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 0xb3aa
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xb3c4
movq 0x20(%rsp), %rsi
jmp 0xb3bc
movq %rax, %r14
jmp 0xb3db
jmp 0xb3aa
jmp 0xb3aa
jmp 0xb3aa
jmp 0xb3aa
jmp 0xb3aa
jmp 0xb3aa
jmp 0xb3aa
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xb3c4
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xb3db
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x8ca2
movq %r14, %rdi
callq 0x3400