// File: /workspace/github_cpp_makefile_star2_O1/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 0x4080
movq %rbx, 0x60(%rsp)
xorl %r15d, %r15d
movq 0x627a(%rip), %rbx      # 0x8fd8
leaq 0x80(%rsp), %r12
leaq 0x3616(%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 0x2f50
movq 0x30(%rsp), %rax
cmpl (%rax), %ebp
jge 0x3017
testl %ebp, %ebp
jne 0x2dc0
movq 0x40(%rsp), %r15
jmp 0x2dc4
addq $0x20, %r15
movq %r12, %r13
movq %r12, %rdi
movq %r14, %rsi
callq 0x2250
movl $0x1, %r12d
testq %rax, %rax
je 0x2e71
cmpb $0x0, (%rax)
je 0x2e71
movq %rax, %rdi
callq 0x2240
movl %eax, 0xc(%r15)
xorl %edi, %edi
movq %r14, %rsi
callq 0x2250
movl $0x2, %r12d
testq %rax, %rax
je 0x2e71
cmpb $0x0, (%rax)
je 0x2e71
movq %rax, %rdi
callq 0x2240
movl %eax, 0x4(%r15)
xorl %edi, %edi
movq %r14, %rsi
callq 0x2250
movl $0x3, %r12d
testq %rax, %rax
je 0x2e71
cmpb $0x0, (%rax)
je 0x2e71
movq %rax, %rdi
callq 0x2240
movl %eax, 0x8(%r15)
xorl %edi, %edi
movq %r14, %rsi
callq 0x2250
movl $0x4, %r12d
testq %rax, %rax
je 0x2e71
cmpb $0x0, (%rax)
je 0x2e71
movq %rax, %rdi
callq 0x2240
movl %eax, (%r15)
incl %ebp
movq %r13, %r12
jmp 0x2d6f
movq 0x6178(%rip), %rdi      # 0x8ff0
leaq 0x3399(%rip), %rsi      # 0x6218
movl $0x26, %edx
callq 0x21e0
movq 0x6160(%rip), %rdi      # 0x8ff0
movl %r12d, %esi
callq 0x22b0
movq %rax, %rbx
leaq 0x31e4(%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 0x337a(%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 %ebp, %ebp
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2f3c
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
movl %ebp, %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 0x309c
movq 0x608c(%rip), %rdi      # 0x8ff0
leaq 0x3226(%rip), %rsi      # 0x6191
movl $0x21, %edx
callq 0x21e0
movq 0x30(%rsp), %rax
movl (%rax), %esi
movq 0x606d(%rip), %rdi      # 0x8ff0
callq 0x22b0
movq %rax, %rbx
leaq 0x32d8(%rip), %rsi      # 0x626a
movl $0x38, %edx
movq %rax, %rdi
callq 0x21e0
leaq 0x32fd(%rip), %rsi      # 0x62a3
movl $0xa, %edx
movq %rbx, %rdi
callq 0x21e0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x22b0
movq %rax, %rbx
leaq 0x32e7(%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 0x2f10
movq 0x5fd2(%rip), %rdi      # 0x8ff0
leaq 0x316c(%rip), %rsi      # 0x6191
movl $0x21, %edx
callq 0x21e0
movq 0x30(%rsp), %rax
movl (%rax), %esi
movq 0x5fb3(%rip), %rdi      # 0x8ff0
callq 0x22b0
movq %rax, %rbx
leaq 0x3167(%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 0x2f10
movq 0x40(%rsp), %rbx
movq 0x48(%rsp), %r14
cmpq %r14, %rbx
movq 0x60(%rsp), %r15
je 0x30eb
movq %r14, %rax
subq %rbx, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xae2(%rip), %rcx      # 0x25ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49f5
leaq -0xaf4(%rip), %rdx      # 0x25ec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4b50
movq 0x40(%rsp), %rbx
movl (%rbx), %eax
movq (%r15), %rcx
cmpl (%rcx), %eax
jne 0x3301
movq 0x8(%r15), %rdx
movq %rbx, %rax
cmpq %rdx, %rcx
je 0x3134
movq 0x48(%rsp), %rsi
movq %rbx, %rax
cmpq %rsi, %rax
je 0x312b
movl (%rcx), %edi
cmpl %edi, (%rax)
jne 0x312b
fldt 0x10(%rcx)
fstpt 0x10(%rax)
addq $0x20, %rax
cmpq %rsi, %rax
jne 0x3118
addq $0x20, %rcx
cmpq %rdx, %rcx
jne 0x3111
movq 0x48(%rsp), %r14
cmpq %r14, %rax
fldz
je 0x3152
fstp %st(0)
fld1
fld %st(0)
fstpt 0x10(%rax)
addq $0x20, %rax
cmpq %r14, %rax
jne 0x3144
fstp %st(0)
cmpq %r14, %rbx
je 0x3194
movq %r14, %rax
subq %rbx, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xb83(%rip), %rcx      # 0x25f4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49f5
leaq -0xb95(%rip), %rdx      # 0x25f4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4b50
movq 0x40(%rsp), %r12
movb $0x1, %bpl
cmpq 0x48(%rsp), %r12
je 0x2f25
addq $0xc, %r12
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
leaq 0x2f(%rsp), %r13
flds 0x2e49(%rip)            # 0x6008
fstpt 0x30(%rsp)
cmpl %r15d, (%r12)
je 0x31dd
movq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x40b4
movq (%rax), %r14
movl (%r12), %r15d
fldt 0x4(%r12)
movq 0x78(%rsp), %rax
fldt (%rax)
fucompi %st(1), %st
fstp %st(0)
jb 0x32e5
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x5dc7(%rip), %rdi      # 0x8fc8
callq 0x21e0
movb $0x9, 0x2f(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21e0
movl -0x8(%r12), %esi
movq %rax, %rdi
callq 0x22b0
movb $0x9, 0x2f(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %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 0x3120(%rip), %rsi      # 0x6381
callq 0x21e0
fldt 0x4(%r12)
fstpt (%rsp)
movq %rbx, %rdi
callq 0x20e0
movq 0x68(%rsp), %rax
cmpb $0x1, (%rax)
jne 0x32cc
movb $0x9, 0x2f(%rsp)
movl $0x1, %edx
movq 0x5d37(%rip), %rdi      # 0x8fc8
movq %r13, %rsi
callq 0x21e0
movq %rax, %rbx
xorl %eax, %eax
subl -0xc(%r12), %eax
movl %eax, 0x5c(%rsp)
fildl 0x5c(%rsp)
fdivs 0x2d53(%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 0x5ceb(%rip), %rdi      # 0x8fc8
movq %r13, %rsi
callq 0x21e0
leaq 0x20(%r12), %rax
addq $0x14, %r12
cmpq 0x48(%rsp), %r12
movq %rax, %r12
jne 0x31c3
jmp 0x2f25
movq 0x5ce8(%rip), %rdi      # 0x8ff0
leaq 0x2fb2(%rip), %rsi      # 0x62c1
movl $0x14, %edx
callq 0x21e0
movq 0x5cd0(%rip), %rdi      # 0x8ff0
movl $0xff, %esi
callq 0x22b0
movq %rax, %rbx
leaq 0x2fa2(%rip), %rsi      # 0x62d6
movl $0x3b, %edx
movq %rax, %rdi
callq 0x21e0
leaq 0x2fca(%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 0x2fd7(%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 0x2fc8(%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 0x2f10
jmp 0x33fb
jmp 0x33fb
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3415
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x22c0