// File: /workspace/github_c_makefile_star2_O1/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 0xc3b6(%rip), %rsi      # 0x11aaf
movq %rax, %rdi
callq 0x2250
movq %rax, %r15
testq %rax, %rax
jne 0x5712
xorl %edi, %edi
xorl %eax, %eax
callq 0x8110
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 0xc4b4(%rip), %rsi      # 0x11bf7
leaq 0x4(%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x23b0
cmpl $0x2, %eax
jne 0x57ea
testb %bpl, %bpl
je 0x5776
movq %r15, %rdi
leaq 0xc490(%rip), %rsi      # 0x11bfa
leaq 0x54(%rsp), %rdx
xorl %eax, %eax
callq 0x23b0
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5793
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x57a2
leaq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x5248
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x57bf
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x57cc
leaq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x5248
movl 0x4(%rsp), %eax
cmpl %r13d, %eax
cmovgl %eax, %r13d
movl 0xc(%rsp), %eax
cmpl %r13d, %eax
cmovgl %eax, %r13d
incq %rbx
jmp 0x5739
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 0x58c6
movq 0x127c1(%rip), %r13     # 0x17fd8
leaq 0xc3df(%rip), %r15      # 0x11bfd
leaq 0xc3f1(%rip), %r12      # 0x11c16
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movl (%rax,%rbp), %eax
movq 0x30(%rsp), %rcx
movl (%rcx,%rbp), %edx
cmpl %edx, %eax
je 0x589c
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 0x58ae
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 0x5891
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 0x5827
jmp 0x58c6
movq (%r13), %rdi
movq %r15, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x22d0
jmp 0x5891
movq (%r13), %rdi
movq 0x10(%rsp), %rax
movl (%rax,%rbp), %edx
movq %r12, %rsi
xorl %eax, %eax
callq 0x22d0
jmp 0x586d
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x58d7
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
cmpq %rdi, 0x38(%rsp)
je 0x58e8
movq %rdi, 0x38(%rsp)
testq %rdi, %rdi
je 0x58fa
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5911
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 0x5924
jmp 0x5924
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x593e
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5955
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2370
nop