// File: /workspace/github_cpp_makefile_star2_O1/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
movq $0x0, 0x28(%rsp)
xorl %esi, %esi
xorl %eax, %eax
callq 0x21a0
cmpl $-0x1, %eax
je 0x41ff
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 0xc(%rsp), %rax
movl $0x0, (%rax)
leaq 0xc8(%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 0x90(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
movss 0x69bc(%rip), %xmm0     # 0xa8c0
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
leaq 0x7(%rsp), %r12
movq %rax, 0x30(%rsp)
movss %xmm0, 0x8(%rsp)
movl $0x0, 0x1c(%rsp)
xorl %r13d, %r13d
movl $0x1, %edx
movl %ebp, %edi
movq %r12, %rsi
callq 0x2310
movq %rax, %r14
cmpl $0x400, %r13d           # imm = 0x400
jne 0x3f52
movl $0x800, %esi            # imm = 0x800
movq %r15, %rdi
callq 0x23b0
movq %rax, %r15
movzbl 0x7(%rsp), %eax
cmpl $0x20, %eax
je 0x3f70
cmpl $0xd, %eax
je 0x4175
cmpl $0xa, %eax
jne 0x3faa
movb $0x1, %al
movl %eax, 0x1c(%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
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
movb $0x1, %bl
jmp 0x3fb4
movslq %r13d, %rcx
movb %al, (%r15,%rcx)
incl %r13d
testl %r13d, %r13d
setg %al
andb %bl, %al
cmpb $0x1, %al
jne 0x4175
cmpl $0x3, 0x28(%rsp)
jne 0x401b
movq 0x38(%rsp), %r13
callq 0x2060
movq %rax, %rbx
movl (%rax), %eax
movl %eax, 0x24(%rsp)
movl $0x0, (%rbx)
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x2300
movss %xmm0, 0x8(%rsp)
cmpq %r13, 0x10(%rsp)
je 0x41e7
movl (%rbx), %eax
testl %eax, %eax
movq 0x30(%rsp), %r13
je 0x4049
cmpl $0x22, %eax
jne 0x40b1
jmp 0x41f3
leaq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x4556
testq %rax, %rax
je 0x4051
leaq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x493e
movl (%rax), %r13d
jmp 0x40b1
movl 0x24(%rsp), %eax
movl %eax, (%rbx)
jmp 0x40b1
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 0xc(%rsp), %rsi
callq 0x466e
movq %rbx, (%rax)
movl 0xc(%rsp), %ebx
leaq 0x98(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x493e
movl %ebx, (%rax)
movl 0xc(%rsp), %r13d
leal 0x1(%r13), %eax
movl %eax, 0xc(%rsp)
testb $0x1, 0x1c(%rsp)
movl 0x18(%rsp), %ebx
movq %r13, 0x30(%rsp)
je 0x4150
movl %r13d, 0x20(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x4c7c
movl %ebx, 0x10(%rsp)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4f70
movl %ebx, 0x20(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x4c7c
movl %r13d, 0x10(%rsp)
movss 0x8(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4f70
movl $0x0, 0x1c(%rsp)
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movss 0x6781(%rip), %xmm0     # 0xa8c0
movss %xmm0, 0x8(%rsp)
movq $0x0, 0x28(%rsp)
jmp 0x415b
cmpl $-0x1, %ebx
cmovel %r13d, %ebx
movl %ebx, 0x18(%rsp)
movq %r15, %rdi
callq 0x22a0
movl $0x400, %edi            # imm = 0x400
callq 0x22f0
movq %rax, %r15
xorl %ebx, %ebx
xorl %r13d, %r13d
testl %r14d, %r14d
jne 0x3f27
movq %r15, %rdi
callq 0x22a0
leaq 0xd0(%rsp), %rsi
leaq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rdi
callq 0x4270
leaq 0x60(%rsp), %rdi
callq 0x4388
leaq 0xd0(%rsp), %rdi
callq 0x445e
leaq 0x98(%rsp), %rdi
callq 0x44c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x41d5
callq 0x2220
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x66e7(%rip), %rdi      # 0xa8d5
callq 0x2130
leaq 0x66db(%rip), %rdi      # 0xa8d5
callq 0x2320
callq 0x2430
jmp 0x422d
movq %rax, %r14
movq %rbx, %rdi
callq 0x2220
jmp 0x4230
jmp 0x422d
jmp 0x422d
jmp 0x422d
jmp 0x422d
jmp 0x422d
movq %rax, %r14
cmpl $0x0, (%rbx)
jne 0x4230
movl 0x24(%rsp), %eax
movl %eax, (%rbx)
jmp 0x4230
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0x4388
leaq 0xd0(%rsp), %rdi
callq 0x445e
leaq 0x98(%rsp), %rdi
callq 0x44c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x4268
callq 0x2220
movq %r14, %rdi
callq 0x23d0