// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkio.cc
// Function: readCSSRFile(char*, ATOM_NETWORK*, bool)
bool readCSSRFile(char *filename, ATOM_NETWORK *cell, bool radial){
  string garbage; //this is a garbage string to read line
  int i,j;

  fstream input;
  input.open(filename);
  if(input.is_open()==true){
    // Read the header information
    cout << "Reading input file: " << filename << endl;
    input.ignore(38);
    input >> cell->a >> cell->b >> cell->c;
    getline(input,garbage);

    input.ignore(21);
    input >> cell->alpha >> cell->beta >> cell->gamma;
    getline(input,garbage);

    string numStr;
    bool longCSSR=false;  // this flag wiill enable switching to a different read routine
                          // to handle files with number of atoms larger than 10000
    bool CartCoords=false; // this flag enables reading Cartesian coordinates

    input >> numStr >> CartCoords;
    getline(input,garbage);
//    input >> cell->numAtoms;
    if(numStr.compare("****") == 0) longCSSR=true;

//    input >> i >> cell->name;  // some files have '0' preceeding name
//    getline(input,garbage);
    getline(input,cell->name);
    cell->initialize();

    if(longCSSR == false){
      cell->numAtoms = atoi(numStr.c_str());

      // Read and store information about each atom
      for(j=0;j<cell->numAtoms;j++) {
        ATOM newAtom;

        if(CartCoords==false) {
           input >> newAtom.specialID >> newAtom.type >> newAtom.a_coord >> newAtom.b_coord >>newAtom.c_coord;
           newAtom.a_coord = trans_to_origuc(newAtom.a_coord);
           newAtom.b_coord = trans_to_origuc(newAtom.b_coord);
           newAtom.c_coord = trans_to_origuc(newAtom.c_coord);
           Point newCoords=cell->abc_to_xyz(newAtom.a_coord,newAtom.b_coord,newAtom.c_coord);
           newAtom.x=newCoords[0]; newAtom.y=newCoords[1]; newAtom.z=newCoords[2];}
         else{ // read-in cartesian
           input >> newAtom.specialID >> newAtom.type >> newAtom.x >> newAtom.y >> newAtom.z;
           Point newCoords=cell->xyz_to_abc(newAtom.x,newAtom.y,newAtom.z);
           newAtom.a_coord=newCoords[0]; newAtom.b_coord=newCoords[1]; newAtom.c_coord=newCoords[2];
           newAtom.a_coord = trans_to_origuc(newAtom.a_coord);
           newAtom.b_coord = trans_to_origuc(newAtom.b_coord);
           newAtom.c_coord = trans_to_origuc(newAtom.c_coord);
           newCoords=cell->abc_to_xyz(newAtom.a_coord,newAtom.b_coord,newAtom.c_coord);
           newAtom.x=newCoords[0]; newAtom.y=newCoords[1]; newAtom.z=newCoords[2];
           };

        newAtom.radius=lookupRadius(newAtom.type, radial);
        cell->atoms.push_back(newAtom);
//        getline(input,garbage);
        //read these numbers after the coords, since the final field contains charge information
        int empty_int = 0;
        for(int k=0; k<8; k++) input >> empty_int;
        input >> newAtom.charge;
        }
      }
    else{ // start longCSSR=true
      cout << "Long CSSR file. Switching to another reading routine.\n" ;
      int na=1;
      while(!input.eof())
        {
        ATOM newAtom;
        newAtom.specialID = na;
        input >> garbage;
        if(input.eof())
          {
          na--;
          break;
          };
        if(CartCoords==false) {
          input >> newAtom.type >> newAtom.a_coord >> newAtom.b_coord >>newAtom.c_coord;
          newAtom.a_coord = trans_to_origuc(newAtom.a_coord);
          newAtom.b_coord = trans_to_origuc(newAtom.b_coord);
          newAtom.c_coord = trans_to_origuc(newAtom.c_coord);
          Point newCoords=cell->abc_to_xyz(newAtom.a_coord,newAtom.b_coord,newAtom.c_coord);
          newAtom.x=newCoords[0]; newAtom.y=newCoords[1]; newAtom.z=newCoords[2];}
        else{  // input in cartesian
          input >> newAtom.type >> newAtom.x >> newAtom.y >> newAtom.z;
          Point newCoords=cell->xyz_to_abc(newAtom.x,newAtom.y,newAtom.z);
          newAtom.a_coord=newCoords[0]; newAtom.b_coord=newCoords[1]; newAtom.c_coord=newCoords[2];
          newAtom.a_coord = trans_to_origuc(newAtom.a_coord);
          newAtom.b_coord = trans_to_origuc(newAtom.b_coord);
          newAtom.c_coord = trans_to_origuc(newAtom.c_coord);
          newCoords=cell->abc_to_xyz(newAtom.a_coord,newAtom.b_coord,newAtom.c_coord);
          newAtom.x=newCoords[0]; newAtom.y=newCoords[1]; newAtom.z=newCoords[2];
          };

        newAtom.radius=lookupRadius(newAtom.type, radial);
        //read these numbers after the coords, since the final field contains charge information
        int empty_int = 0;
        for(int k=0; k<8; k++) input >> empty_int;
        input >> newAtom.charge;
        cell->atoms.push_back(newAtom);
//        cout << na << "  " << newAtom.type << " " << newAtom.a_coord << "  " << newAtom.b_coord << "  " << newAtom.c_coord << endl;
        na++;
        };
      cell->numAtoms = na;
      cout << na << " atoms read." << endl;
    };// end longCSSR=true

    input.close();
  }
  else{
    cerr << "Error: CSSR failed to open " << filename << endl;
//    abort();
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x388, %rsp            # imm = 0x388
movl %edx, %ebx
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
leaq 0x108(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x178(%rsp), %rdi
callq 0x4540
leaq 0x178(%rsp), %rdi
pushq $0x18
popq %rdx
movq %r15, %rsi
callq 0x4410
leaq 0x1f8(%rsp), %rdi
callq 0x4130
movb %al, 0x1b(%rsp)
testb %al, %al
je 0x1f3dd
movq 0x131055(%rip), %rdi    # 0x14ffc0
leaq 0xde1dc(%rip), %rsi     # 0xfd14e
callq 0x4480
movq %rax, %rdi
movq %r15, %rsi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0x178(%rsp), %rdi
pushq $0x26
popq %rsi
callq 0x4070
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %rsi
leaq 0x178(%rsp), %rdi
callq 0x42d0
movq 0x10(%rsp), %rcx
leaq 0x10(%rcx), %rsi
movq %rax, %rdi
callq 0x42d0
movq 0x10(%rsp), %rcx
leaq 0x18(%rcx), %rsi
movq %rax, %rdi
callq 0x42d0
leaq 0x178(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x40e0
leaq 0x178(%rsp), %rdi
pushq $0x15
popq %rsi
callq 0x4070
movq 0x10(%rsp), %rax
leaq 0x20(%rax), %rsi
leaq 0x178(%rsp), %rdi
callq 0x42d0
movq 0x10(%rsp), %rcx
leaq 0x28(%rcx), %rsi
movq %rax, %rdi
callq 0x42d0
movq 0x10(%rsp), %rcx
leaq 0x30(%rcx), %rsi
movq %rax, %rdi
callq 0x42d0
leaq 0x178(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x40e0
leaq 0x128(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
movb %cl, 0xf(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x4580
leaq 0xf(%rsp), %rsi
movq %rax, %rdi
callq 0x43d0
leaq 0x178(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x40e0
leaq 0xde3e9(%rip), %rsi     # 0xfd484
leaq 0x118(%rsp), %rdi
callq 0x4190
movl %eax, %ebp
movq 0x10(%rsp), %rax
leaq 0x320(%rax), %rsi
leaq 0x178(%rsp), %rdi
callq 0x40e0
movq 0x10(%rsp), %rdi
callq 0x3e5a4
movzbl %bl, %eax
movl %eax, 0x1c(%rsp)
testl %ebp, %ebp
je 0x1f408
movq 0x118(%rsp), %rdi
callq 0x4680
movq 0x10(%rsp), %rcx
movl %eax, 0x110(%rcx)
addq $0x2f0, %rcx            # imm = 0x2F0
movq %rcx, 0xb8(%rsp)
xorl %r13d, %r13d
leaq 0x20(%rsp), %r15
leaq 0x178(%rsp), %rbx
leaq 0xc0(%rsp), %rbp
leaq 0x158(%rsp), %r12
cmpl %eax, %r13d
jge 0x1f769
movq %r15, %rdi
callq 0x3dc5a
cmpb $0x0, 0xf(%rsp)
je 0x1f28b
movq %rbx, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x60(%rsp), %rsi
callq 0x4580
movq %rax, %rdi
movq %r15, %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x28(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x42d0
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0x3f1ce
movq %rbp, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x6377f
movaps %xmm0, %xmm2
movsd %xmm0, 0x48(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
leaq 0xe0(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3f0e6
movq 0xf0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movups 0xe0(%rsp), %xmm0
movaps %xmm0, 0xc0(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
jmp 0x1f352
movq %rbx, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x42a0
movq %rax, %rdi
leaq 0x60(%rsp), %rsi
callq 0x4580
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x48(%rsp), %rsi
callq 0x42d0
movsd 0x38(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x6377f
movaps %xmm0, %xmm2
movsd %xmm0, 0x48(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0x3f0e6
movq %rbp, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0x45d0
movq %r12, %rdi
movl 0x1c(%rsp), %esi
callq 0x1b1bb
movsd %xmm0, 0x50(%rsp)
movq %r12, %rdi
callq 0x4210
movq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0xa7d8
andl $0x0, 0xc0(%rsp)
pushq $0x8
popq %r14
subl $0x1, %r14d
jb 0x1f3b2
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x42a0
jmp 0x1f39f
movq %rbx, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x42d0
movq %r15, %rdi
callq 0xa808
incl %r13d
movq 0x10(%rsp), %rax
movl 0x110(%rax), %eax
jmp 0x1f123
movq 0x130c0c(%rip), %rdi    # 0x14fff0
leaq 0xdddbc(%rip), %rsi     # 0xfd1a7
callq 0x4480
movq %rax, %rdi
movq %r15, %rsi
callq 0x4480
movq %rax, %rdi
callq 0x4230
jmp 0x1f783
movq 0x130bb1(%rip), %rdi    # 0x14ffc0
leaq 0xddd4d(%rip), %rsi     # 0xfd163
callq 0x4480
pushq $0x1
popq %r15
movq 0x10(%rsp), %rax
addq $0x2f0, %rax            # imm = 0x2F0
movq %rax, 0xb8(%rsp)
leaq 0x178(%rsp), %r12
leaq 0xc0(%rsp), %rbx
leaq 0x138(%rsp), %r13
movq 0x178(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x198(%rsp,%rax)
jne 0x1f737
leaq 0x20(%rsp), %rdi
callq 0x3dc5a
movl %r15d, 0xa0(%rsp)
movq %r12, %rdi
leaq 0xf8(%rsp), %rsi
callq 0x4580
movq 0x178(%rsp), %rax
movq -0x18(%rax), %rax
movl 0x198(%rsp,%rax), %ebp
testb $0x2, %bpl
jne 0x1f5ec
cmpb $0x0, 0xf(%rsp)
je 0x1f5f4
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0x4580
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x28(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x42d0
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x3f1ce
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x6377f
movaps %xmm0, %xmm2
movsd %xmm0, 0x48(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
leaq 0xe0(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3f0e6
movq 0xf0(%rsp), %rax
movq %rax, 0xd0(%rsp)
movups 0xe0(%rsp), %xmm0
movaps %xmm0, 0xc0(%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
jmp 0x1f6ab
decl %r15d
jmp 0x1f723
movq %r12, %rdi
leaq 0x60(%rsp), %rsi
callq 0x4580
movq %rax, %rdi
leaq 0x38(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x42d0
movq %rax, %rdi
leaq 0x48(%rsp), %rsi
callq 0x42d0
movsd 0x38(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x6377f
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x6377f
movaps %xmm0, %xmm2
movsd %xmm0, 0x48(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x3f0e6
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
callq 0x45d0
movq %r13, %r14
movq %r13, %rdi
movl 0x1c(%rsp), %esi
callq 0x1b1bb
movsd %xmm0, 0x50(%rsp)
movq %r14, %rdi
callq 0x4210
andl $0x0, 0xc0(%rsp)
pushq $0x8
popq %r14
subl $0x1, %r14d
jb 0x1f6fe
movq %r12, %rdi
movq %rbx, %rsi
callq 0x42a0
jmp 0x1f6eb
movq %r12, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x42d0
movq 0xb8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xa7d8
incl %r15d
leaq 0x20(%rsp), %rdi
callq 0xa808
testb $0x2, %bpl
je 0x1f44a
movq 0x10(%rsp), %rax
movl %r15d, 0x110(%rax)
movq 0x130876(%rip), %rdi    # 0x14ffc0
movl %r15d, %esi
callq 0x4760
leaq 0xdda41(%rip), %rsi     # 0xfd19a
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0x178(%rsp), %rdi
callq 0x4080
leaq 0x118(%rsp), %rdi
callq 0x4210
leaq 0x178(%rsp), %rdi
callq 0x4120
leaq 0xf8(%rsp), %rdi
callq 0x4210
movb 0x1b(%rsp), %al
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f7dc
jmp 0x1f7fd
movq %rax, %rbx
jmp 0x1f824
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x1f7ec
jmp 0x1f7fd
jmp 0x1f7fd
jmp 0x1f7dc
jmp 0x1f7dc
jmp 0x1f7fd
movq %rax, %rbx
jmp 0x1f817
jmp 0x1f7fd
jmp 0x1f7fd
movq %rax, %rbx
jmp 0x1f80a
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x4210
jmp 0x1f800
jmp 0x1f7fd
jmp 0x1f7fd
jmp 0x1f7fd
jmp 0x1f7fd
jmp 0x1f7fd
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xa808
leaq 0x118(%rsp), %rdi
callq 0x4210
leaq 0x178(%rsp), %rdi
callq 0x4120
leaq 0xf8(%rsp), %rdi
callq 0x4210
movq %rbx, %rdi
callq 0x4780