// File: /workspace/github_cpp_makefile_star2_O1/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 $0xf8, %rsp
movq %rdx, 0x70(%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, 0x5c(%rsp)
movl %eax, 0x34(%rsp)
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %r13, %rdx
callq 0x4690
testq %rax, %rax
je 0x618fe
movq %r14, 0x38(%rsp)
leaq 0xb0(%rsp), %r15
movq $0x0, 0x68(%rsp)
xorl %ebp, %ebp
movq $0x0, 0x78(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x58(%rsp)
movq $0x0, 0x60(%rsp)
incl 0x5c(%rsp)
movq %r15, 0xa0(%rsp)
movq %rbx, %rdi
callq 0x41e0
leaq (%rax,%rbx), %rdx
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x2263c
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x80(%rsp), %r14
movq %r14, %rdi
leaq 0xf424c(%rip), %rsi     # 0x155529
leaq 0xf424b(%rip), %rdx     # 0x15552f
callq 0x2263c
leaq 0xe0(%rsp), %r12
movq %r12, %rdi
leaq 0xa0(%rsp), %rsi
movq %r14, %rdx
callq 0x4a6d4
xorps %xmm0, %xmm0
movaps %xmm0, 0xc0(%rsp)
movaps 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rax
movups 0xe0(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0xf0(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movaps 0xc0(%rsp), %xmm1
movaps %xmm0, 0xc0(%rsp)
movq %rax, 0xd0(%rsp)
movups %xmm1, 0xe0(%rsp)
movq $0x0, 0xf0(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x2f6f0
movq %r12, %rdi
callq 0x2f6f0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x61399
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xa0(%rsp), %rdi
movq %r15, %r14
cmpq %r15, %rdi
je 0x613b9
movq 0xb0(%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 0x614c2
cmpq %rdi, %rax
je 0x619f7
leaq 0xf2c04(%rip), %rsi     # 0x153fea
callq 0x4170
testl %eax, %eax
je 0x61488
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf4126(%rip), %rsi     # 0x155530
callq 0x4170
testl %eax, %eax
je 0x61488
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xee8f2(%rip), %rsi     # 0x14fd1c
callq 0x4170
testl %eax, %eax
je 0x61488
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf40eb(%rip), %rsi     # 0x155535
callq 0x4170
testl %eax, %eax
je 0x61488
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
testb $0x1, 0x58(%rsp)
je 0x614ff
cmpq %rsi, %rax
je 0x619d2
movq 0x70(%rsp), %rdi
callq 0x4240
movq %r14, %r15
movl $0x0, 0x58(%rsp)
jmp 0x614c5
cmpl $0x2, %r15d
jl 0x614bc
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %r15
subq %rsi, %r15
sarq $0x5, %r15
cmpq $0x2, %r15
jb 0x619ed
addq $0x20, %rsi
movq 0x70(%rsp), %rdi
callq 0x4240
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movl %eax, 0x58(%rsp)
movq %r14, %r15
testb $0x1, 0x60(%rsp)
je 0x614d7
testb $0x1, 0x78(%rsp)
jne 0x619d7
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
movq %r13, %rdx
callq 0x4690
testq %rax, %rax
je 0x618e1
testb $0x1, %bpl
je 0x61293
jmp 0x618e1
cmpq %rsi, %rax
je 0x619d2
movq %rsi, %rdi
leaq 0xf2d34(%rip), %rsi     # 0x154246
callq 0x4170
testl %eax, %eax
je 0x61570
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf4006(%rip), %rsi     # 0x155538
callq 0x4170
testl %eax, %eax
je 0x61570
movl 0x54(%rsp), %eax
notb %al
cmpl $0x6, %r15d
setl %cl
orb %al, %cl
testb $0x1, %cl
jne 0x6159d
movl $0x0, 0x54(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x61a74
movq %r14, %r15
jmp 0x614c5
cmpl $0x7, %r15d
jl 0x61592
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x38(%rsp), %rdx
callq 0x61a74
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movl %eax, 0x54(%rsp)
jmp 0x614c2
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf3f89(%rip), %rsi     # 0x15553d
callq 0x4170
testl %eax, %eax
je 0x61605
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf3f6f(%rip), %rsi     # 0x155543
callq 0x4170
testl %eax, %eax
je 0x61605
testb $0x1, 0x50(%rsp)
je 0x61632
movl $0x0, 0x50(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x61c03
movq %r14, %r15
jmp 0x614c5
cmpl $0x2, %r15d
jl 0x61627
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x38(%rsp), %rdx
callq 0x61c03
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movl %eax, 0x50(%rsp)
jmp 0x614c2
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf7c02(%rip), %rsi     # 0x15924b
callq 0x4170
testl %eax, %eax
je 0x616b8
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf3ee0(%rip), %rsi     # 0x155549
callq 0x4170
testl %eax, %eax
je 0x616b8
movl 0x4c(%rsp), %eax
notb %al
cmpl $0x5, %r15d
setl %cl
orb %al, %cl
testb $0x1, %cl
jne 0x616fd
movl $0x0, 0x4c(%rsp)
movq %r13, (%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
leaq 0x34(%rsp), %rcx
leaq 0x5c(%rsp), %r8
movq %rbx, %r9
callq 0x61d1a
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movq %rax, 0x78(%rsp)
cmpl $0x6, %r15d
jl 0x616f2
movq %r13, (%rsp)
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x38(%rsp), %rdx
leaq 0x34(%rsp), %rcx
leaq 0x5c(%rsp), %r8
movq %rbx, %r9
callq 0x61d1a
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movl %eax, 0x4c(%rsp)
jmp 0x614c2
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf6d9d(%rip), %rsi     # 0x1584b1
callq 0x4170
testl %eax, %eax
je 0x61777
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf6a55(%rip), %rsi     # 0x158189
callq 0x4170
testl %eax, %eax
je 0x61777
cmpl $0x5, %r15d
setl %al
movl 0x48(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x617b0
movl $0x0, 0x48(%rsp)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
leaq 0x34(%rsp), %rcx
callq 0x62494
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movq %rax, 0x60(%rsp)
cmpl $0x6, %r15d
jl 0x617a5
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x38(%rsp), %rdx
leaq 0x34(%rsp), %rcx
callq 0x62494
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movl %eax, 0x48(%rsp)
jmp 0x614c2
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xfed45(%rip), %rsi     # 0x16050c
callq 0x4170
testl %eax, %eax
je 0x61833
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf3e2f(%rip), %rsi     # 0x155616
callq 0x4170
testl %eax, %eax
je 0x61833
cmpl $0x6, %r15d
setl %al
movl 0x44(%rsp), %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x6186e
movl 0x34(%rsp), %ecx
movl $0x0, 0x44(%rsp)
movzbl 0x60(%rsp), %r8d
andl $0x1, %r8d
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x6268d
movq %r14, %r15
jmp 0x614c5
cmpl $0x7, %r15d
jl 0x61863
movl 0x34(%rsp), %ecx
movzbl 0x60(%rsp), %r8d
andl $0x1, %r8d
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movq 0x38(%rsp), %rdx
callq 0x6268d
movq %r14, %r15
jmp 0x614c5
movb $0x1, %al
movl %eax, 0x44(%rsp)
jmp 0x614c2
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
movq %r14, %r15
leaq 0xf1b76(%rip), %rsi     # 0x1533fe
callq 0x4170
testl %eax, %eax
je 0x614c5
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xf6aa0(%rip), %rsi     # 0x15834c
callq 0x4170
testl %eax, %eax
je 0x618d9
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x619d2
leaq 0xee967(%rip), %rsi     # 0x150233
callq 0x4170
testl %eax, %eax
jne 0x614c5
movb $0x1, %bpl
jmp 0x614c5
leaq 0xf472f(%rip), %rax     # 0x156017
leaq 0xf46e9(%rip), %rdi     # 0x155fd8
testb $0x1, %bpl
cmovneq %rax, %rdi
movq 0x38(%rsp), %r14
jmp 0x61905
leaq 0xf46d3(%rip), %rdi     # 0x155fd8
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 0x61994
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rdx, %rsi
negq %rsi
addq $0x28, %rax
movb $0x1, %bpl
movl $0x1, %edi
movabsq $-0x5555555555555555, %r8 # imm = 0xAAAAAAAAAAAAAAAB
xorl %r9d, %r9d
leaq (%rsi,%rdi), %r10
cmpq $0x1, %r10
je 0x619c1
movq (%rax), %r10
subq -0x8(%rax), %r10
movslq -0x10(%rax), %r11
sarq $0x3, %r10
imulq %r8, %r10
cmpq %r11, %r10
movzbl %bpl, %ebp
cmovnel %r9d, %ebp
cmpq %rcx, %rdi
jae 0x61997
incq %rdi
addq $0x70, %rax
testb $0x1, %bpl
jne 0x61958
jmp 0x61997
movb $0x1, %bpl
movq %rbx, %rdi
callq 0x4570
leaq 0x10(%rsp), %rdi
callq 0x2f6f0
andb $0x1, %bpl
movl %ebp, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xedcdd(%rip), %rdi     # 0x14f6a5
movq %rdx, %rsi
xorl %eax, %eax
callq 0x4630
xorl %r15d, %r15d
jmp 0x619f7
leaq 0xf4653(%rip), %rdi     # 0x156031
callq 0x4660
movl $0x1, %edi
callq 0x710c
movl $0x1, %eax
movq %rax, 0x68(%rsp)
leaq 0xedca7(%rip), %rdi     # 0x14f6a5
movq 0x68(%rsp), %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x4630
jmp 0x61a5f
jmp 0x61a5f
movq %rax, %rbx
jmp 0x61a3e
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x61a3e
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x61a62
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x61a62
jmp 0x61a5f
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2f6f0
movq %rbx, %rdi
callq 0x4780