// File: /workspace/github_cpp_makefile_star2_O3/Altius[P]hotspot2/src/hotspot2_part2.cpp
// Function: parseAndProcessInput(std::map<int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, std::less<int>, std::allocator<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*>>> const&, std::vector<std::pair<int, long double>, std::allocator<std::pair<int, long double>>> const&, int const&, long double const&, bool const&)
bool parseAndProcessInput(const map<int, string*>& intToChromNameMap, const vector<pair<int, long double> >& PvalToFDRmapping,
			  const int& N, const long double& FDRthreshold, const bool& writePvals)
{
  const int BUFSIZE(1000);
  char buf[BUFSIZE], *p;
  vector<SiteRangeData> vec;
  vector<SiteRangeData>::iterator it;
  int linenum(0), fieldnum;

  vec.resize(N);

  while (cin.getline(buf, BUFSIZE))
    {
      linenum++;
      if (linenum > N)
	{
	  cerr << "Error:  Expected to find exactly " << N
	       << " lines of data in the file of location and P-value data, but at least one additional line was found."
	       << endl << endl;
	  return false;
	}
      if (1 == linenum)
	it = vec.begin();
      else
	it++;
      fieldnum = 1;
      if (!(p = strtok(buf, "\t")) || !*p)
	{
	MissingField:
	  cerr << "Error:  Failed to find required field " << fieldnum
	       << " on line " << linenum << " of the file of location and P-value data."
	       << endl << endl;
	  return false;
	}
      it->chromID = atoi(p);
      fieldnum++;
      if (!(p = strtok(NULL, "\t")) || !*p)
	goto MissingField;
      it->begPos = atoi(p);
      fieldnum++;
      if (!(p = strtok(NULL, "\t")) || !*p)
	goto MissingField;
      it->width = atoi(p);
      fieldnum++;
      if (!(p = strtok(NULL, "\t")) || !*p)
	goto MissingField;
      it->negLog10P_scaled = atoi(p);
    }

  if (linenum < N)
    {
      cerr << "Error:  Expected to find exactly " << N
	   << " lines of data in the file of location and P-value data,"
	   << " but only " << linenum << " lines were found."
	   << endl << endl;
      return false;
    }

  sort(vec.begin(), vec.end(), NegLog10Pscaled_GT);

  if (vec[0].negLog10P_scaled != PvalToFDRmapping[0].first)
    {
      cerr << "Coding error:  Line " << __LINE__
	   << ", expected scaled -log10(P) values in the initial elements\n"
	   << "of the genomic data and P-to-FDR vectors to be equal, but they are not\n"
	   << '(' << vec[0].negLog10P_scaled << " for the former and "
	   << PvalToFDRmapping[0].first << " for the latter.)"
	   << endl << endl;
      return false;
    }

  it = vec.begin();
  for (vector<pair<int, long double> >::const_iterator itPtoQ = PvalToFDRmapping.begin();
       itPtoQ != PvalToFDRmapping.end(); itPtoQ++)
    {
      while (it != vec.end() && it->negLog10P_scaled == itPtoQ->first)
	{
	  it->FDR = itPtoQ->second;
	  it++;
	}
    }
  while (it != vec.end())
    {
      it->FDR = 1.;
      it++;
    }
  
  sort(vec.begin(), vec.end(), OutputOrder_LT);  
  int prevChromID(-1);
  string *prevChromString(NULL);
  
  for (it = vec.begin(); it != vec.end(); it++)
    {
      // Even though the map is tiny, perform as few map lookups as possible.
      if (it->chromID != prevChromID)
	{
	  prevChromString = intToChromNameMap.at(it->chromID);
	  prevChromID = it->chromID;
	}
      if (it->FDR <= FDRthreshold)
	{
	  cout << *prevChromString << '\t'
	       << it->begPos << '\t'
	       << it->begPos + it->width << "\ti\t"
	       << it->FDR;
	  if (writePvals)
	    cout << '\t' << pow(10., -it->negLog10P_scaled/CHANGE_OF_SCALE);
	  cout << '\n';
	}
    }
      
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movq %r8, 0x68(%rsp)
movq %rcx, 0x78(%rsp)
movq %rsi, %rbx
movq %rdi, 0x70(%rsp)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rdx, 0x30(%rsp)
movslq (%rdx), %rsi
callq 0x4048
movq %rbx, 0x60(%rsp)
xorl %r15d, %r15d
movq 0x62ad(%rip), %rbx      # 0x8fd8
leaq 0x80(%rsp), %r12
leaq 0x3649(%rip), %r14      # 0x6383
xorl %ebp, %ebp
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %ecx
movl $0x3e8, %edx            # imm = 0x3E8
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2f20
movq 0x30(%rsp), %rax
cmpl (%rax), %ebp
jge 0x2fe7
testl %ebp, %ebp
jne 0x2d8d
movq 0x40(%rsp), %r15
jmp 0x2d91
addq $0x20, %r15
movq %r12, %r13
movq %r12, %rdi
movq %r14, %rsi
callq 0x2250
movl $0x1, %r12d
testq %rax, %rax
je 0x2e3e
cmpb $0x0, (%rax)
je 0x2e3e
movq %rax, %rdi
callq 0x2240
movl %eax, 0xc(%r15)
xorl %edi, %edi
movq %r14, %rsi
callq 0x2250
movl $0x2, %r12d
testq %rax, %rax
je 0x2e3e
cmpb $0x0, (%rax)
je 0x2e3e
movq %rax, %rdi
callq 0x2240
movl %eax, 0x4(%r15)
xorl %edi, %edi
movq %r14, %rsi
callq 0x2250
movl $0x3, %r12d
testq %rax, %rax
je 0x2e3e
cmpb $0x0, (%rax)
je 0x2e3e
movq %rax, %rdi
callq 0x2240
movl %eax, 0x8(%r15)
xorl %edi, %edi
movq %r14, %rsi
callq 0x2250
movl $0x4, %r12d
testq %rax, %rax
je 0x2e3e
cmpb $0x0, (%rax)
je 0x2e3e
movq %rax, %rdi
callq 0x2240
movl %eax, (%r15)
incl %ebp
movq %r13, %r12
jmp 0x2d3c
movq 0x61ab(%rip), %rdi      # 0x8ff0
leaq 0x33cc(%rip), %rsi      # 0x6218
movl $0x26, %edx
callq 0x21e0
movq 0x6193(%rip), %rdi      # 0x8ff0
movl %r12d, %esi
callq 0x22b0
movq %rax, %rbx
leaq 0x3217(%rip), %rsi      # 0x6086
movl $0x9, %edx
movq %rax, %rdi
callq 0x21e0
incl %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x22b0
movq %rax, %rbx
leaq 0x33ad(%rip), %rsi      # 0x623f
movl $0x2a, %edx
movq %rax, %rdi
callq 0x21e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
xorl %ebx, %ebx
movq 0x40(%rsp), %r12
testq %r12, %r12
je 0x2f0c
movq 0x50(%rsp), %rsi
subq %r12, %rsi
movq %r12, %rdi
callq 0x21b0
movl %ebx, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rax
cmpl (%rax), %ebp
jge 0x306c
movq 0x60bc(%rip), %rdi      # 0x8ff0
leaq 0x3256(%rip), %rsi      # 0x6191
movl $0x21, %edx
callq 0x21e0
movq 0x30(%rsp), %rax
movl (%rax), %esi
movq 0x609d(%rip), %rdi      # 0x8ff0
callq 0x22b0
movq %rax, %rbx
leaq 0x3308(%rip), %rsi      # 0x626a
movl $0x38, %edx
movq %rax, %rdi
callq 0x21e0
leaq 0x332d(%rip), %rsi      # 0x62a3
movl $0xa, %edx
movq %rbx, %rdi
callq 0x21e0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x22b0
movq %rax, %rbx
leaq 0x3317(%rip), %rsi      # 0x62ae
movl $0x12, %edx
movq %rax, %rdi
callq 0x21e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
jmp 0x2edd
movq 0x6002(%rip), %rdi      # 0x8ff0
leaq 0x319c(%rip), %rsi      # 0x6191
movl $0x21, %edx
callq 0x21e0
movq 0x30(%rsp), %rax
movl (%rax), %esi
movq 0x5fe3(%rip), %rdi      # 0x8ff0
callq 0x22b0
movq %rax, %rbx
leaq 0x3197(%rip), %rsi      # 0x61b3
movl $0x64, %edx
movq %rax, %rdi
callq 0x21e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
jmp 0x2edd
movq 0x40(%rsp), %rbx
movq 0x48(%rsp), %r14
cmpq %r14, %rbx
je 0x30c2
movq %r14, %rax
subq %rbx, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xaad(%rip), %rcx      # 0x25ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49b3
movq 0x60(%rsp), %r15
leaq -0xac4(%rip), %rdx      # 0x25ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4b0e
movq 0x40(%rsp), %rbx
jmp 0x30c7
movq 0x60(%rsp), %r15
movl (%rbx), %eax
movq (%r15), %rcx
cmpl (%rcx), %eax
jne 0x32d1
movq 0x8(%r15), %rdx
movq 0x48(%rsp), %r14
movq %rbx, %rax
cmpq %rdx, %rcx
je 0x310b
movq %rbx, %rax
cmpq %r14, %rax
je 0x3102
movl (%rcx), %esi
cmpl %esi, (%rax)
jne 0x3102
fldt 0x10(%rcx)
fstpt 0x10(%rax)
addq $0x20, %rax
cmpq %r14, %rax
jne 0x30ef
addq $0x20, %rcx
cmpq %rdx, %rcx
jne 0x30e8
cmpq %r14, %rax
fldz
je 0x3124
fstp %st(0)
fld1
fld %st(0)
fstpt 0x10(%rax)
addq $0x20, %rax
cmpq %r14, %rax
jne 0x3116
fstp %st(0)
cmpq %r14, %rbx
je 0x33c7
movq %r14, %rax
subq %rbx, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xb59(%rip), %rcx      # 0x25f4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49b3
leaq -0xb6b(%rip), %rdx      # 0x25f4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4b0e
movq 0x40(%rsp), %r12
cmpq 0x48(%rsp), %r12
je 0x33ce
addq $0xc, %r12
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq 0x5e3a(%rip), %r13      # 0x8fc8
leaq 0x2f(%rsp), %rbp
flds 0x2e6f(%rip)            # 0x6008
fstpt 0x30(%rsp)
cmpl %r15d, (%r12)
je 0x31b7
movq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x407c
movq (%rax), %r14
movl (%r12), %r15d
fldt 0x4(%r12)
movq 0x78(%rsp), %rax
fldt (%rax)
fucompi %st(1), %st
fstp %st(0)
jb 0x32b3
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r13, %rdi
callq 0x21e0
movb $0x9, 0x2f(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x21e0
movl -0x8(%r12), %esi
movq %rax, %rdi
callq 0x22b0
movb $0x9, 0x2f(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x21e0
movl -0x4(%r12), %esi
addl -0x8(%r12), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x314a(%rip), %rsi      # 0x6381
callq 0x21e0
fldt 0x4(%r12)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x20e0
movq 0x68(%rsp), %rax
cmpb $0x1, (%rax)
jne 0x329e
movb $0x9, 0x2f(%rsp)
movl $0x1, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x21e0
movq %rax, %rbx
xorl %eax, %eax
subl -0xc(%r12), %eax
movl %eax, 0x5c(%rsp)
fildl 0x5c(%rsp)
fdivs 0x2d81(%rip)            # 0x6004
fldt 0x30(%rsp)
fstpt (%rsp)
fstpt 0x10(%rsp)
callq 0x2290
fstpt (%rsp)
movq %rbx, %rdi
callq 0x20e0
movb $0xa, 0x2f(%rsp)
movl $0x1, %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x21e0
leaq 0x20(%r12), %rax
addq $0x14, %r12
movb $0x1, %bl
cmpq 0x48(%rsp), %r12
movq %rax, %r12
jne 0x319d
jmp 0x2ef2
movq 0x5d18(%rip), %rdi      # 0x8ff0
leaq 0x2fe2(%rip), %rsi      # 0x62c1
movl $0x14, %edx
callq 0x21e0
movq 0x5d00(%rip), %rdi      # 0x8ff0
movl $0xff, %esi
callq 0x22b0
movq %rax, %rbx
leaq 0x2fd2(%rip), %rsi      # 0x62d6
movl $0x3b, %edx
movq %rax, %rdi
callq 0x21e0
leaq 0x2ffa(%rip), %rsi      # 0x6312
movl $0x47, %edx
movq %rbx, %rdi
callq 0x21e0
leaq 0x2f(%rsp), %rsi
movb $0x28, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x21e0
movq 0x40(%rsp), %rcx
movl (%rcx), %esi
movq %rax, %rdi
callq 0x22b0
movq %rax, %rbx
leaq 0x3007(%rip), %rsi      # 0x635a
movl $0x14, %edx
movq %rax, %rdi
callq 0x21e0
movq (%r15), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x22b0
movq %rax, %rbx
leaq 0x2ff8(%rip), %rsi      # 0x636f
movl $0x11, %edx
movq %rax, %rdi
callq 0x21e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
jmp 0x2edd
movb $0x1, %bl
jmp 0x2ef2
movb $0x1, %bl
jmp 0x2ef7
jmp 0x33d9
jmp 0x33d9
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x33f3
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x22c0