// File: /workspace/github_cpp_makefile_star2_O3/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, %r13
movq %rsi, %r15
movq (%rdi), %rsi
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x3220
movq (%rbx), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x5, 0xa0(%rsp,%rax)
jne 0x3ab8
movq (%r15), %r14
movq 0x8(%r15), %r12
cmpq %r14, %r12
je 0x37d6
movq %r14, %rbx
movq %rbx, %rdi
callq 0x498e
addq $0x18, %rbx
cmpq %r12, %rbx
jne 0x37c1
movq %r14, 0x8(%r15)
movq %r13, 0x40(%rsp)
movq %r13, %rdi
callq 0x4dc2
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movl $0x0, (%rax)
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
movq 0x170(%rsp,%rax), %rdi
testq %rdi, %rdi
je 0x3a80
leaq 0x30(%rsp), %r13
xorl %r14d, %r14d
leaq 0x50(%rsp), %rbp
leaq 0x288(%rsp), %r12
movq $0x0, 0x18(%rsp)
movq (%rdi), %rax
movl $0xa, %esi
callq *0x50(%rax)
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
movl %eax, %edx
callq 0x3310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3a85
movq %r12, %rdi
movq %rbp, %rsi
movl $0x8, %edx
callq 0x3350
movq %r13, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
testl %r14d, %r14d
je 0x397c
movq %r13, %rbx
movq 0x8(%r15), %rax
movq -0x18(%rax), %r13
movq %r12, %rdi
movq %rsp, %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x31e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
xorl %r14d, %r14d
testb $0x5, 0x20(%rax,%rcx)
jne 0x3a28
movq 0x8(%r13), %rsi
cmpq (%r13), %rsi
je 0x3959
movsd -0x10(%rsi), %xmm1
movsd (%rsp), %xmm0
movsd %xmm1, 0x48(%rsp)
subsd %xmm1, %xmm0
addsd 0x4713(%rip), %xmm0     # 0x8008
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x3959
xorl %r14d, %r14d
movsd 0x4708(%rip), %xmm0     # 0x8010
movapd %xmm0, 0x70(%rsp)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x3929
movapd 0x70(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%r13)
jmp 0x3936
movq %r13, %rdi
leaq 0x70(%rsp), %rdx
callq 0x53ca
incl %r14d
movsd (%rsp), %xmm0
subsd 0x48(%rsp), %xmm0
addsd 0x46bc(%rip), %xmm0     # 0x8008
cvttsd2si %xmm0, %eax
cmpl %eax, %r14d
jl 0x3900
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x3a17
movupd (%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%r13)
movl $0x1, %r14d
jmp 0x3a28
movq %r12, %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x3160
movq %rsp, %r14
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x4912
movq 0x18(%rsp), %rcx
movq %rcx, (%rax)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl $0x18, %edi
callq 0x32d0
movq %rax, (%rsp)
movq %rax, %rcx
addq $0x18, %rcx
movq %rcx, 0x10(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rcx, 0x8(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x51a2
movq %r14, %rdi
callq 0x498e
movq 0x8(%r15), %rdi
addq $-0x18, %rdi
movl $0x8, %esi
callq 0x49e2
incq 0x18(%rsp)
movl $0x1, %r14d
jmp 0x3a2b
movl $0x1, %r14d
movq %r13, %rdi
movq %rsp, %rdx
callq 0x53ca
movq %rbx, %r13
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x3a47
movq 0x30(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
movq %r12, %rdi
movq 0x757f(%rip), %rsi      # 0xafd0
callq 0x3190
leaq 0x300(%rsp), %rdi
callq 0x30b0
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
movq 0x170(%rsp,%rax), %rdi
testq %rdi, %rdi
jne 0x3835
callq 0x3380
leaq 0x80(%rsp), %rdi
callq 0x3080
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x3ab3
movq 0x60(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
movl $0x1, %ebx
leaq 0x80(%rsp), %rdi
callq 0x3200
movl %ebx, %eax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rbx
movq %rax, %r14
movq %rsp, %rdi
callq 0x498e
jmp 0x3af9
jmp 0x3af1
jmp 0x3b38
jmp 0x3b38
jmp 0x3af6
movq %r13, %rbx
jmp 0x3af6
movq %rax, %r14
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3b15
movq 0x30(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
movq 0x74b4(%rip), %rsi      # 0xafd0
leaq 0x288(%rsp), %rdi
callq 0x3190
leaq 0x300(%rsp), %rdi
callq 0x30b0
jmp 0x3b3b
movq %rax, %r14
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x3b5c
movq 0x60(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
leaq 0x80(%rsp), %rdi
callq 0x3200
movq %r14, %rdi
callq 0x3470