// File: Luthaf[P]zeopp/networkio.cc
// Function: readCARFile(char*, ATOM_NETWORK*, bool)
bool readCARFile(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;
    getline(input, garbage); // skip the first comment line

    string PBCline;

    input >> PBCline; getline(input, garbage);
    if(PBCline.compare("PBC=ON") != 0)
      {
      cerr << "This .car file does not have a periodic structure. Exiting...\n";
      return false;
      };

    getline(input, garbage); // skipping two next lines
    getline(input, garbage);

    input >> garbage;
    input >> cell->a >> cell->b >> cell->c;
    input >> cell->alpha >> cell->beta >> cell->gamma;
    string SYMMline;
    input >> SYMMline;
    getline(input,garbage);

    if(SYMMline.compare("(P1)") !=0)
      {
      cerr << "The current .car reader does only work for (P1) symmetry.\n";
      return false;
      };

    cell->name = filename;
    cell->initialize();

    bool end=false;
    int na=0;
    while(!end)
      {
      string str1, str2, str3, str4;

      input >> str1;

      if(str1.compare("end") == 0 || str1.compare("END") == 0)
        {
        end = true;
        } else
        {
        ATOM newAtom;
        input >> newAtom.x >> newAtom.y >> newAtom.z;
        input >> str2 >> str3 >> str4;
        input >> newAtom.type >> newAtom.charge;

        if(!CAR_USE_ATOM_TYPE_OVER_NAME) newAtom.type = str1;

        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.radius = lookupRadius(newAtom.type, radial);
        cell->atoms.push_back(newAtom);
        na++;
        };

      };

    cell->numAtoms = na;
    cout << na << " atoms read." << endl;

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4d0, %rsp            # imm = 0x4D0
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5720
leaq -0x258(%rbp), %rdi
callq 0x5660
jmp 0x51fc1
movq -0x10(%rbp), %rax
movq %rax, -0x418(%rbp)
movl $0x8, %edi
movl $0x10, %esi
callq 0x47640
movl %eax, -0x40c(%rbp)
jmp 0x51fe3
movl -0x40c(%rbp), %edx
movq -0x418(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x54b0
jmp 0x51ffe
leaq -0x258(%rbp), %rdi
callq 0x58b0
movb %al, -0x419(%rbp)
jmp 0x52012
movb -0x419(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x526fa
movq 0x220f93(%rip), %rdi    # 0x272fc0
leaq 0x1a12f3(%rip), %rsi    # 0x1f3327
callq 0x5540
movq %rax, -0x428(%rbp)
jmp 0x52042
movq -0x428(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x430(%rbp)
jmp 0x5205b
movq -0x430(%rbp), %rdi
movq 0x220f2f(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x52070
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5110
jmp 0x52082
leaq -0x288(%rbp), %rdi
movq %rdi, -0x438(%rbp)
callq 0x5720
movq -0x438(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x56a0
jmp 0x520aa
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5110
jmp 0x520bc
leaq -0x288(%rbp), %rdi
leaq 0x1a132c(%rip), %rsi    # 0x1f33f6
callq 0x51b0
cmpl $0x0, %eax
je 0x52141
movq 0x220f15(%rip), %rdi    # 0x272ff0
leaq 0x1a131b(%rip), %rsi    # 0x1f33fd
callq 0x5540
jmp 0x520e9
movb $0x0, -0x1(%rbp)
movl $0x1, -0x28c(%rbp)
jmp 0x526bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x52791
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x52785
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x526e9
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5110
jmp 0x52153
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5110
jmp 0x52165
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x56a0
jmp 0x52177
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
leaq -0x258(%rbp), %rdi
callq 0x5420
movq %rax, -0x440(%rbp)
jmp 0x52194
movq -0x440(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
callq 0x5420
movq %rax, -0x448(%rbp)
jmp 0x521b1
movq -0x448(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
callq 0x5420
jmp 0x521c7
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
leaq -0x258(%rbp), %rdi
callq 0x5420
movq %rax, -0x450(%rbp)
jmp 0x521e4
movq -0x450(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x28, %rsi
callq 0x5420
movq %rax, -0x458(%rbp)
jmp 0x52201
movq -0x458(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x30, %rsi
callq 0x5420
jmp 0x52217
leaq -0x2b0(%rbp), %rdi
movq %rdi, -0x460(%rbp)
callq 0x5720
movq -0x460(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x56a0
jmp 0x5223f
leaq -0x258(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5110
jmp 0x52251
leaq -0x2b0(%rbp), %rdi
leaq 0x1a11dd(%rip), %rsi    # 0x1f343c
callq 0x51b0
cmpl $0x0, %eax
je 0x522a8
movq 0x220d80(%rip), %rdi    # 0x272ff0
leaq 0x1a11ca(%rip), %rsi    # 0x1f3441
callq 0x5540
jmp 0x5227e
movb $0x0, -0x1(%rbp)
movl $0x1, -0x28c(%rbp)
jmp 0x526b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x526dd
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdi
addq $0x320, %rdi            # imm = 0x320
callq 0x5710
jmp 0x522be
movq -0x18(%rbp), %rdi
callq 0x96250
jmp 0x522c9
movb $0x0, -0x2b1(%rbp)
movl $0x0, -0x2b8(%rbp)
movb -0x2b1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x522eb
jmp 0x5263f
leaq -0x2d8(%rbp), %rdi
movq %rdi, -0x468(%rbp)
callq 0x5720
leaq -0x2f8(%rbp), %rdi
callq 0x5720
leaq -0x318(%rbp), %rdi
callq 0x5720
leaq -0x338(%rbp), %rdi
callq 0x5720
movq -0x468(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x56a0
jmp 0x52337
leaq -0x2d8(%rbp), %rdi
leaq 0x1aadb0(%rip), %rsi    # 0x1fd0f5
callq 0x51b0
cmpl $0x0, %eax
je 0x52367
leaq -0x2d8(%rbp), %rdi
leaq 0x1a111f(%rip), %rsi    # 0x1f347c
callq 0x51b0
cmpl $0x0, %eax
jne 0x5238a
movb $0x1, -0x2b1(%rbp)
jmp 0x525d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x5260a
leaq -0x3d0(%rbp), %rdi
callq 0x954b0
jmp 0x52398
leaq -0x258(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x5420
movq %rax, -0x470(%rbp)
jmp 0x523b4
movq -0x470(%rbp), %rdi
leaq -0x3c8(%rbp), %rsi
callq 0x5420
movq %rax, -0x478(%rbp)
jmp 0x523d0
movq -0x478(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x5420
jmp 0x523e5
leaq -0x258(%rbp), %rdi
leaq -0x2f8(%rbp), %rsi
callq 0x56a0
movq %rax, -0x480(%rbp)
jmp 0x52401
movq -0x480(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x56a0
movq %rax, -0x488(%rbp)
jmp 0x5241d
movq -0x488(%rbp), %rdi
leaq -0x338(%rbp), %rsi
callq 0x56a0
jmp 0x52432
leaq -0x390(%rbp), %rsi
leaq -0x258(%rbp), %rdi
callq 0x56a0
movq %rax, -0x490(%rbp)
jmp 0x5244e
movq -0x490(%rbp), %rdi
leaq -0x348(%rbp), %rsi
callq 0x5420
jmp 0x52463
movq -0x18(%rbp), %rsi
movsd -0x3d0(%rbp), %xmm0
movsd -0x3c8(%rbp), %xmm1
movsd -0x3c0(%rbp), %xmm2
leaq -0x3e8(%rbp), %rdi
callq 0x97360
jmp 0x5248d
leaq -0x3e8(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x498(%rbp)
jmp 0x524a4
movq -0x498(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x3b8(%rbp)
leaq -0x3e8(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x4a0(%rbp)
jmp 0x524d1
movq -0x4a0(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x3b0(%rbp)
leaq -0x3e8(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x4a8(%rbp)
jmp 0x524fe
movq -0x4a8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x3a8(%rbp)
leaq -0x390(%rbp), %rsi
leaq -0x408(%rbp), %rdi
callq 0x5220
jmp 0x52526
movzbl -0x19(%rbp), %esi
andl $0x1, %esi
leaq -0x408(%rbp), %rdi
callq 0x466e0
movsd %xmm0, -0x4b0(%rbp)
jmp 0x52543
movsd -0x4b0(%rbp), %xmm0
movsd %xmm0, -0x3a0(%rbp)
leaq -0x408(%rbp), %rdi
callq 0x5300
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
leaq -0x3d0(%rbp), %rsi
callq 0xf190
jmp 0x52578
movl -0x2b8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b8(%rbp)
leaq -0x3d0(%rbp), %rdi
callq 0xf200
jmp 0x525d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
jmp 0x525c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x408(%rbp), %rdi
callq 0x5300
leaq -0x3d0(%rbp), %rdi
callq 0xf200
jmp 0x5260a
leaq -0x338(%rbp), %rdi
callq 0x5300
leaq -0x318(%rbp), %rdi
callq 0x5300
leaq -0x2f8(%rbp), %rdi
callq 0x5300
leaq -0x2d8(%rbp), %rdi
callq 0x5300
jmp 0x522da
leaq -0x338(%rbp), %rdi
callq 0x5300
leaq -0x318(%rbp), %rdi
callq 0x5300
leaq -0x2f8(%rbp), %rdi
callq 0x5300
leaq -0x2d8(%rbp), %rdi
callq 0x5300
jmp 0x526dd
movl -0x2b8(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x110(%rax)
movl -0x2b8(%rbp), %esi
movq 0x220964(%rip), %rdi    # 0x272fc0
callq 0x58d0
movq %rax, -0x4b8(%rbp)
jmp 0x5266a
movq -0x4b8(%rbp), %rdi
leaq 0x1a0cfb(%rip), %rsi    # 0x1f3373
callq 0x5540
movq %rax, -0x4c0(%rbp)
jmp 0x52686
movq -0x4c0(%rbp), %rdi
movq 0x220904(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x5269b
leaq -0x258(%rbp), %rdi
callq 0x50a0
jmp 0x526a9
movl $0x0, -0x28c(%rbp)
leaq -0x2b0(%rbp), %rdi
callq 0x5300
leaq -0x288(%rbp), %rdi
callq 0x5300
movl -0x28c(%rbp), %eax
testl %eax, %eax
jne 0x52762
jmp 0x526db
jmp 0x52754
leaq -0x2b0(%rbp), %rdi
callq 0x5300
leaq -0x288(%rbp), %rdi
callq 0x5300
jmp 0x52785
movq 0x2208ef(%rip), %rdi    # 0x272ff0
leaq 0x1a0d78(%rip), %rsi    # 0x1f3480
callq 0x5540
movq %rax, -0x4c8(%rbp)
jmp 0x52716
movq -0x4c8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x4d0(%rbp)
jmp 0x5272f
movq -0x4d0(%rbp), %rdi
movq 0x22085b(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x52744
movb $0x0, -0x1(%rbp)
movl $0x1, -0x28c(%rbp)
jmp 0x52762
movb $0x1, -0x1(%rbp)
movl $0x1, -0x28c(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x5150
leaq -0x40(%rbp), %rdi
callq 0x5300
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbp
retq
leaq -0x258(%rbp), %rdi
callq 0x5150
leaq -0x40(%rbp), %rdi
callq 0x5300
movq -0x260(%rbp), %rdi
callq 0x58f0
nopw %cs:(%rax,%rax)