// File: /workspace/github_cpp_makefile_star2_O3/rtackx[P]ComSim/graph.cpp
// Function: Graph::load_graph(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Graph::load_graph(string bip_filename)
{
	char delim = ' ';

	int fd = open(bip_filename.c_str(), O_RDONLY);
	if(fd == -1)
	{
		perror("Can't open file.");
		exit(EXIT_FAILURE);
	}

	Node* node, *node_tmp;

	char* w = (char*) malloc(sizeof(char) * SIZE_BUFFER);
	string word;
	char c;
	float weight;
	int i, size_w, count;
	bool new_w, new_line;
	new_line = new_w;

	unsigned int index = 0;
	int index1, index2;
	unordered_map<string, unsigned int> map_word;
	unordered_map<unsigned int, Node*> map_node;
	unordered_map<unsigned int, set<pair<unsigned int, float>, comp_pair>> map_neighbor;

	index2 = -1;
	size_w = 0;
	count = 0;
	weight = 1.0;
	node_tmp = NULL;

	do
	{
		i = read(fd, &c, 1);

		if(size_w == SIZE_BUFFER)
			w = (char*) realloc(w, sizeof(char) * SIZE_BUFFER + size_w);

		if(c == '\r')
			continue;

		if(c == delim || c == '\n')
		{
			if(c == '\n')
				new_line = true;

			w[size_w] = '\0';
			new_w = true;
			word = w;
			count++;
		}
		else
		{
			w[size_w] = c;
			size_w++;
		}

		if(new_w && size_w > 0)
		{
			new_w = false;
			if(count == 3)
			{
				weight = stof(word);
			}
			else
			{
				if(map_word.find(word) == map_word.end())
				{
					node = new Node();
					node->id = word;
					map_node[index] = node;
					map_word[word] = index;

					index1 = index;
					index++;
				}
				else
					index1 = map_word[word];
			}

			if(new_line)
			{
				map_neighbor[index1].insert(make_pair(index2, weight));
				map_neighbor[index2].insert(make_pair(index1, weight));

				new_line = false;
				count = 0;
				weight = 1.0;
				index2 = -1;
			}
			else
			{
				if(index2 == -1)
					index2 = index1;
			}
			
			free(w);
			w = (char*) malloc(sizeof(char) * SIZE_BUFFER);
			size_w = 0;
		}

	} while(i != 0);
	free(w);

	create_graph(map_node, map_neighbor);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x58(%rsp)
movq (%rsi), %rdi
xorl %r12d, %r12d
xorl %esi, %esi
xorl %eax, %eax
callq 0x21a0
cmpl $-0x1, %eax
je 0x41e5
movl %eax, %ebp
movl $0x400, %edi            # imm = 0x400
callq 0x22f0
movq %rax, %r15
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x14(%rsp), %rax
movl $0x0, (%rax)
leaq 0x90(%rsp), %rax
movq %rax, -0x30(%rax)
movl $0x1, %ecx
movq %rcx, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, %edx       # imm = 0x3F800000
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0x100(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0xc8(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
movss 0x69ce(%rip), %xmm0     # 0xa8c0
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movq %rax, 0x28(%rsp)
movss %xmm0, 0xc(%rsp)
movl $0x0, 0x24(%rsp)
xorl %r13d, %r13d
movl $0x1, %edx
movl %ebp, %edi
leaq 0xb(%rsp), %rsi
callq 0x2310
movq %rax, %r14
cmpl $0x400, %r13d           # imm = 0x400
jne 0x3f3d
movl $0x800, %esi            # imm = 0x800
movq %r15, %rdi
callq 0x23b0
movq %rax, %r15
movzbl 0xb(%rsp), %eax
cmpl $0x20, %eax
je 0x3f5b
cmpl $0xd, %eax
je 0x4158
cmpl $0xa, %eax
jne 0x3f8c
movb $0x1, %al
movl %eax, 0x24(%rsp)
movslq %r13d, %rax
movb $0x0, (%r15,%rax)
movq 0x40(%rsp), %rbx
movq %r15, %rdi
callq 0x20f0
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0x2360
incl %r12d
movb $0x1, %bl
jmp 0x3f96
movslq %r13d, %rcx
movb %al, (%r15,%rcx)
incl %r13d
testl %r13d, %r13d
setg %al
andb %bl, %al
cmpb $0x1, %al
jne 0x4158
cmpl $0x3, %r12d
jne 0x3ff7
movq 0x38(%rsp), %r13
callq 0x2060
movq %rax, %rbx
movl (%rax), %eax
movl %eax, 0x30(%rsp)
movl $0x0, (%rbx)
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x2300
movss %xmm0, 0xc(%rsp)
cmpq %r13, 0x18(%rsp)
je 0x41cd
movl (%rbx), %eax
testl %eax, %eax
je 0x4023
cmpl $0x22, %eax
jne 0x408a
jmp 0x41d9
leaq 0x60(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x453c
testq %rax, %rax
je 0x402b
leaq 0x60(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x48ee
movl (%rax), %eax
movq %rax, 0x28(%rsp)
jmp 0x408a
movl 0x30(%rsp), %eax
movl %eax, (%rbx)
jmp 0x408a
movl $0x68, %edi
callq 0x2250
movq %rax, %rbx
movq %rax, %rdi
callq 0x265c
movq %rbx, %rdi
addq $0x8, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2110
leaq 0xd0(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x4654
movq %rbx, (%rax)
movl 0x14(%rsp), %ebx
leaq 0x60(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x48ee
movl %ebx, (%rax)
movl 0x14(%rsp), %eax
movq %rax, 0x28(%rsp)
incl %eax
movl %eax, 0x14(%rsp)
testb $0x1, 0x24(%rsp)
je 0x4126
movq 0x28(%rsp), %rax
movl %eax, 0x34(%rsp)
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
leaq 0x34(%rsp), %r12
movq %r12, %rsi
callq 0x4c22
movl 0x10(%rsp), %r13d
movl %r13d, 0x18(%rsp)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4ee2
movl %r13d, 0x34(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4c22
movq 0x28(%rsp), %rcx
movl %ecx, 0x18(%rsp)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4ee2
xorl %r12d, %r12d
movl $0xffffffff, 0x10(%rsp) # imm = 0xFFFFFFFF
movss 0x67a2(%rip), %xmm0     # 0xa8c0
movss %xmm0, 0xc(%rsp)
jmp 0x4136
movl 0x10(%rsp), %eax
cmpl $-0x1, %eax
cmovel 0x28(%rsp), %eax
movl %eax, 0x10(%rsp)
movq %r15, %rdi
callq 0x22a0
movl $0x400, %edi            # imm = 0x400
callq 0x22f0
movq %rax, %r15
movl $0x0, 0x24(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
testl %r14d, %r14d
jne 0x3f10
movq %r15, %rdi
callq 0x22a0
leaq 0xd0(%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq 0x58(%rsp), %rdi
callq 0x4256
leaq 0x98(%rsp), %rdi
callq 0x436e
leaq 0xd0(%rsp), %rdi
callq 0x4444
leaq 0x60(%rsp), %rdi
callq 0x44a6
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x41bb
callq 0x2220
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6701(%rip), %rdi      # 0xa8d5
callq 0x2130
leaq 0x66f5(%rip), %rdi      # 0xa8d5
callq 0x2320
callq 0x2430
jmp 0x4213
movq %rax, %r14
movq %rbx, %rdi
callq 0x2220
jmp 0x4216
jmp 0x4213
jmp 0x4213
jmp 0x4213
jmp 0x4213
jmp 0x4213
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x4216
movl 0x30(%rsp), %eax
movl %eax, (%rbx)
jmp 0x4216
movq %rax, %r14
leaq 0x98(%rsp), %rdi
callq 0x436e
leaq 0xd0(%rsp), %rdi
callq 0x4444
leaq 0x60(%rsp), %rdi
callq 0x44a6
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x424e
callq 0x2220
movq %r14, %rdi
callq 0x23d0