// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movl %edx, 0x8(%rsp)
movq %rsi, %rax
movq %rdi, %r14
leaq 0xbd36(%rip), %rsi      # 0x114af
movq %rax, %rdi
callq 0x2250
movq %rax, %r15
testq %rax, %rax
jne 0x5792
xorl %edi, %edi
xorl %eax, %eax
callq 0x8240
xorl %eax, %eax
leaq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
leaq 0x30(%rsp), %rcx
movq %rax, 0x10(%rcx)
movaps %xmm0, (%rcx)
leaq 0xc(%rsp), %r12
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r15, %rdi
leaq 0xc44d(%rip), %rsi      # 0x11c10
leaq 0x4(%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x23b0
cmpl $0x2, %eax
jne 0x586a
testb %bpl, %bpl
je 0x57f6
movq %r15, %rdi
leaq 0xc429(%rip), %rsi      # 0x11c13
leaq 0x54(%rsp), %rdx
xorl %eax, %eax
callq 0x23b0
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5813
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x5822
leaq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x52ec
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x583f
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x5850
leaq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x52ec
movl 0xc(%rsp), %eax
movl 0x4(%rsp), %ecx
cmpl %r13d, %ecx
cmovgl %ecx, %r13d
cmpl %r13d, %eax
cmovgl %eax, %r13d
incq %rbx
jmp 0x57b9
movq %r15, %rdi
callq 0x21e0
movq (%r14), %rax
movl 0x8(%rsp), %ecx
xorb $0x1, %cl
movzbl %cl, %edx
movq %r14, %rdi
movl %r13d, %esi
callq *0x18(%rax)
testl %ebx, %ebx
je 0x5946
movq 0x12741(%rip), %r13     # 0x17fd8
leaq 0xc378(%rip), %r15      # 0x11c16
leaq 0xc38a(%rip), %r12      # 0x11c2f
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movl (%rax,%rbp), %eax
movq 0x30(%rsp), %rcx
movl (%rcx,%rbp), %edx
cmpl %edx, %eax
je 0x591c
decl %eax
decl %edx
movq (%r14), %rcx
movq %r14, %rdi
movl %eax, %esi
callq *0x50(%rcx)
movq 0x30(%rsp), %rcx
movl (%rcx,%rbp), %ecx
testb %al, %al
jne 0x592e
movq 0x10(%rsp), %rax
movl (%rax,%rbp), %esi
decl %esi
decl %ecx
movq (%r14), %rax
movq %r14, %rdi
movl %ecx, %edx
callq *0x30(%rax)
cmpb $0x0, 0x8(%rsp)
jne 0x5911
movq 0x30(%rsp), %rax
movl (%rax,%rbp), %esi
decl %esi
movq 0x10(%rsp), %rax
movl (%rax,%rbp), %edx
decl %edx
movq (%r14), %rax
movq %r14, %rdi
callq *0x30(%rax)
addq $0x4, %rbp
decq %rbx
jne 0x58a7
jmp 0x5946
movq (%r13), %rdi
movq %r15, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x22d0
jmp 0x5911
movq (%r13), %rdi
movq 0x10(%rsp), %rax
movl (%rax,%rbp), %edx
movq %r12, %rsi
xorl %eax, %eax
callq 0x22d0
jmp 0x58ed
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x5957
movq %rdi, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x5968
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x5982
movq 0x40(%rsp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x2200
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5994
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x59a7
jmp 0x59a7
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x59c1
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x59d8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2370