// File: sjain12[P]CliqueCounting/GraphIO.cpp
// Function: loadGraph_Escape(char const*, Escape::Graph&, int)
static ErrorCode loadGraph_Escape(const char *path, Graph& graph, int undirected)
{
  FILE* f = fopen(path, "r");
  if (!f)
  {
    fprintf(stderr, "could not open file %s\n", path);
    return ecInvalidInput;
  }

  graph.nVertices = 0;
  EdgeIdx iEdge = 0;
  char line[1024];
  while (fgets(line, sizeof(line), f))
  {
    //Ignore comment lines.
    if (line[0] == '#')
      continue;

    if (isBlankLine(line))
      continue;
      
    int64_t i1, i2;
    sscanf(line, "%ld%ld", &i1, &i2);
    if (graph.nVertices == 0)
    {
      graph.nVertices = i1;
	//cout << "Original number of edges = " << i2 << endl;
      if (undirected)
          graph.nEdges = 2*i2;
      else
          graph.nEdges = i2;
      graph.srcs = new VertexIdx[graph.nEdges];
      graph.dsts = new VertexIdx[graph.nEdges];
    }
    else
    {
      graph.srcs[iEdge] = i1;
      graph.dsts[iEdge] = i2;
      ++iEdge;
      if (undirected)
      {
          graph.srcs[iEdge] = i2;
          graph.dsts[iEdge] = i1;
          ++iEdge;
      }
    }
  }
  fclose(f);
	//cout << "num edges = " << graph.nEdges << endl;
  if (iEdge < graph.nEdges)
  {
    fprintf(stderr, "expected %ld edges, only got %ld\n", graph.nEdges, iEdge);
    return ecIOError;
  }
  
  return ecNone;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1682(%rip), %rsi      # 0x19153
callq 0x33c0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x17b09
movq 0xc4f0(%rip), %rax      # 0x23fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1b2e(%rip), %rsi      # 0x19624
movb $0x0, %al
callq 0x3450
movl $0x1, -0x4(%rbp)
jmp 0x17cfb
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x30(%rbp)
leaq -0x430(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x34c0
cmpq $0x0, %rax
je 0x17cb0
movsbl -0x430(%rbp), %eax
cmpl $0x23, %eax
jne 0x17b49
jmp 0x17b1c
leaq -0x430(%rbp), %rdi
callq 0x18080
testb $0x1, %al
jne 0x17b5b
jmp 0x17b5d
jmp 0x17b1c
leaq -0x430(%rbp), %rdi
leaq 0x1ad1(%rip), %rsi      # 0x1963c
leaq -0x438(%rbp), %rdx
leaq -0x440(%rbp), %rcx
movb $0x0, %al
callq 0x32f0
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x17c2f
movq -0x438(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x1c(%rbp)
je 0x17bb6
movq -0x440(%rbp), %rcx
shlq %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x17bc5
movq -0x440(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x17cab
movq -0x438(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x440(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x17ca9
movq -0x440(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x438(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x17cab
jmp 0x17b1c
movq -0x28(%rbp), %rdi
callq 0x3310
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x17cf4
movq 0xc30a(%rip), %rax      # 0x23fd8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x30(%rbp), %rcx
leaq 0x195f(%rip), %rsi      # 0x19643
movb $0x0, %al
callq 0x3450
movl $0x4, -0x4(%rbp)
jmp 0x17cfb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopw (%rax,%rax)