// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkstorage.cc
// Function: read_cgd(_IO_FILE*, ATOM_NETWORK*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)
bool read_cgd(FILE *cgd, ATOM_NETWORK *cell, string *net) {
  bool verbose = false; //write parsing progress to terminal
  if(verbose) printf(" --- called read_cgd() --- \n");
  char *line = new char[maxline];
  vector<string> token;
  int line_num = 0;
  bool read_ok = false;
  int atom_index = 0;
  bool uses_atom = false;
  bool uses_node = false; //two different kinds of file format use these different flags, and order/format the data differently ...
  //flags for when line breaks separate the data to be read
  bool anticipating_name = false, anticipating_cell = false, anticipating_group = false, anticipating_atom = false, anticipating_node = false, anticipating_edge = false;
  //reading loop begins here
  while(fgets(line, maxline, cgd)!=NULL && !read_ok) {
    if(verbose) printf("read line \"%s\"\n", line);
    line_num++;
    token = split(string(line)," ()\r\t\n");
    int num_tokens = token.size();
    if(num_tokens==0) {
      //do nothing on this empty line, just skip to next line
    }
    else if(token.at(0)=="name" || token.at(0)=="NAME" || token.at(0)=="id" || token.at(0)=="ID") {
      if(num_tokens>1) { //read from this line if there are fields, else read from next line...
        (*net) = token.at(1); //returning
      } else anticipating_name = true;
      if(verbose) printf("parsed topology name %s\n", net->c_str());
    }
    else if(anticipating_name) {
      (*net) = token.at(0); //returning
      anticipating_name = false;
    }
    else if(token.at(0)=="cell" || token.at(0)=="CELL") {
      if(num_tokens>6) { //read from this line if there are fields, else read from next line...
        parse_cell(&token, 1, cell);
      } else anticipating_cell = true;
    }
    else if(anticipating_cell && num_tokens>5) { //right now potential line breaks between cell definition and data fields are only handled when all the data fields are on the same line
      parse_cell(&token, 0, cell);
      anticipating_cell = false;
    }
    else if(token.at(0)=="group" || token.at(0)=="GROUP") {
      if(num_tokens>1) { //read from this line if there are fields, else read from next line...
        parse_group(&token, 1, cell);
      } else anticipating_group = true;
    }
    else if(anticipating_group) {
      parse_group(&token, 0, cell);
      anticipating_group = false;
    }
    else if(token.at(0)=="atom" || token.at(0)=="ATOM") {
      uses_atom = true;
      if(num_tokens>5) { //read from this line if there are fields, else read from next line...
        parse_atom(&token, 1, cell, &atom_index, &line_num, line, cgd);
      } else anticipating_atom = true;
    }
    else if(anticipating_atom && num_tokens>4) { //right now potential line breaks between atom definition and data fields are only handled when all the data fields are on the same line
      parse_atom(&token, 0, cell, &atom_index, &line_num, line, cgd);
      anticipating_atom = false;
    }
    else if(token.at(0)=="node" || token.at(0)=="NODE") { //a different kind of atom, does not list nodes directly
      uses_node = true;
      if(num_tokens>5) { //read from this line if there are fields, else read from next line...
        parse_node(&token, 1, cell, &atom_index);
      } else anticipating_node = true;
    }
    else if(anticipating_node && num_tokens>4) { //right now potential line breaks between node definition and data fields are only handled when all the data fields are on the same line
      parse_node(&token, 0, cell, &atom_index);
      anticipating_node = false;
    }
    else if(token.at(0)=="edge" || token.at(0)=="EDGE") { //should only occur when the different kind of atom (node) is used - handled differently to edges above
      if(num_tokens>6) { //read from this line if there are fields, else read from next line...
        parse_edge(&token, 1, cell, atom_index, uses_node);
      } else anticipating_edge = true;
    }
    else if(anticipating_edge && num_tokens>5) {
      parse_edge(&token, 0, cell, atom_index, uses_node);
      anticipating_edge = false;
    }
    else if(token.at(0)=="#") { //comment - ignore
      //do nothing
    }
    else if(token.at(0)=="end" || token.at(0)=="END") {
      if(verbose) printf(" --- successfully finished parsing net file --- \n");
      read_ok = true;
    }
    if(uses_node && uses_atom) {
      printf("NET ERROR: detected that both atom and node flags are used in the input net file - this is currently assumed to indicate an invalid input file\n");
      exit(EXIT_FAILURE);
    }
  }
  if(!read_ok) {
    printf("NET WARNING: net file parsing ended before \"end\" line was read\n");
  } else printf("net file parsed correctly\n");
  int num_v = cell->vertices.size();
  bool edges_provided_exhaustively = true;
  for(int i=0; i<num_v && edges_provided_exhaustively; i++) {
    if(cell->vertices.at(i).expected_edges!=cell->vertices.at(i).edges.size()) edges_provided_exhaustively = false;
  }
  delete[] line;
  return edges_provided_exhaustively;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdx, 0x58(%rsp)
movq %rsi, %r14
movq %rdi, %r13
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x4030
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
xorl %eax, %eax
movl %eax, 0x4c(%rsp)
movl %eax, 0x2c(%rsp)
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %r13, %rdx
callq 0x4690
testq %rax, %rax
je 0x61107
movq %r14, 0x30(%rsp)
movq $0x0, 0x50(%rsp)
leaq 0xa0(%rsp), %rbp
movl $0x0, 0x48(%rsp)
movl $0x0, 0x38(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x8(%rsp)
xorl %r12d, %r12d
incl 0x4c(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
callq 0x41e0
leaq (%rax,%rbx), %rdx
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x22538
leaq 0x90(%rsp), %r15
movq %r15, 0x80(%rsp)
leaq 0x80(%rsp), %r14
movq %r14, %rdi
leaq 0xf2b77(%rip), %rsi     # 0x153619
leaq 0xf2b76(%rip), %rdx     # 0x15361f
callq 0x22538
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
movq %r14, %rdx
callq 0x4a3cc
movq 0x20(%rsp), %rax
movaps 0xa0(%rsp), %xmm0
movq 0xb0(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movaps 0x10(%rsp), %xmm1
movaps %xmm0, 0x10(%rsp)
movaps %xmm1, 0xc0(%rsp)
movq %rax, 0xd0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x2f4c2
movq %rbp, %rdi
callq 0x2f4c2
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x60b3b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x60b57
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
movq %rax, %r15
subq %rdi, %r15
sarq $0x5, %r15
testl %r15d, %r15d
je 0x60cfd
cmpq %rdi, %rax
je 0x611f1
leaq 0xf1516(%rip), %rsi     # 0x15209a
callq 0x4170
testl %eax, %eax
je 0x60c1a
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf2a78(%rip), %rsi     # 0x153620
callq 0x4170
testl %eax, %eax
je 0x60c1a
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xed1c4(%rip), %rsi     # 0x14dd8c
callq 0x4170
testl %eax, %eax
je 0x60c1a
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf2a3d(%rip), %rsi     # 0x153625
callq 0x4170
testl %eax, %eax
je 0x60c1a
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
testb $0x1, 0x8(%rsp)
je 0x60c59
cmpq %rsi, %rax
je 0x611cc
movq 0x58(%rsp), %rdi
callq 0x4240
jmp 0x60cf5
cmpl $0x2, %r15d
jl 0x60c4e
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %r15
subq %rsi, %r15
sarq $0x5, %r15
cmpq $0x2, %r15
jb 0x611e7
addq $0x20, %rsi
movq 0x58(%rsp), %rdi
callq 0x4240
jmp 0x60cfd
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x60cfd
cmpq %rsi, %rax
je 0x611cc
movq %rsi, %rdi
leaq 0xf168a(%rip), %rsi     # 0x1522f6
callq 0x4170
testl %eax, %eax
je 0x60cd3
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf299c(%rip), %rsi     # 0x153628
callq 0x4170
testl %eax, %eax
je 0x60cd3
cmpl $0x6, %r15d
setl %al
movl 0x44(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x60d40
movl $0x0, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
callq 0x61265
movl $0x0, 0x44(%rsp)
xorl %r15d, %r15d
jmp 0x60d00
cmpl $0x7, %r15d
jl 0x60cef
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rdx
callq 0x61265
jmp 0x60cf5
movb $0x1, %al
movl %eax, 0x44(%rsp)
movl $0x0, 0x8(%rsp)
xorl %r15d, %r15d
testb $0x1, %r12b
je 0x60d19
testb $0x1, 0x48(%rsp)
jne 0x611d1
movl $0x0, 0x48(%rsp)
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %r13, %rdx
callq 0x4690
testq %rax, %rax
je 0x610eb
testb %r15b, %r15b
je 0x60a59
jmp 0x610eb
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf28d6(%rip), %rsi     # 0x15362d
callq 0x4170
testl %eax, %eax
je 0x60db0
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf28bc(%rip), %rsi     # 0x153633
callq 0x4170
testl %eax, %eax
je 0x60db0
testb $0x1, 0xc(%rsp)
je 0x60dda
movl $0x0, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
callq 0x613f4
movl $0x0, 0xc(%rsp)
xorl %r15d, %r15d
jmp 0x60d00
cmpl $0x2, %r15d
jl 0x60dcf
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rdx
callq 0x613f4
jmp 0x60cf5
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x60cf5
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf661a(%rip), %rsi     # 0x15740b
callq 0x4170
testl %eax, %eax
je 0x60e74
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf2828(%rip), %rsi     # 0x153639
callq 0x4170
testl %eax, %eax
je 0x60e74
cmpl $0x5, %r15d
setl %al
movl 0x40(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x60ed5
movl $0x0, 0x8(%rsp)
movq %r13, (%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x4c(%rsp), %r8
movq %rbx, %r9
callq 0x6150b
movl $0x0, 0xc(%rsp)
movl $0x0, 0x40(%rsp)
xorl %r15d, %r15d
jmp 0x60d00
movb $0x1, %al
movl %eax, 0x48(%rsp)
cmpl $0x6, %r15d
jl 0x60eba
movq %r13, (%rsp)
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x4c(%rsp), %r8
movq %rbx, %r9
callq 0x6150b
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x60cfd
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
movb $0x1, %al
movl %eax, 0x40(%rsp)
jmp 0x60cfd
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf5785(%rip), %rsi     # 0x156671
callq 0x4170
testl %eax, %eax
je 0x60f5f
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf53dd(%rip), %rsi     # 0x1562e9
callq 0x4170
testl %eax, %eax
je 0x60f5f
cmpl $0x5, %r15d
setl %al
movl 0x3c(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x60fa4
movl $0x0, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
leaq 0x2c(%rsp), %rcx
callq 0x61c87
movl $0x0, 0xc(%rsp)
movl $0x0, 0x3c(%rsp)
xorl %r15d, %r15d
jmp 0x60d00
movb $0x1, %r12b
cmpl $0x6, %r15d
jl 0x60f86
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rdx
leaq 0x2c(%rsp), %rcx
callq 0x61c87
xorl %r15d, %r15d
jmp 0x60f8f
xorl %r15d, %r15d
movb $0x1, %al
movl %eax, 0x3c(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
jmp 0x60d06
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xfd431(%rip), %rsi     # 0x15e3ec
callq 0x4170
testl %eax, %eax
je 0x61035
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf272b(%rip), %rsi     # 0x153706
callq 0x4170
testl %eax, %eax
je 0x61035
cmpl $0x6, %r15d
setl %al
movl 0x38(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x6106b
movl 0x2c(%rsp), %ecx
movl $0x0, 0x8(%rsp)
movzbl %r12b, %r8d
andl $0x1, %r8d
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x30(%rsp), %rdx
callq 0x61e84
movl $0x0, 0xc(%rsp)
movl $0x0, 0x38(%rsp)
xorl %r15d, %r15d
jmp 0x60d00
cmpl $0x7, %r15d
jl 0x61060
movl 0x2c(%rsp), %ecx
movzbl %r12b, %r8d
andl $0x1, %r8d
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x30(%rsp), %rdx
callq 0x61e84
jmp 0x60ea5
movb $0x1, %al
movl %eax, 0x38(%rsp)
jmp 0x60ea5
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf040c(%rip), %rsi     # 0x15148e
callq 0x4170
testl %eax, %eax
je 0x60ea5
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xf5406(%rip), %rsi     # 0x1564ac
callq 0x4170
testl %eax, %eax
je 0x610d3
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x611cc
leaq 0xed1dd(%rip), %rsi     # 0x14e2a3
callq 0x4170
testl %eax, %eax
jne 0x60ea5
movb $0x1, %r15b
movl $0x0, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
jmp 0x60d00
leaq 0xf3015(%rip), %rax     # 0x154107
leaq 0xf2fcf(%rip), %rdi     # 0x1540c8
testb %r15b, %r15b
cmovneq %rax, %rdi
movq 0x30(%rsp), %r14
jmp 0x6110e
leaq 0xf2fba(%rip), %rdi     # 0x1540c8
callq 0x4660
movq 0x3c0(%r14), %rax
movq 0x3c8(%r14), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
movabsq $0x6db6db6db6db6db7, %rdx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rdx
testl %edx, %edx
jle 0x61192
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rdx, %rsi
negq %rsi
addq $0x28, %rax
movl $0x1, %edi
movabsq $-0x5555555555555555, %r8 # imm = 0xAAAAAAAAAAAAAAAB
leaq (%rsi,%rdi), %r9
cmpq $0x1, %r9
je 0x611bb
movslq -0x10(%rax), %r9
movq (%rax), %r10
subq -0x8(%rax), %r10
sarq $0x3, %r10
imulq %r8, %r10
cmpq %r9, %r10
sete %bpl
cmpq %rcx, %rdi
jae 0x61195
incq %rdi
addq $0x70, %rax
cmpq %r9, %r10
je 0x6115b
jmp 0x61195
movb $0x1, %bpl
movq %rbx, %rdi
callq 0x4570
leaq 0x10(%rsp), %rdi
callq 0x2f4c2
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xec533(%rip), %rdi     # 0x14d6f5
movq %rdx, %rsi
xorl %eax, %eax
callq 0x4630
xorl %r15d, %r15d
jmp 0x611f1
leaq 0xf2f49(%rip), %rdi     # 0x154121
callq 0x4660
movl $0x1, %edi
callq 0x72bc
movl $0x1, %eax
movq %rax, 0x50(%rsp)
leaq 0xec4fd(%rip), %rdi     # 0x14d6f5
movq 0x50(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x4630
jmp 0x61250
jmp 0x61250
movq %rax, %rbx
jmp 0x61230
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x61230
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x61253
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x61253
jmp 0x61250
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2f4c2
movq %rbx, %rdi
callq 0x4780