// File: /workspace/github_cpp_makefile_star2_O1/flastest[P]HeterogeneousParallelDijkstra/parallel_workloads.cc
// Function: get_min_graph_time_for_given_amount_of_threads(bool, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
time_type get_min_graph_time_for_given_amount_of_threads(bool TEST_DEBUG, int num_threads, int num_tests, std::string graph_name)
{
	time_type min_time = 2147483647;

	if (TEST_DEBUG) 
	{
		std::cout<<"loading graph from a graph"<<std::endl;
		std::cout << "num threads: " << num_threads<< " num tests: "<<num_tests<<std::endl; 
	}
	graph_t g = cit_graph_from_file(graph_name,true);
	
	//number of nodes in g
	int num_nodes = num_vertices(g);

	//get a source node...
	vertex_descriptor s = vertex(1, g);

	predecessor_map_t pred;


	//get the results from the BGL to compare against
	std::vector<vertex_descriptor> p_BGL(num_nodes);

	std::vector<int> BGL_results = testBGL ( g,  s, p_BGL);
		
	distance_map_t parallel_results;


	for (int i = 0 ; i < num_tests; i++)
	{
		if(TEST_DEBUG) std::cout << "test " << i << " of "<< num_tests << std::endl;
		auto startTime = chrono::high_resolution_clock::now();
		parallel_results = parallel_dijkstra(g, s, pred, num_threads);
		auto endTime = chrono::high_resolution_clock::now();

		float t = chrono::duration_cast<std::chrono::microseconds>( endTime - startTime ).count();

		for (int i = 0 ; i < num_nodes; i++)
		{
			// if(TEST_DEBUG)
			// {	
			// 	std::cout<<"test number "<<i<<std::endl;
			// 	std::cout<<"comparing " <<parallel_results[i] <<" and "<<BGL_results[i]<<std::endl;
			// }
			if(parallel_results[i] != BGL_results[i])
			{
				//std::cout<<"testing parallel_results: " << parallel_results[i] <<" and " <<"BGL_results: " <<BGL_results[i]<<std::endl;
				if(parallel_results[i] != INFINITY && (BGL_results[i] !=  2147483647 || BGL_results[i] !=  -2147483647))
				{	
					std::cout<<"ERROR: parallel dijkstra produced different result than BGL"<<std::endl;
					return -1;
				}
			}
			
			//not sure if I need to check predecessors because they might be different even with functioning code
		}

		min_time = t < min_time ? t : min_time; 
	}
	//if (TEST_DEBUG)std::cout<< "results are:"<<std::endl << print_dijkstra_results(g, parallel_results) <<std::endl;
	return min_time;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rcx, %r14
movl %edx, 0x8(%rsp)
movl %esi, 0xc(%rsp)
movl %edi, 0x10(%rsp)
testl %edi, %edi
je 0x9227
movq 0xde51(%rip), %rbx      # 0x16fd0
leaq 0x7150(%rip), %rsi      # 0x102d6
movl $0x1a, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
leaq 0x715b(%rip), %rsi      # 0x1031c
movl $0xd, %edx
movq %rbx, %rdi
callq 0x3300
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x3480
movq %rax, %rbx
leaq 0x7146(%rip), %rsi      # 0x1032a
movl $0xc, %edx
movq %rax, %rdi
callq 0x3300
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x3480
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
leaq 0xc8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0xa218
leaq 0xd8(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0xeaf0
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x927f
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xf8(%rsp), %rdx
subq 0xf0(%rsp), %rdx
shrq $0x5, %rdx
movq $0x1, 0x20(%rsp)
leaq 0x150(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq %rdx, 0x18(%rsp)
movslq %edx, %rsi
leaq 0xa0(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x9c80
leaq 0x110(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x9d0a
movq 0x20(%rsp), %rdx
leaq 0x88(%rsp), %rdi
leaq 0x110(%rsp), %rbx
leaq 0xa0(%rsp), %rcx
movq %rbx, %rsi
callq 0x4146
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x9327
movl $0x1, %esi
callq 0x32b0
leaq 0x128(%rsp), %r14
movq %r14, %rdi
callq 0x9f26
movq -0x18(%r14), %rdi
cmpq %rbx, %rdi
je 0x9355
movq (%rdi), %r14
movl $0x28, %esi
callq 0x32b0
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x9340
leaq 0x60(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
cmpl $0x0, 0x8(%rsp)
jle 0x95ce
movq 0x18(%rsp), %rax
testl %eax, %eax
setg 0x3(%rsp)
movslq %eax, %r13
movl %r13d, %r12d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0x7fffffff, 0x4(%rsp)  # imm = 0x7FFFFFFF
leaq 0x28(%rsp), %rbp
xorl %r14d, %r14d
cmpb $0x0, 0x10(%rsp)
je 0x9421
movl $0x5, %edx
movq 0xdc17(%rip), %rdi      # 0x16fd0
leaq 0x6f77(%rip), %rsi      # 0x10337
callq 0x3300
movq 0xdc04(%rip), %rdi      # 0x16fd0
movl %r14d, %esi
callq 0x3480
movq %rax, %rbx
movl $0x4, %edx
movq %rax, %rdi
leaq 0x6f57(%rip), %rsi      # 0x1033d
callq 0x3300
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x3480
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
callq 0x3060
movq %rax, %rbx
movq %rbp, %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
leaq 0x148(%rsp), %rcx
movl 0xc(%rsp), %r8d
callq 0xc863
movl %r14d, 0x14(%rsp)
leaq 0x58(%rsp), %rdi
callq 0xa19a
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x94ac
movl 0x30(%rsp), %ecx
movl %ecx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, 0x70(%rsp)
leaq 0x60(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
xorl %eax, %eax
movq %rax, 0x38(%rsp)
leaq 0x30(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movq %rbp, %rdi
callq 0xa186
callq 0x3060
subq %rbx, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rbx
movb 0x3(%rsp), %r15b
cmpl $0x0, 0x18(%rsp)
jle 0x953c
xorl %r14d, %r14d
movb 0x3(%rsp), %r15b
movq %r14, 0x28(%rsp)
leaq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x9b4c
movq 0x88(%rsp), %rcx
xorps %xmm0, %xmm0
cvtsi2ssl (%rcx,%r14,4), %xmm0
movss (%rax), %xmm1
ucomiss %xmm0, %xmm1
jne 0x950e
jnp 0x952d
movq %r14, 0x28(%rsp)
leaq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x9b4c
movss (%rax), %xmm0
ucomiss 0x6bc5(%rip), %xmm0     # 0x100f0
jb 0x9569
incq %r14
cmpq %r13, %r14
setl %r15b
cmpq %r14, %r12
jne 0x94e0
movq %rbx, %rax
shrq $0x3f, %rax
sarq $0x7, %rbx
addq %rax, %rbx
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x4(%rsp), %xmm1
minss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, 0x4(%rsp)
jmp 0x95b3
movl $0x3b, %edx
movq 0xda5b(%rip), %rdi      # 0x16fd0
leaq 0x6dc6(%rip), %rsi      # 0x10342
callq 0x3300
movq 0xda48(%rip), %rcx      # 0x16fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq 0xda2a(%rip), %rdi      # 0x16fd0
callq 0x3040
movq %rax, %rdi
callq 0x31d0
testb $0x1, %r15b
jne 0x95d8
movl 0x14(%rsp), %r14d
incl %r14d
cmpl 0x8(%rsp), %r14d
jne 0x93a6
jmp 0x95e0
movl $0x7fffffff, 0x4(%rsp)  # imm = 0x7FFFFFFF
jmp 0x95e0
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
leaq 0x58(%rsp), %rdi
callq 0xa186
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x9607
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
leaq 0xd8(%rsp), %r14
je 0x962c
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0xf0(%rsp), %rbx
leaq 0x148(%rsp), %rdi
callq 0xa1c8
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x9654
movl $0x1, %esi
callq 0x32b0
movq %rbx, %rdi
callq 0x9f26
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x967e
movq (%rdi), %rbx
movl $0x28, %esi
callq 0x32b0
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x9669
movl 0x4(%rsp), %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x9da4
jmp 0x9704
movq %rax, %rbx
jmp 0x9704
movq %rax, %rbx
jmp 0x9721
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x973b
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x973b
jmp 0x96da
jmp 0x96da
jmp 0x96da
jmp 0x96da
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0xa186
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x9704
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x9721
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0x148(%rsp), %rdi
callq 0xa1c8
leaq 0xd8(%rsp), %rdi
callq 0x9da4
movq %rbx, %rdi
callq 0x34a0