// File: 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
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
callq 0x4120
movq %rax, %rsi
leaq -0x228(%rbp), %rdi
movl $0x8, %edx
callq 0x42c0
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x4470
movb %al, -0x461(%rbp)
jmp 0x4a00
movb -0x461(%rbp), %al
testb $0x1, %al
jne 0x4a0c
jmp 0x4a39
movl $0x0, -0x4(%rbp)
movl $0x1, -0x238(%rbp)
jmp 0x4e1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x4e33
movq -0x18(%rbp), %rdi
callq 0x5fc0
movq -0x20(%rbp), %rdi
callq 0x5fe0
leaq -0x258(%rbp), %rdi
callq 0x4170
movq $0x0, -0x260(%rbp)
movl $0x0, -0x264(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4380
movq %rax, -0x470(%rbp)
jmp 0x4a88
movq -0x470(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x4690
movb %al, -0x471(%rbp)
jmp 0x4aa6
movb -0x471(%rbp), %al
testb $0x1, %al
jne 0x4ab5
jmp 0x4de0
leaq -0x3e8(%rbp), %rdi
leaq -0x258(%rbp), %rsi
movl $0x8, %edx
callq 0x4460
jmp 0x4acf
leaq -0x408(%rbp), %rdi
callq 0x4170
movl -0x264(%rbp), %eax
movl %eax, -0x478(%rbp)
testl %eax, %eax
je 0x4b18
jmp 0x4aed
movl -0x478(%rbp), %eax
subl $0x1, %eax
je 0x4c5d
jmp 0x4da9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x4e0d
leaq -0x3e8(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x41c0
jmp 0x4b2d
movq -0x260(%rbp), %rax
movq %rax, -0x488(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x6000
movq %rax, -0x480(%rbp)
jmp 0x4b54
movq -0x480(%rbp), %rax
movq -0x488(%rbp), %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x498(%rbp)
leaq -0x421(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x6110
movq -0x490(%rbp), %rdx
leaq -0x420(%rbp), %rdi
movl $0x1, %esi
callq 0x6130
jmp 0x4b9d
movq -0x498(%rbp), %rdi
leaq -0x420(%rbp), %rsi
callq 0x60e0
jmp 0x4bb2
leaq -0x420(%rbp), %rdi
callq 0x61a0
leaq -0x421(%rbp), %rdi
callq 0x6200
movq -0x18(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
movl $0x8, %esi
callq 0x6260
jmp 0x4be2
movq -0x260(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x260(%rbp)
movl $0x1, -0x264(%rbp)
jmp 0x4da9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x4dc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x4c4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x61a0
leaq -0x421(%rbp), %rdi
callq 0x6200
jmp 0x4dc6
movq -0x18(%rbp), %rdi
callq 0x6220
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6360
movq %rax, -0x440(%rbp)
leaq -0x3e8(%rbp), %rdi
leaq -0x438(%rbp), %rsi
callq 0x4190
movq %rax, -0x4a0(%rbp)
jmp 0x4c95
movq -0x4a0(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x4190
movq %rax, -0x4a8(%rbp)
jmp 0x4cb1
movq -0x4a8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x4690
movb %al, -0x4a9(%rbp)
jmp 0x4ccf
movb -0x4a9(%rbp), %al
testb $0x1, %al
jne 0x4cde
jmp 0x4d9d
movq -0x440(%rbp), %rdi
callq 0x6380
cmpq $0x0, %rax
jbe 0x4d86
movq -0x440(%rbp), %rdi
callq 0x63a0
movsd (%rax), %xmm0
movsd %xmm0, -0x448(%rbp)
movl $0x0, -0x44c(%rbp)
movl -0x44c(%rbp), %eax
movsd -0x438(%rbp), %xmm0
subsd -0x448(%rbp), %xmm0
movsd 0xd2d4(%rip), %xmm1     # 0x12008
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jge 0x4d84
movabsq $-0x3e9ced3000000000, %rax # imm = 0xC16312D000000000
movq %rax, -0x460(%rbp)
movq $0x0, -0x458(%rbp)
movq -0x440(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x63e0
jmp 0x4d71
jmp 0x4d73
movl -0x44c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44c(%rbp)
jmp 0x4d16
jmp 0x4d86
movq -0x440(%rbp), %rdi
leaq -0x438(%rbp), %rsi
callq 0x63e0
jmp 0x4d9b
jmp 0x4da7
movl $0x0, -0x264(%rbp)
jmp 0x4da9
leaq -0x408(%rbp), %rdi
callq 0x4738
leaq -0x3e8(%rbp), %rdi
callq 0x46f0
jmp 0x4a6c
leaq -0x408(%rbp), %rdi
callq 0x4738
leaq -0x3e8(%rbp), %rdi
callq 0x46f0
jmp 0x4e0d
leaq -0x228(%rbp), %rdi
callq 0x4080
jmp 0x4dee
movl $0x1, -0x4(%rbp)
movl $0x1, -0x238(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x4738
jmp 0x4e1b
leaq -0x258(%rbp), %rdi
callq 0x4738
jmp 0x4e33
leaq -0x228(%rbp), %rdi
callq 0x4290
movl -0x4(%rbp), %eax
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x4290
movq -0x230(%rbp), %rdi
callq 0x4620
nopl (%rax,%rax)