// File: /workspace/github_cpp_makefile_star2_O3/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, %r12d
movl %esi, 0x4(%rsp)
movl %edi, 0x14(%rsp)
testl %edi, %edi
je 0x909a
movq 0xcfdd(%rip), %rbx      # 0x15fd0
leaq 0x731c(%rip), %rsi      # 0x10316
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 0x7327(%rip), %rsi      # 0x1035c
movl $0xd, %edx
movq %rbx, %rdi
callq 0x3300
movq %rbx, %rdi
movl 0x4(%rsp), %esi
callq 0x3480
movq %rax, %rbx
leaq 0x7312(%rip), %rsi      # 0x1036a
movl $0xc, %edx
movq %rax, %rdi
callq 0x3300
movq %rbx, %rdi
movl %r12d, %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 0xa07c
leaq 0xd8(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0xe81f
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x90f2
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xf8(%rsp), %rdx
subq 0xf0(%rsp), %rdx
shrq $0x5, %rdx
movq $0x1, 0x20(%rsp)
leaq 0x118(%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 0x70(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x9ade
leaq 0x140(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x9b6c
movq 0x20(%rsp), %rdx
leaq 0x58(%rsp), %rdi
leaq 0x140(%rsp), %rbx
leaq 0x70(%rsp), %rcx
movq %rbx, %rsi
callq 0x4141
leaq 0x158(%rsp), %r14
movq 0x18(%r14), %rdi
movl $0x1, %esi
callq 0x32b0
movq %r14, %rdi
callq 0x9d84
movq -0x18(%r14), %rdi
cmpq %rbx, %rdi
je 0x91b9
movq (%rdi), %r14
movl $0x28, %esi
callq 0x32b0
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x91a4
leaq 0x90(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
testl %r12d, %r12d
jle 0x941f
movq 0x18(%rsp), %r15
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl $0x7fffffff, (%rsp)     # imm = 0x7FFFFFFF
movb $0x1, %al
movq %rax, 0x8(%rsp)
leaq 0x28(%rsp), %r13
leaq 0x88(%rsp), %rbp
xorl %r14d, %r14d
movl %r12d, 0x10(%rsp)
cmpb $0x0, 0x14(%rsp)
je 0x928b
movl $0x5, %edx
movq 0xcdac(%rip), %rdi      # 0x15fd0
leaq 0x714c(%rip), %rsi      # 0x10377
callq 0x3300
movq 0xcd99(%rip), %rdi      # 0x15fd0
movl %r14d, %esi
callq 0x3480
movq %rax, %rbx
movl $0x4, %edx
movq %rax, %rdi
leaq 0x712c(%rip), %rsi      # 0x1037d
callq 0x3300
movq %rbx, %rdi
movl %r12d, %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 %r13, %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
leaq 0x110(%rsp), %rcx
movl 0x4(%rsp), %r8d
callq 0xc5b5
movq %rbp, %rdi
callq 0x9ffe
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x931b
movl 0x30(%rsp), %ecx
movl %ecx, 0x90(%rsp)
movq %rax, 0x98(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, 0xa0(%rsp)
leaq 0x90(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x50(%rsp), %rax
movq %rax, 0xb0(%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 %r13, %rdi
callq 0x9fea
callq 0x3060
subq %rbx, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rbx
cmpl $0x0, 0x18(%rsp)
jle 0x9393
xorl %r12d, %r12d
movq %r12, 0x28(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x99a8
movq 0x58(%rsp), %rcx
xorps %xmm0, %xmm0
cvtsi2ssl (%rcx,%r12,4), %xmm0
movss (%rax), %xmm1
ucomiss %xmm0, %xmm1
jne 0x936e
jnp 0x938b
movq %r12, 0x28(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x99a8
movss (%rax), %xmm0
ucomiss 0x6da7(%rip), %xmm0     # 0x10130
jb 0x93d7
incq %r12
cmpq %r12, %r15
jne 0x9345
movq %rbx, %rax
shrq $0x3f, %rax
sarq $0x7, %rbx
addq %rax, %rbx
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl (%rsp), %xmm1
minss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, (%rsp)
incl %r14d
movl 0x10(%rsp), %r12d
cmpl %r12d, %r14d
setl %al
movq %rax, 0x8(%rsp)
jne 0x9211
jmp 0x942f
movq 0xcbf2(%rip), %rbx      # 0x15fd0
leaq 0x6f9d(%rip), %rsi      # 0x10382
movl $0x3b, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq 0xcbc0(%rip), %rdi      # 0x15fd0
callq 0x3040
movq %rax, %rdi
callq 0x31d0
jmp 0x942f
movl $0x7fffffff, (%rsp)     # imm = 0x7FFFFFFF
movq $0x0, 0x8(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x9fea
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x9453
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0xf0(%rsp), %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
leaq 0xd8(%rsp), %r14
je 0x947d
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0x110(%rsp), %rdi
callq 0xa02c
movq 0x108(%rsp), %rdi
movl $0x1, %esi
callq 0x32b0
movq %rbx, %rdi
callq 0x9d84
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x94c6
movq (%rdi), %rbx
movl $0x28, %esi
callq 0x32b0
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x94b1
testb $0x1, 0x8(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl (%rsp), %eax
cmovnel %ecx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x9c06
jmp 0x9555
movq %rax, %rbx
jmp 0x9555
movq %rax, %rbx
jmp 0x956f
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x9589
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x9589
jmp 0x952e
jmp 0x952e
jmp 0x952e
jmp 0x952e
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x9fea
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x9555
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x956f
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0x110(%rsp), %rdi
callq 0xa02c
leaq 0xd8(%rsp), %rdi
callq 0x9c06
movq %rbx, %rdi
callq 0x34a0