// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/networkstorage.cc
// Function: read_xyz(_IO_FILE*, MOLECULE*, char const*)
void read_xyz(FILE *input, MOLECULE *mol, const char *filename) {
  int length = 100;
  char ch1[length];
  int status = 0;
  int num_atoms = 0;
  if(fgets(ch1, length, input)!=NULL) {
    string str = string(ch1);
//    printf("DEBUG: read char array as \"%s\", parsed to string as \"%s\"\n", ch, str.c_str());
    int pos=0;
    char c = str[pos];

//@@@ WARNING - there is a memory leak here and I cannot tell why

    while(c<=0) { //for some reason, xyz files from marvinsketch have three characters at the beginning with ascii codes <0 - very strange, but we need to remove these to succesfully parse any data
      pos++;
      c = str[pos];
    }
    char ch2[length];
    str.copy(ch2, str.size()-pos, pos);
    status = sscanf(ch2, "%d", &num_atoms);
    //printf("DEBUG: parsed num_atoms = %d from string %s (status = %d)\n", num_atoms, ch2, status);
  } else {
    printf("ERROR: could not read string\n");
    exit(EXIT_FAILURE);
  }
  //printf("(status = %d) DEBUG: read that there will be %d atoms\n", status, num_atoms);
  search_for_char(input, '\n'); //now we are on a line containing an atom
  for(int i=0; i<num_atoms; i++) {
    XYZ a;
    char e[length];
    char ch[length];
    if(fgets(ch, length, input)!=NULL) {
      string str = string(ch);
      //printf("DEBUG: read char array as \"%s\", parsed to string as \"%s\"\n", ch, str.c_str());
      int pos=0;
      char c = str[pos];
      while(c<=0) { //for some reason, xyz files from marvinsketch have three characters at the beginning with ascii codes <0 - very strange, but we need to remove these to succesfully parse any data
        pos++;
        c = str[pos];
      }
      char ch2[length];
      str.copy(ch2, str.size()-pos, pos);
      status = sscanf(ch2, "%s %lf %lf %lf", e, &a.x, &a.y, &a.z);
    } else {
      printf("ERROR: could not read expected atom coord string from %s - %d out of %d atom coords were read\n", filename, i, num_atoms);
      exit(EXIT_FAILURE);
    }

    mol->atoms_xyz.push_back(a);
    string name_string(e);
    mol->atoms_label.push_back(name_string);
    //parse out any digits from the name of the element
    int name_length = name_string.length();
    int digit_pos = -1;
    for(int i=0; i<name_length && digit_pos==-1; i++) {
      if(isdigit(name_string[i])) digit_pos = i;
    }
    if(digit_pos==0) { //first character was a digit - this is no good
      printf("ERROR: could not parse label from atom beginning with a digit in read_xyz: %s: %s\n", filename, name_string.c_str());
      exit(EXIT_FAILURE);
    } else {
      string element(e);
      if(digit_pos>0) {
        element = name_string.substr(0,digit_pos);
      }
      mol->atoms_type.push_back(element);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, %r15
movq %rsi, -0x60(%rbp)
movq %rdi, %rdx
movl $0x0, -0x2c(%rbp)
leaq -0x140(%rbp), %rdi
movl $0x64, %esi
movq %rdx, -0x68(%rbp)
callq 0x4690
testq %rax, %rax
je 0x676db
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x140(%rbp), %rbx
movq %rbx, %rdi
callq 0x41e0
leaq (%rax,%rbp), %rdx
addq $-0x140, %rdx           # imm = 0xFEC0
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x2263c
movq -0x50(%rbp), %rax
cmpb $0x0, (%rax)
jle 0x6737f
xorl %ecx, %ecx
jmp 0x6738e
xorl %ecx, %ecx
cmpb $0x0, 0x1(%rax,%rcx)
leaq 0x1(%rcx), %rcx
jle 0x67381
movl %ecx, %ecx
movq %rsp, %r14
movq %rsp, %rbx
addq $-0x70, %rbx
movq %rbx, %rsp
leaq -0x50(%rbp), %rdi
movq 0x8(%rdi), %rdx
subq %rcx, %rdx
movq %rbx, %rsi
callq 0x40b0
movq %r15, -0x58(%rbp)
leaq 0xf90f2(%rip), %rsi     # 0x1604ab
leaq -0x2c(%rbp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x4430
movq %r14, %rsp
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x673e3
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x4470
movq -0x68(%rbp), %rdi
movl $0xa, %esi
callq 0xa322a
cmpl $0x0, -0x2c(%rbp)
movq -0x60(%rbp), %rax
jle 0x67692
leaq 0x30(%rax), %rcx
movq %rcx, -0xb0(%rbp)
addq $0x18, %rax
movq %rax, -0xa8(%rbp)
leaq -0x50(%rbp), %rbx
leaq -0xd8(%rbp), %r14
xorl %r13d, %r13d
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
leaq -0xa0(%rbp), %rdi
callq 0x85982
movq %rsp, -0xb8(%rbp)
movq %rsp, %r15
addq $-0x70, %r15
movq %r15, %rsp
movq %rsp, %r12
addq $-0x70, %r12
movq %r12, %rsp
movq %r12, %rdi
movl $0x64, %esi
movq -0x68(%rbp), %rdx
callq 0x4690
testq %rax, %rax
je 0x676a1
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq %r12, %rdi
callq 0x41e0
leaq (%rax,%r12), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2263c
movq -0x50(%rbp), %rax
cmpb $0x0, (%rax)
jle 0x67499
xorl %ecx, %ecx
jmp 0x674a8
xorl %ecx, %ecx
cmpb $0x0, 0x1(%rax,%rcx)
leaq 0x1(%rcx), %rcx
jle 0x6749b
movl %ecx, %ecx
movq %rsp, %rbx
movq %rsp, %r12
addq $-0x70, %r12
movq %r12, %rsp
movq -0x48(%rbp), %rdx
subq %rcx, %rdx
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x40b0
movq %r12, %rdi
leaq 0xee8b5(%rip), %rsi     # 0x155d87
movq %r15, %rdx
leaq -0xa0(%rbp), %rcx
leaq -0x98(%rbp), %r8
leaq -0x90(%rbp), %r9
xorl %eax, %eax
callq 0x4430
movq %rbx, %rsp
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6750d
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x4470
movq -0x60(%rbp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
leaq -0x50(%rbp), %rbx
je 0x6753b
movq -0x90(%rbp), %rax
movq %rax, 0x10(%rsi)
movups -0xa0(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x8(%rdi)
jmp 0x67547
leaq -0xa0(%rbp), %rdx
callq 0x6a5be
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq %r15, %rdi
callq 0x41e0
leaq (%rax,%r15), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2263c
movq -0xb0(%rbp), %rdi
movq %rbx, %rsi
callq 0x2f74c
movq -0x48(%rbp), %rax
testl %eax, %eax
jle 0x675bb
movq -0x50(%rbp), %rcx
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0x1, %edx
movsbl -0x1(%rcx,%rdx), %esi
addl $-0x3a, %esi
incl %r12d
cmpl $-0xb, %esi
ja 0x675ad
leaq 0x1(%rdx), %rdi
cmpq %rax, %rdx
movq %rdi, %rdx
jb 0x67591
cmpl $-0xa, %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovbl %eax, %r12d
jmp 0x675c1
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testl %r12d, %r12d
je 0x676bb
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq %r15, %rdi
callq 0x41e0
leaq (%rax,%r15), %rdx
leaq -0x88(%rbp), %rdi
movq %r15, %rsi
callq 0x2263c
testl %r12d, %r12d
jle 0x67636
movl %r12d, %ecx
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4490
leaq -0x88(%rbp), %rdi
movq %r14, %rsi
callq 0x4540
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x67636
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x4470
movq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x2f74c
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x67665
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x4470
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6767e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x4470
movq -0xb8(%rbp), %rsp
incl %r13d
cmpl -0x2c(%rbp), %r13d
jl 0x67423
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x2c(%rbp), %ecx
leaq 0xee6eb(%rip), %rdi     # 0x155d96
movq -0x58(%rbp), %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x4060
jmp 0x676d1
movq -0x50(%rbp), %rdx
leaq 0xee72f(%rip), %rdi     # 0x155df5
movq -0x58(%rbp), %rsi
xorl %eax, %eax
callq 0x4060
movl $0x1, %edi
callq 0x710c
leaq 0xeeadd(%rip), %rdi     # 0x1561bf
callq 0x4660
jmp 0x676d1
jmp 0x676fa
jmp 0x676f3
jmp 0x676ff
jmp 0x676f3
jmp 0x676fa
movq %rax, %rbx
jmp 0x67737
jmp 0x676fa
movq %rax, %rbx
jmp 0x6771e
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x6771e
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x4470
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x67737
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780
nop