// File: /workspace/github_cpp_makefile_star2_O1/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 $0x418, %rsp            # imm = 0x418
movq %rdx, %r13
movq %rsi, %r14
movq (%rdi), %rsi
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x3220
movq (%rbx), %rax
movq -0x18(%rax), %rax
xorl %ebx, %ebx
testb $0x5, 0xb0(%rsp,%rax)
jne 0x3ae2
movq (%r14), %r15
movq 0x8(%r14), %r12
cmpq %r15, %r12
je 0x37e6
movq %r15, %rbx
movq %rbx, %rdi
callq 0x49a0
addq $0x18, %rbx
cmpq %r12, %rbx
jne 0x37d1
movq %r15, 0x8(%r14)
movq %r14, 0x28(%rsp)
movq %r13, 0x50(%rsp)
movq %r13, %rdi
callq 0x4dce
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movl $0x0, (%rax)
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movq 0x180(%rsp,%rax), %rdi
testq %rdi, %rdi
je 0x3aa4
leaq 0x40(%rsp), %r13
xorl %ebp, %ebp
leaq 0x70(%rsp), %r12
leaq 0x298(%rsp), %r15
movabsq $-0x3e9ced3000000000, %rbx # imm = 0xC16312D000000000
movq $0x0, 0x20(%rsp)
movq (%rdi), %rax
movl $0xa, %esi
callq *0x50(%rax)
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x3310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3aa9
movq %r15, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x3350
movq %r13, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
testl %ebp, %ebp
je 0x3998
movq %r13, %r14
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rax), %r13
movq %r15, %rdi
movq %rsp, %rsi
callq 0x31e0
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x31e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
xorl %ebp, %ebp
testb $0x5, 0x20(%rax,%rcx)
jne 0x3a4c
movq 0x8(%r13), %rax
cmpq (%r13), %rax
je 0x3972
movsd -0x10(%rax), %xmm1
movsd (%rsp), %xmm0
movsd %xmm1, 0x58(%rsp)
subsd %xmm1, %xmm0
addsd 0x46f3(%rip), %xmm0     # 0x8008
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x3972
xorl %ebp, %ebp
movq %rbx, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x3948
movupd 0x60(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%r13)
jmp 0x3955
movq %r13, %rdi
leaq 0x60(%rsp), %rdx
callq 0x53ec
incl %ebp
movsd (%rsp), %xmm0
subsd 0x58(%rsp), %xmm0
addsd 0x469e(%rip), %xmm0     # 0x8008
cvttsd2si %xmm0, %eax
cmpl %eax, %ebp
jl 0x391f
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x3a3c
movupd (%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, 0x8(%r13)
movl $0x1, %ebp
jmp 0x3a4c
movq %r15, %rdi
leaq 0x30(%rsp), %rbp
movq %rbp, %rsi
callq 0x3160
movq 0x50(%rsp), %rdi
movq 0x28(%rsp), %r14
movq %rbp, %rsi
callq 0x4924
movq 0x20(%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, 0x8(%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 %r14, %rdi
movq %rsp, %rbp
movq %rbp, %rsi
callq 0x51ae
movq %rbp, %rdi
callq 0x49a0
movq 0x8(%r14), %rdi
addq $-0x18, %rdi
movl $0x8, %esi
callq 0x49ee
incq 0x20(%rsp)
movl $0x1, %ebp
jmp 0x3a4f
movl $0x1, %ebp
movq %r13, %rdi
movq %rsp, %rdx
callq 0x53ec
movq %r14, %r13
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x3a6b
movq 0x40(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
movq %r15, %rdi
movq 0x755b(%rip), %rsi      # 0xafd0
callq 0x3190
leaq 0x310(%rsp), %rdi
callq 0x30b0
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
movq 0x180(%rsp,%rax), %rdi
testq %rdi, %rdi
jne 0x3856
callq 0x3380
leaq 0x90(%rsp), %rdi
callq 0x3080
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x3add
movq 0x80(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
movl $0x1, %ebx
leaq 0x90(%rsp), %rdi
callq 0x3200
movl %ebx, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %r14
movq %rax, %rbx
movq %rsp, %rdi
callq 0x49a0
jmp 0x3b23
jmp 0x3b1b
jmp 0x3b62
jmp 0x3b62
jmp 0x3b20
movq %r13, %r14
jmp 0x3b20
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x3b3f
movq 0x40(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
movq 0x748a(%rip), %rsi      # 0xafd0
leaq 0x298(%rsp), %rdi
callq 0x3190
leaq 0x310(%rsp), %rdi
callq 0x30b0
jmp 0x3b65
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x3b8c
movq 0x80(%rsp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x32f0
leaq 0x90(%rsp), %rdi
callq 0x3200
movq %rbx, %rdi
callq 0x3480