// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]gtrieScanner/GraphUtils.cpp
// Function: GraphUtils::readFileTxt(Graph*, char const*, bool, bool)
void GraphUtils::readFileTxt(Graph *g, const char *s, bool dir, bool weight) {

  FILE *f = fopen(s, "r");
  if (!f) Error::msg(NULL);

  int i, a, b, c, size, max;
  vector<int> va, vb;

  size = max = 0;
  while (fscanf(f,"%d %d", &a, &b)==2) {
    if (weight) i=fscanf(f,"%d", &c);
    va.push_back(a);
    vb.push_back(b);
    if (a>max) max=a;
    if (b>max) max=b;
    size++;
  }
    
  fclose(f);

  if (dir) g->createGraph(max, DIRECTED);
  else     g->createGraph(max, UNDIRECTED);

  for (i=0; i<size; i++) {
    if (va[i]==vb[i]) {
      fprintf(stderr, "Self-Loop on %d ignored\n", va[i]);
      continue; // discard self loops!
    }
    if (g->hasEdge(va[i]-1, vb[i]-1))
      fprintf(stderr,"Repeated connection! %d %d\n", va[i], vb[i]);
    else 
      g->addEdge(va[i]-1, vb[i]-1);
    if (!dir) g->addEdge(vb[i]-1, va[i]-1);
  } 
  va.clear();
  vb.clear();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, 0x4(%rsp)
movl %edx, (%rsp)
movq %rsi, %rax
movq %rdi, %r14
leaq 0xb1b5(%rip), %rsi      # 0x104af
movq %rax, %rdi
callq 0x2270
movq %rax, %r15
testq %rax, %rax
jne 0x5313
xorl %edi, %edi
xorl %eax, %eax
callq 0x7c64
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x10(%rsp), %rax
andq $0x0, 0x10(%rax)
movaps %xmm0, (%rax)
leaq 0xc(%rsp), %r13
leaq 0x8(%rsp), %r12
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %r15, %rdi
leaq 0xb867(%rip), %rsi      # 0x10baf
movq %r13, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x23f0
cmpl $0x2, %eax
jne 0x53a8
cmpb $0x0, 0x4(%rsp)
je 0x5377
movq %r15, %rdi
leaq 0xb847(%rip), %rsi      # 0x10bb2
leaq 0x54(%rsp), %rdx
xorl %eax, %eax
callq 0x23f0
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x4c68
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x4c68
movl 0xc(%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
movl 0x8(%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
incq %rbp
jmp 0x533e
movq %r15, %rdi
callq 0x21f0
movq (%r14), %rax
movl (%rsp), %ecx
xorb $0x1, %cl
movzbl %cl, %edx
movq %r14, %rdi
movl %ebx, %esi
callq *0x18(%rax)
movq 0x12c0d(%rip), %rbx     # 0x17fd8
leaq 0xb7e3(%rip), %r15      # 0x10bb5
leaq 0xb7f5(%rip), %r12      # 0x10bce
xorl %r13d, %r13d
movq 0x30(%rsp), %rax
subq $0x1, %rbp
jb 0x5484
movl (%rax,%r13), %eax
movq 0x10(%rsp), %rcx
movl (%rcx,%r13), %edx
cmpl %edx, %eax
je 0x545b
decl %eax
decl %edx
movq (%r14), %rcx
movq %r14, %rdi
movl %eax, %esi
callq *0x50(%rcx)
movq 0x10(%rsp), %rcx
movl (%rcx,%r13), %ecx
testb %al, %al
jne 0x546c
movq 0x30(%rsp), %rax
movl (%rax,%r13), %esi
decl %esi
decl %ecx
movq (%r14), %rax
movq %r14, %rdi
movl %ecx, %edx
callq *0x30(%rax)
cmpb $0x0, (%rsp)
jne 0x5455
movq 0x10(%rsp), %rax
movl (%rax,%r13), %esi
decl %esi
movq 0x30(%rsp), %rax
movl (%rax,%r13), %edx
decl %edx
movq (%r14), %rax
movq %r14, %rdi
callq *0x30(%rax)
addq $0x4, %r13
jmp 0x53dc
movq (%rbx), %rdi
movq %r15, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x2310
jmp 0x5455
movq (%rbx), %rdi
movq 0x30(%rsp), %rax
movl (%rax,%r13), %edx
movq %r12, %rsi
xorl %eax, %eax
callq 0x2310
jmp 0x5430
cmpq %rax, 0x38(%rsp)
je 0x5490
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x54a1
movq %rax, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x4d62
leaq 0x30(%rsp), %rdi
callq 0x4d62
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x54c8
jmp 0x54c8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4d62
leaq 0x30(%rsp), %rdi
callq 0x4d62
movq %rbx, %rdi
callq 0x23b0
nop