// File: /workspace/github_c_makefile_star2_O3/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 0x5df6(%rip), %rsi      # 0xd150
movq %rax, %rdi
callq 0x21d0
testq %rax, %rax
je 0x754c
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 0x5daa(%rip), %rsi      # 0xd152
leaq 0x8(%rsp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x22f0
cmpl $0x2, %eax
jne 0x7457
testb %bpl, %bpl
je 0x73db
movq %r15, %rdi
leaq 0x5d86(%rip), %rsi      # 0xd155
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 0x7404
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x7413
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6800
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x7430
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x7441
leaq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x6800
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ecx
cmpl %ebx, %ecx
cmovgl %ecx, %ebx
cmpl %ebx, %eax
cmovgl %eax, %ebx
incq %r14
jmp 0x739e
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 0x74ef
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movl (%rax,%rbx), %esi
movq 0x30(%rsp), %rax
movl (%rax,%rbx), %edx
cmpl %edx, %esi
je 0x74e6
decl %esi
decl %edx
movq (%r15), %rax
movq %r15, %rdi
callq *0x48(%rax)
testb %al, %al
jne 0x74c4
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 0x74e6
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 0x7482
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x7500
movq %rdi, 0x18(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x7511
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x752b
movq 0x40(%rsp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x21a0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x753d
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 0x755a
jmp 0x755a
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7574
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x758b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21a0
movq %rbx, %rdi
callq 0x22c0
nop