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

  FILE *f = fopen(s, "r");
  if (!f)
    exit(EXIT_FAILURE);

  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);
    a += 1 - base; b += 1 - base;
    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 %r8d, %ebx
movl %ecx, 0xc(%rsp)
movl %edx, 0x8(%rsp)
movq %rsi, %rax
movq %rdi, 0x48(%rsp)
leaq 0x57dc(%rip), %rsi      # 0xc114
movq %rax, %rdi
callq 0x21e0
testq %rax, %rax
je 0x6ac6
movq %rax, %r15
leaq 0x30(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x1
popq %r14
subl %ebx, %r14d
leaq 0x4(%rsp), %r13
movq %rsp, %r12
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %r15, %rdi
leaq 0x5790(%rip), %rsi      # 0xc116
movq %r13, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2320
cmpl $0x2, %eax
jne 0x69ee
cmpb $0x0, 0xc(%rsp)
je 0x69b5
movq %r15, %rdi
leaq 0x5770(%rip), %rsi      # 0xc119
leaq 0x54(%rsp), %rdx
xorl %eax, %eax
callq 0x2320
addl %r14d, 0x4(%rsp)
addl %r14d, (%rsp)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x5328
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x5328
movl 0x4(%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
movl (%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
incq %rbp
jmp 0x697c
movq %r15, %rdi
callq 0x2190
movq 0x48(%rsp), %r15
movq (%r15), %rax
movl 0x8(%rsp), %r14d
movl %r14d, %ecx
xorb $0x1, %cl
movzbl %cl, %edx
movq %r15, %rdi
movl %ebx, %esi
callq *0x10(%rax)
xorl %ebx, %ebx
movq 0x30(%rsp), %rax
subq $0x1, %rbp
jb 0x6a86
movl (%rax,%rbx), %esi
movq 0x10(%rsp), %rax
movl (%rax,%rbx), %edx
cmpl %edx, %esi
je 0x6a80
decl %esi
decl %edx
movq (%r15), %rax
movq %r15, %rdi
callq *0x48(%rax)
testb %al, %al
jne 0x6a5e
movq 0x30(%rsp), %rax
movl (%rax,%rbx), %esi
decl %esi
movq 0x10(%rsp), %rax
movl (%rax,%rbx), %edx
decl %edx
movq (%r15), %rax
movq %r15, %rdi
callq *0x28(%rax)
testb %r14b, %r14b
jne 0x6a80
movq 0x10(%rsp), %rax
movl (%rax,%rbx), %esi
decl %esi
movq 0x30(%rsp), %rax
movl (%rax,%rbx), %edx
decl %edx
movq (%r15), %rax
movq %r15, %rdi
callq *0x28(%rax)
addq $0x4, %rbx
jmp 0x6a16
cmpq %rax, 0x38(%rsp)
je 0x6a92
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x6aa3
movq %rax, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x541c
leaq 0x30(%rsp), %rdi
callq 0x541c
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
callq 0x2200
jmp 0x6ad2
jmp 0x6ad2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x541c
leaq 0x30(%rsp), %rdi
callq 0x541c
movq %rbx, %rdi
callq 0x22f0
nop