// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
movq %rdi, 0x48(%rsp)
movq (%rsi), %rdi
xorl %r12d, %r12d
xorl %esi, %esi
xorl %eax, %eax
callq 0x21a0
movl %eax, 0x24(%rsp)
cmpl $-0x1, %eax
je 0x3854
movl $0x400, %edi            # imm = 0x400
callq 0x22d0
movq %rax, %r15
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0xc(%rsp), %rcx
andl $0x0, (%rcx)
movb $0x0, (%rax)
leaq 0x80(%rsp), %rax
movq %rax, -0x30(%rax)
pushq $0x1
popq %rdx
movq %rdx, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, %ecx       # imm = 0x3F800000
movl %ecx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0xf0(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rdx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %ecx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0xb8(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rdx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %ecx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
movss 0x72a6(%rip), %xmm0     # 0xa894
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movss %xmm0, 0x4(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movl 0x24(%rsp), %edi
leaq 0x3(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x22f0
movq %rax, %r14
cmpl $0x400, %r13d           # imm = 0x400
jne 0x3632
movl $0x800, %esi            # imm = 0x800
movq %r15, %rdi
callq 0x2380
movq %rax, %r15
movzbl 0x3(%rsp), %ecx
movslq %r13d, %rax
cmpl $0x20, %ecx
je 0x3650
cmpl $0xd, %ecx
je 0x37e9
cmpl $0xa, %ecx
jne 0x3669
movb $0x1, %bpl
movb $0x0, (%r15,%rax)
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x23e0
incl %r12d
movb $0x1, %bl
jmp 0x3670
movb %cl, (%r15,%rax)
incl %r13d
testl %r13d, %r13d
setg %al
andb %bl, %al
cmpb $0x1, %al
jne 0x37e9
cmpl $0x3, %r12d
jne 0x369d
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x39ca
movss %xmm0, 0x4(%rsp)
jmp 0x3726
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3cb6
testq %rax, %rax
je 0x36c9
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4142
movl (%rax), %eax
movq %rax, 0x10(%rsp)
jmp 0x3726
pushq $0x68
popq %rdi
callq 0x2250
movq %rax, %r13
movq %rax, %rdi
callq 0x25bc
movq %r13, %rdi
addq $0x8, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2130
leaq 0xc0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x3dd2
movq %r13, (%rax)
movl 0xc(%rsp), %ebx
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4142
movl %ebx, (%rax)
movl 0xc(%rsp), %eax
movq %rax, 0x10(%rsp)
incl %eax
movl %eax, 0xc(%rsp)
testb $0x1, %bpl
je 0x37bd
movq 0x10(%rsp), %rax
movl %eax, 0x20(%rsp)
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
leaq 0x20(%rsp), %r12
movq %r12, %rsi
callq 0x449c
movl 0x8(%rsp), %ebp
movl %ebp, 0x18(%rsp)
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x47f6
movl %ebp, 0x20(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x449c
movq 0x10(%rsp), %rcx
movl %ecx, 0x18(%rsp)
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x47f6
xorl %r12d, %r12d
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
movss 0x70df(%rip), %xmm0     # 0xa894
movss %xmm0, 0x4(%rsp)
jmp 0x37cd
movl 0x8(%rsp), %eax
cmpl $-0x1, %eax
cmovel 0x10(%rsp), %eax
movl %eax, 0x8(%rsp)
movq %r15, %rdi
callq 0x2280
movl $0x400, %edi            # imm = 0x400
callq 0x22d0
movq %rax, %r15
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r13d, %r13d
testl %r14d, %r14d
jne 0x3605
movq %r15, %rdi
callq 0x2280
leaq 0xc0(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq 0x48(%rsp), %rdi
callq 0x38ba
leaq 0x88(%rsp), %rdi
callq 0x3a98
leaq 0xc0(%rsp), %rdi
callq 0x3b88
leaq 0x50(%rsp), %rdi
callq 0x3c0e
leaq 0x28(%rsp), %rdi
callq 0x2100
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x703d(%rip), %rdi      # 0xa898
callq 0x21d0
pushq $0x1
popq %rdi
callq 0x2290
jmp 0x3881
movq %rax, %rbx
movq %r13, %rdi
callq 0x2220
jmp 0x3884
jmp 0x3881
jmp 0x3881
jmp 0x3881
jmp 0x3881
jmp 0x3881
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3a98
leaq 0xc0(%rsp), %rdi
callq 0x3b88
leaq 0x50(%rsp), %rdi
callq 0x3c0e
leaq 0x28(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x23a0