// File: /workspace/github_cpp_makefile_star2_O2/princelab[P]emass/emass.cpp
// Function: init_data(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<std::vector<std::vector<peak, std::allocator<peak>>, std::allocator<std::vector<peak, std::allocator<peak>>>>, std::allocator<std::vector<std::vector<peak, std::allocator<peak>>, std::allocator<std::vector<peak, std::allocator<peak>>>>>>&, std::map<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, unsigned long, std::less<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>>, std::allocator<std::pair<std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>> const, unsigned long>>>&)
int init_data(string filename, SuperAtomData & sad, ElemMap & em)
{
  wifstream f(filename.c_str());
  
  if(f.fail())
    return 0;

  sad.clear();
  em.clear();

  wstring line;
  ulong elemindex = 0;
  int state = 0;
  while(getline(f, line)) {
    wistringstream ist(line);
    wstring element;
    switch(state) {
    case 0: // new element
      ist >> element;
      em[element] = elemindex;
      sad.push_back(SuperAtomList(1));
      sad.back().reserve(8); // reserve room for 8 superatoms
      elemindex++;
      state = 1;
      break;
    case 1: // isotope
      peak p;
      Pattern & idist = sad.back()[0];
      if(ist >> p.mass >> p.rel_area) {
	// fill the gaps in the patterns with zero abundancy peaks
	if(idist.size() > 0) {
	  double prevmass = idist.back().mass;
	  for(int i = 0; i < int(p.mass - prevmass - 0.5); i++) {
	    peak filler;
	    filler.mass = DUMMY_MASS;
	    filler.rel_area = 0;
	    idist.push_back(filler);
	  }
	}
	// insert the peak
	idist.push_back(p);                                                        
      } else  
	state = 0; // no more isotope data
      break;
    }
  }  
  f.close();
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
movq %rdx, %r15
movq %rsi, %r14
movq (%rdi), %rsi
leaq 0x80(%rsp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x31e0
movq (%rbx), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x5, 0xa0(%rsp,%rax)
jne 0x38d1
movq %r14, %rdi
callq 0x4294
movq %r15, 0x8(%rsp)
movq %r15, %rdi
callq 0x4700
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
andl $0x0, (%rax)
movq $0x0, (%rsp)
leaq 0x60(%rsp), %rbx
leaq 0x288(%rsp), %rbp
leaq 0x40(%rsp), %r15
xorl %r13d, %r13d
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x3290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x38b7
movq %rbp, %rdi
movq %rbx, %rsi
pushq $0x8
popq %rdx
callq 0x3300
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
andq $0x0, 0x48(%rsp)
andl $0x0, 0x50(%rsp)
testl %r13d, %r13d
je 0x382a
movq %rbp, %rdi
movq %r15, %r12
movq %rbx, %r15
movq 0x8(%r14), %rax
movq -0x18(%rax), %rbx
leaq 0x18(%rsp), %rsi
callq 0x31a0
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x31a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
xorl %r13d, %r13d
testb $0x5, 0x20(%rax,%rcx)
jne 0x389c
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
je 0x388b
movsd -0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r13d, %r13d
movsd 0x18(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
addsd 0x380b(%rip), %xmm0     # 0x7008
cvttsd2si %xmm0, %eax
cmpl %eax, %r13d
jge 0x388b
movsd 0x37fe(%rip), %xmm0     # 0x7010
movapd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4418
incl %r13d
jmp 0x37e9
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3140
leaq 0x18(%rsp), %r12
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x429c
movq (%rsp), %rcx
movq %rcx, (%rax)
movq %r12, %rdi
pushq $0x1
popq %rsi
leaq 0x30(%rsp), %rdx
callq 0x4302
movq %r14, %rdi
movq %r12, %rsi
callq 0x4c0a
movq %r12, %rdi
callq 0x4354
movq 0x8(%r14), %rdi
addq $-0x18, %rdi
pushq $0x8
popq %rsi
callq 0x4376
incq (%rsp)
pushq $0x1
popq %r13
jmp 0x38a2
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x4418
pushq $0x1
popq %r13
movq %r15, %rbx
movq %r12, %r15
movq %r15, %rdi
callq 0x34c0
movq %rbp, %rdi
callq 0x3480
jmp 0x3743
leaq 0x80(%rsp), %rdi
callq 0x3070
leaq 0x60(%rsp), %rdi
callq 0x34c0
pushq $0x1
popq %rbx
leaq 0x80(%rsp), %rdi
callq 0x31c0
movl %ebx, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3907
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4354
jmp 0x3913
jmp 0x3910
jmp 0x3907
movq %rax, %rbx
jmp 0x392a
jmp 0x3910
jmp 0x3910
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x34c0
leaq 0x288(%rsp), %rdi
callq 0x3480
leaq 0x60(%rsp), %rdi
callq 0x34c0
leaq 0x80(%rsp), %rdi
callq 0x31c0
movq %rbx, %rdi
callq 0x33f0