// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movl %r8d, %ebx
movl %ecx, %ebp
movl %edx, 0x54(%rsp)
movq %rsi, %rax
movq %rdi, 0x58(%rsp)
leaq 0x5dd2(%rip), %rsi      # 0xd114
movq %rax, %rdi
callq 0x21d0
testq %rax, %rax
je 0x7531
movq %rax, %r15
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)
movl $0x1, %r13d
subl %ebx, %r13d
leaq 0xc(%rsp), %r12
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r15, %rdi
leaq 0x5d86(%rip), %rsi      # 0xd116
leaq 0x8(%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x22f0
cmpl $0x2, %eax
jne 0x743f
testb %bpl, %bpl
je 0x73c3
movq %r15, %rdi
leaq 0x5d62(%rip), %rsi      # 0xd119
leaq 0x64(%rsp), %rdx
xorl %eax, %eax
callq 0x22f0
movl 0x8(%rsp), %eax
addl %r13d, %eax
addl %r13d, 0xc(%rsp)
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x73ec
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x73fb
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x67f6
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x7418
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x7425
leaq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x67f6
movl 0x8(%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
movl 0xc(%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
incq %r14
jmp 0x7386
movq %r15, %rdi
callq 0x2180
movq 0x58(%rsp), %r15
movq (%r15), %rax
movl 0x54(%rsp), %ebp
movl %ebp, %ecx
xorb $0x1, %cl
movzbl %cl, %edx
movq %r15, %rdi
movl %ebx, %esi
callq *0x10(%rax)
testl %r14d, %r14d
je 0x74d7
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movl (%rax,%rbx), %esi
movq 0x30(%rsp), %rax
movl (%rax,%rbx), %edx
cmpl %edx, %esi
je 0x74ce
decl %esi
decl %edx
movq (%r15), %rax
movq %r15, %rdi
callq *0x48(%rax)
testb %al, %al
jne 0x74ac
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)
testb %bpl, %bpl
jne 0x74ce
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)
addq $0x4, %rbx
decq %r14
jne 0x746a
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x74e8
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
cmpq %rdi, 0x38(%rsp)
je 0x74f9
movq %rdi, 0x38(%rsp)
testq %rdi, %rdi
je 0x750b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7522
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x21f0
jmp 0x753f
jmp 0x753f
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7559
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7570
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22c0