// File: /workspace/github_cpp_makefile_star2_O2/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, 0x20(%rsp)
movq %rdi, 0x50(%rsp)
movl $0x1f4, %edi            # imm = 0x1F4
callq 0x4030
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %r13
movaps %xmm0, (%r13)
andq $0x0, 0x10(%r13)
leaq 0x3c(%rsp), %rax
andl $0x0, (%rax)
leaq 0x1c(%rsp), %rax
andl $0x0, (%rax)
movq $0x0, 0x48(%rsp)
leaq 0xa0(%rsp), %rbp
leaq 0x80(%rsp), %r14
leaq 0xc0(%rsp), %r15
movl $0x0, 0x14(%rsp)
movl $0x0, 0x38(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x44(%rsp)
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq 0x50(%rsp), %rdx
callq 0x4690
testq %rax, %rax
je 0x4791c
testb $0x1, %r12b
jne 0x4791c
incl 0x3c(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x43(%rsp), %rdx
callq 0x1b80e
movq %r14, %rdi
leaq 0xbb1c5(%rip), %rsi     # 0x102579
leaq 0x42(%rsp), %rdx
callq 0x1b80e
movq %r15, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x38311
movq %r13, %rdi
movq %r15, %rsi
callq 0x2472c
movq %r15, %rdi
callq 0x244fc
movq %r14, %rdi
callq 0x4210
movq %rbp, %rdi
callq 0x4210
movq 0x68(%rsp), %r12
subq 0x60(%rsp), %r12
shrq $0x5, %r12
testl %r12d, %r12d
je 0x474a0
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xb9bf0(%rip), %rsi     # 0x10100a
callq 0x36bf4
testb %al, %al
jne 0x4747a
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbb149(%rip), %rsi     # 0x102580
callq 0x36bf4
testb %al, %al
jne 0x4747a
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xb5938(%rip), %rsi     # 0xfcd8c
callq 0x36bf4
testb %al, %al
jne 0x4747a
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbb114(%rip), %rsi     # 0x102585
callq 0x36bf4
testb %al, %al
je 0x474b3
cmpl $0x2, %r12d
jl 0x4749a
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x4bb9a
movq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x4270
jmp 0x474a0
movb $0x1, %al
movl %eax, 0x14(%rsp)
xorl %r12d, %r12d
testb $0x1, 0x48(%rsp)
je 0x47371
jmp 0x478fd
testb $0x1, 0x14(%rsp)
je 0x474d3
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x4270
jmp 0x4752b
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xb9d7f(%rip), %rsi     # 0x101266
callq 0x36bf4
testb %al, %al
jne 0x4750d
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbb084(%rip), %rsi     # 0x102588
callq 0x36bf4
testb %al, %al
je 0x47538
cmpl $0x7, %r12d
jl 0x47525
movq %r13, %rdi
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdx
callq 0x47a10
jmp 0x4752b
movb $0x1, %al
movl %eax, 0x38(%rsp)
movl $0x0, 0x14(%rsp)
jmp 0x474a0
cmpl $0x6, %r12d
setl %al
movl 0x38(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x47573
movl $0x0, 0x14(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movq 0x20(%rsp), %rdx
callq 0x47a10
movl $0x0, 0x38(%rsp)
xorl %r12d, %r12d
jmp 0x474a3
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbb006(%rip), %rsi     # 0x10258d
callq 0x36bf4
testb %al, %al
jne 0x475ad
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbafef(%rip), %rsi     # 0x102593
callq 0x36bf4
testb %al, %al
je 0x475d3
cmpl $0x2, %r12d
jl 0x475c8
movq %r13, %rdi
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdx
callq 0x47b10
jmp 0x4752b
movb $0x1, %al
movl %eax, 0x18(%rsp)
jmp 0x4752b
testb $0x1, 0x18(%rsp)
je 0x47601
movl $0x0, 0x14(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movq 0x20(%rsp), %rdx
callq 0x47b10
movl $0x0, 0x18(%rsp)
xorl %r12d, %r12d
jmp 0x474a3
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbecd6(%rip), %rsi     # 0x1062eb
callq 0x36bf4
testb %al, %al
jne 0x4763b
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbaf67(%rip), %rsi     # 0x102599
callq 0x36bf4
testb %al, %al
je 0x4769d
movb $0x1, %al
movl %eax, 0x44(%rsp)
cmpl $0x6, %r12d
jl 0x47682
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rdi
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x3c(%rsp), %r8
movq %rbx, %r9
callq 0x47b9f
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
jmp 0x474a0
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
movb $0x1, %al
movl %eax, 0x34(%rsp)
jmp 0x474a0
cmpl $0x5, %r12d
setl %al
movl 0x34(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x476f6
movl $0x0, 0x14(%rsp)
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %r13, %rdi
xorl %esi, %esi
movq 0x20(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x3c(%rsp), %r8
movq %rbx, %r9
callq 0x47b9f
movl $0x0, 0x18(%rsp)
movl $0x0, 0x34(%rsp)
xorl %r12d, %r12d
jmp 0x474a3
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbde47(%rip), %rsi     # 0x105551
callq 0x36bf4
testb %al, %al
jne 0x478bd
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbdafe(%rip), %rsi     # 0x105229
callq 0x36bf4
testb %al, %al
jne 0x478bd
cmpl $0x5, %r12d
setl %al
movl 0x30(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x47780
movl $0x0, 0x14(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movq 0x20(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x48045
movl $0x0, 0x18(%rsp)
movl $0x0, 0x30(%rsp)
xorl %r12d, %r12d
jmp 0x474a3
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xc7b18(%rip), %rsi     # 0x10f2ac
callq 0x36bf4
movzbl 0x48(%rsp), %ecx
movl %ecx, 0x18(%rsp)
testb %al, %al
jne 0x477c3
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbaeac(%rip), %rsi     # 0x102666
callq 0x36bf4
testb %al, %al
je 0x477f6
cmpl $0x7, %r12d
jl 0x477eb
movl 0x1c(%rsp), %ecx
movl 0x18(%rsp), %r8d
andl $0x1, %r8d
movq %r13, %rdi
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdx
callq 0x48149
jmp 0x4766d
movb $0x1, %al
movl %eax, 0x2c(%rsp)
jmp 0x4766d
cmpl $0x6, %r12d
setl %al
movl 0x2c(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x47846
movl $0x0, 0x14(%rsp)
movl 0x1c(%rsp), %ecx
movl 0x18(%rsp), %r8d
andl $0x1, %r8d
movq %r13, %rdi
xorl %esi, %esi
movq 0x20(%rsp), %rdx
callq 0x48149
movl $0x0, 0x18(%rsp)
movl $0x0, 0x2c(%rsp)
xorl %r12d, %r12d
jmp 0x474a3
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xb8bc4(%rip), %rsi     # 0x10041e
callq 0x36bf4
testb %al, %al
jne 0x4766d
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xbdb71(%rip), %rsi     # 0x1053ec
callq 0x36bf4
testb %al, %al
jne 0x478a5
movq %r13, %rdi
xorl %esi, %esi
callq 0x4bb9a
movq %rax, %rdi
leaq 0xb5a0b(%rip), %rsi     # 0xfd2a3
callq 0x36bf4
testb %al, %al
je 0x4766d
movb $0x1, %r12b
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
jmp 0x474a3
movb $0x1, %al
movq %rax, 0x48(%rsp)
cmpl $0x6, %r12d
jl 0x478e4
movq %r13, %rdi
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x48045
xorl %r12d, %r12d
jmp 0x478ed
xorl %r12d, %r12d
movb $0x1, %al
movl %eax, 0x30(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
testb $0x1, 0x44(%rsp)
je 0x47369
leaq 0xbb772(%rip), %rdi     # 0x103081
callq 0x4670
pushq $0x1
popq %rdi
callq 0x524c
leaq 0xbb744(%rip), %rax     # 0x103067
leaq 0xbb6fe(%rip), %rdi     # 0x103028
testb $0x1, %r12b
cmovneq %rax, %rdi
callq 0x4670
movq 0x20(%rsp), %rcx
leaq 0x3c0(%rcx), %r14
movq 0x3c8(%rcx), %rax
subq 0x3c0(%rcx), %rax
pushq $0x70
popq %rcx
cqto
idivq %rcx
movslq %eax, %r12
movb $0x1, %bpl
xorl %r15d, %r15d
pushq $0x18
popq %r13
cmpq %r12, %r15
jge 0x479a7
testb $0x1, %bpl
je 0x479a7
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b63c
movslq 0x18(%rax), %rbp
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b63c
movq 0x28(%rax), %rcx
subq 0x20(%rax), %rcx
movq %rcx, %rax
cqto
idivq %r13
cmpq %rbp, %rax
sete %bpl
incq %r15
jmp 0x47966
movq %rbx, %rdi
callq 0x4590
leaq 0x60(%rsp), %rdi
callq 0x244fc
andb $0x1, %bpl
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x479fb
jmp 0x479fb
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x4210
jmp 0x479ea
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x4210
jmp 0x479fe
jmp 0x479fb
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x244fc
movq %rbx, %rdi
callq 0x4780