// File: /workspace/github_cpp_makefile_star2_O2/flastest[P]HeterogeneousParallelDijkstra/BBO_graph_creator.cc
// Function: graph_from_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
graph_t graph_from_file(std::string name, bool truncate_early)
{

	int counter = 1000;

	std::ifstream infile(name);

	int biggest_player_id = 0;

	std::vector<Edge> edge_vec;

	std::vector<int> weight_vec;

	std::string input;

	while (std::getline(infile,input))// >> ", 0," >>team_a>>", 0,">>team_b>>", 0")
	{
		if(truncate_early && counter <= 0)
		{
			break;
		}	

		counter--;

		if (input.substr(0,1) != "#" && input.substr(0,1) != "R")
		{
			if (DEBUG_LOGS) std::cout<<"checking line "<<input<<std::endl;
			// let's say we have 0, 0, 0/1, 0, 2/3, 0
			std::string team_a = remove_a_comma (remove_a_comma (input));
			//now we have 0/1, 0, 2/3, 0

			//let's obtain team_b
			std::string team_b = remove_a_comma (remove_a_comma (team_a));
			//now team_b is 2/3, 0
			team_b = team_b.substr(0,team_b.find(","));

			//now fix team_a which is 0/1, 0, 2/3, 0
			team_a = team_a.substr(0,team_a.find(","));

			if (DEBUG_LOGS) std::cout<<"team a is "<<team_a<<std::endl;
			if (DEBUG_LOGS) std::cout<<"team b is "<<team_b<<std::endl;


			//for each teammmate in team_a, we need to add an edge from that teammate to every member in team_b

			auto team_a_vec = get_teammates(team_a);
			auto team_b_vec = get_teammates(team_b);

			for(int teammate : team_a_vec)
			{
				for(int opponent : team_b_vec)
				{
					edge_vec.push_back(Edge(teammate,opponent));
					weight_vec.push_back(1);

				}
				if (teammate > biggest_player_id) 
				{
					biggest_player_id = teammate;
				}
			}

			for(int opponent : team_b_vec)
			{
				//infclude the following for bidirectional graph
				/*
				for(int teammate : team_a_vec)
				{
					edge_vec.push_back(Edge(opponent,teammate));
					weight_vec.push_back(1);

				}
				*/
				
				//to keep track of how many nodes we have
				if (opponent > biggest_player_id) 
				{
					biggest_player_id = opponent;
				}
			}
		}
	}

	//evidence that IDK how to use arrays
	Edge edge_array[edge_vec.size() ]; 

	for (uint32_t i = 0; i < edge_vec.size(); i++)
	{
		edge_array[i] = edge_vec[i];
	}

	int weights[weight_vec.size()]; 

	for (uint32_t i = 0; i < weight_vec.size(); i++)
	{
		weights[i] = 1;
	}	


	int num_arcs = sizeof(edge_array) / sizeof(Edge);

	int num_nodes = biggest_player_id;

	graph_t g(edge_array, edge_array + num_arcs, weights, num_nodes);

	return g;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3b8, %rsp            # imm = 0x3B8
movl %edx, -0x30(%rbp)
movq %rdi, -0x88(%rbp)
leaq -0x3e0(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x3390
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x80(%rbp), %rcx
andq $0x0, 0x10(%rcx)
leaq -0xa8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movaps %xmm0, (%rcx)
movb $0x0, (%rax)
movl $0x3e8, -0x2c(%rbp)     # imm = 0x3E8
xorl %r14d, %r14d
leaq -0xf8(%rbp), %rbx
leaq -0x158(%rbp), %r12
leaq -0x38(%rbp), %r15
leaq -0x3e0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x3080
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
cmpl $0x0, -0x2c(%rbp)
setle %cl
testb $0x5, 0x20(%rax,%rdx)
jne 0xcf26
andb -0x30(%rbp), %cl
jne 0xcf26
movq %rbx, %rdi
leaq -0xb8(%rbp), %rsi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq 0x32b0
movq %rbx, %rdi
leaq 0x331a(%rip), %rsi      # 0xff33
callq 0xd51a
testb %al, %al
je 0xcec9
movq %r12, %rdi
leaq -0xb8(%rbp), %rsi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq 0x32b0
movq %r12, %rdi
leaq 0x32f1(%rip), %rsi      # 0xff35
callq 0xd51a
movl %eax, %r13d
movq %r12, %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3110
testb %r13b, %r13b
je 0xced1
cmpb $0x1, 0xa87f(%rip)      # 0x174eb
jne 0xcc98
movq 0xa353(%rip), %rdi      # 0x16fc8
leaq 0x32bb(%rip), %rsi      # 0xff37
callq 0x3270
movq %rax, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x3250
movq %rax, %rdi
callq 0x3140
leaq -0x138(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x3310
leaq -0x1d8(%rbp), %r13
movq %r13, %rdi
leaq -0x138(%rbp), %rsi
callq 0xcb17
movq %rbx, %rdi
movq %r13, %rsi
callq 0xcb17
movq %r13, %rdi
callq 0x3110
leaq -0x138(%rbp), %rdi
callq 0x3110
leaq -0x118(%rbp), %rdi
movq %rbx, %rsi
callq 0x3310
leaq -0x1b8(%rbp), %r13
movq %r13, %rdi
leaq -0x118(%rbp), %rsi
callq 0xcb17
movq %r12, %rdi
movq %r13, %rsi
callq 0xcb17
movq %r13, %rdi
callq 0x3110
leaq -0x118(%rbp), %rdi
callq 0x3110
movq %r12, %rdi
leaq 0x3203(%rip), %rsi      # 0xff31
xorl %edx, %edx
callq 0x3470
leaq -0xd8(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x32b0
movq %r12, %rdi
movq %r13, %rsi
callq 0x32e0
movq %r13, %rdi
callq 0x3110
movq %rbx, %rdi
leaq 0x31c8(%rip), %rsi      # 0xff31
xorl %edx, %edx
callq 0x3470
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x32b0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x32e0
movq %r13, %rdi
callq 0x3110
movb 0xa752(%rip), %al       # 0x174eb
cmpb $0x1, %al
jne 0xcdc9
movq 0xa224(%rip), %rdi      # 0x16fc8
leaq 0x319b(%rip), %rsi      # 0xff46
callq 0x3270
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, %rdi
callq 0x3140
movb 0xa722(%rip), %al       # 0x174eb
testb $0x1, %al
je 0xcdf3
movq 0xa1f4(%rip), %rdi      # 0x16fc8
leaq 0x3176(%rip), %rsi      # 0xff51
callq 0x3270
movq %rax, %rdi
movq %r12, %rsi
callq 0x3250
movq %rax, %rdi
callq 0x3140
leaq -0x198(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3310
leaq -0xd8(%rbp), %rdi
movq %r13, %rsi
callq 0xc8cc
movq %r13, %rdi
callq 0x3110
leaq -0x178(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3310
leaq -0x68(%rbp), %rdi
movq %r13, %rsi
callq 0xc8cc
decl -0x2c(%rbp)
movq %r13, %rdi
callq 0x3110
movq -0xd8(%rbp), %r12
movq -0xd0(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq -0x90(%rbp), %r12
je 0xced9
movq %r14, -0x98(%rbp)
movl (%r12), %r14d
movq -0x68(%rbp), %r13
movq -0x60(%rbp), %rbx
cmpq %rbx, %r13
je 0xceab
movl (%r13), %eax
movl %r14d, -0x38(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xd72c
movl $0x1, -0x38(%rbp)
leaq -0x80(%rbp), %rdi
movq %r15, %rsi
callq 0xd8aa
addq $0x4, %r13
jmp 0xce76
movq -0x98(%rbp), %rax
cmpl %eax, %r14d
cmovgl %r14d, %eax
movq %rax, %r14
addq $0x4, %r12
leaq -0xf8(%rbp), %rbx
jmp 0xce5a
movq %rbx, %rdi
callq 0x3110
decl -0x2c(%rbp)
jmp 0xcbc6
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq -0x158(%rbp), %r12
cmpq %rcx, %rax
je 0xcefc
movl (%rax), %edx
cmpl %r14d, %edx
cmovgl %edx, %r14d
addq $0x4, %rax
jmp 0xcee8
leaq -0x68(%rbp), %rdi
callq 0x74ca
leaq -0xd8(%rbp), %rdi
callq 0x74ca
movq %r12, %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3110
jmp 0xcbc6
movq %r14, %r12
movq %rsp, %r14
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rbx
movq %rsp, %r15
movq %rbx, %rcx
subq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
subq %rcx, %r15
movq %r15, %rsp
subq %rax, %rbx
je 0xcf66
leaq -0x8(%rbx), %rdx
andq $-0x8, %rdx
addq $0x8, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x3170
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0xcf8a
movq (%rax,%rdx,8), %rsi
movq %rsi, (%r15,%rdx,8)
incl %edx
jmp 0xcf77
movq -0x78(%rbp), %rdx
subq -0x80(%rbp), %rdx
movq %rdx, %rax
sarq $0x2, %rax
movq %rsp, %rcx
addq $0xf, %rdx
andq $-0x10, %rdx
subq %rdx, %rcx
movq %rcx, %rsp
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rax
jbe 0xcfbe
movl $0x1, (%rcx,%rdx,4)
incl %edx
jmp 0xcfac
shlq $0x1d, %rbx
sarq $0x1d, %rbx
addq %r15, %rbx
movl %r12d, %r8d
subq $0x8, %rsp
movq -0x88(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
xorl %r9d, %r9d
leaq -0xf8(%rbp), %rax
pushq %rax
callq 0x6b18
popq %rax
popq %rcx
movq %r14, %rsp
leaq -0xb8(%rbp), %rdi
callq 0x3110
leaq -0x80(%rbp), %rdi
callq 0x74ca
leaq -0x50(%rbp), %rdi
callq 0xd6ec
leaq -0x3e0(%rbp), %rdi
callq 0x30a0
movq %r12, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x3110
jmp 0xd0de
movq %rax, %rbx
jmp 0xd0de
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x3110
jmp 0xd0ea
jmp 0xd0ac
jmp 0xd0ac
jmp 0xd0ac
movq %rax, %rbx
leaq -0x1b8(%rbp), %rdi
callq 0x3110
jmp 0xd07b
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
jmp 0xd0f1
movq %rax, %rbx
jmp 0xd0f6
movq %rax, %rbx
leaq -0x1d8(%rbp), %rdi
callq 0x3110
jmp 0xd09d
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
jmp 0xd0fd
jmp 0xd0cb
jmp 0xd0cb
jmp 0xd0cb
movq %rax, %rbx
jmp 0xd0ea
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
callq 0x3110
jmp 0xd0c9
jmp 0xd0c6
jmp 0xd0cb
movq %rax, %rbx
jmp 0xd0f6
movq %rax, %rbx
jmp 0xd102
jmp 0xd0d2
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x74ca
leaq -0xd8(%rbp), %rdi
callq 0x74ca
leaq -0x158(%rbp), %rdi
callq 0x3110
leaq -0xf8(%rbp), %rdi
callq 0x3110
leaq -0xb8(%rbp), %rdi
callq 0x3110
leaq -0x80(%rbp), %rdi
callq 0x74ca
leaq -0x50(%rbp), %rdi
callq 0xd6ec
leaq -0x3e0(%rbp), %rdi
callq 0x30a0
movq %rbx, %rdi
callq 0x3420