// File: /workspace/github_cpp_makefile_star2_O2/Altius[P]hotspot2/src/hotspot2_part1.cpp
// Function: main
int main(int argc, char* argv[])
{

  // Option defaults
  int background_size = 50001;
  int sampling_interval = 1;
  int smoothing_parameter = 5; // recommend ca. 15 when the maximum # of sampled observations is ca. 250
  int print_help = 0;
  int print_version = 0;
  string infilename = "";
  string outfilename = "";
  string outfilenameChromNames = "";
  string outfilenamePvals = "";

  // Long-opt definitions
  static struct option long_options[] = {
    { "background_size", required_argument, 0, 'b' },
    { "sampling_interval", required_argument, 0, 'n' },
    { "smoothing_parameter", required_argument, 0, 'm' },
    { "input", required_argument, 0, 'i' },
    { "output", required_argument, 0, 'o' },
    { "outputChromlist", required_argument, 0, 'c' },
    { "outputPvals", required_argument, 0, 'p' }, // note we had been using 'p' for num_pvals
    { "help", no_argument, &print_help, 1 },
    { "version", no_argument, &print_version, 1 },
    { 0, 0, 0, 0 }
  };

  // Parse options
  char c;
  stringstream ss; // Used for parsing doubles (allows scientific notation)
  while ((c = getopt_long(argc, argv, "b:f:m:n:p:s:i:o:c:hvV", long_options, NULL)) != -1)
    {
      switch (c)
        {
        case 'b':
          background_size = atoi(optarg);
          break;
        case 'n':
          sampling_interval = atoi(optarg);
          break;
        case 'm':
          smoothing_parameter = atoi(optarg);
          break;
        case 'p':
	  outfilenamePvals = optarg;
          break;
        case 'i':
          infilename = optarg;
          break;
        case 'o':
          outfilename = optarg;
          break;
	case 'c':
          outfilenameChromNames = optarg;
          break;
	case 'h':
          print_help = 1;
          break;
        case 'v':
        case 'V':
          print_version = 1;
          break;
        case 0:
          // long option received, do nothing
          break;
        default:
          print_help = 1;
        }
    }

  if (!print_help && !print_version && outfilenameChromNames.empty())
    {
      cerr << "Error:  No filename supplied for (temporary) output file of integer-to-chromosomeName mapping."
	   << endl
	   << endl;
      print_help = 1;
    }
  if (!print_help && !print_version && outfilenamePvals.empty())
    {
      cerr << "Error:  No filename supplied for (temporary) output file of scaled -log10(P) values."
	   << endl
	   << endl;
      print_help = 1;
    }
  
  // Print usage and exit if necessary
  if (print_help)
    {
      cerr << "Usage:  " << argv[0] << " [options] < in.cutcounts.bed > out.pvalues.bed\n"
           << "\n"
           << "Options: \n"
           << "  -b, --background_size=SIZE     The size of the background region (50001)\n"
           << "  -n, --sampling_interval=INT    How often (bp) to sample for null modeling (1)\n"
           << "  -m, --smoothing_prameter=INT   Smoothing parameter used in null modeling (5)\n"
           << "  -i, --input=FILE               A file to read input from (STDIN)\n"
           << "  -o, --output=FILE              A file to write output to (STDOUT)\n"
	   << "  -c, --outputChromlist=FILE     Output file to store chromName-to-int mapping\n"
	   << "  -p, --outputPvals=FILE         Output file to store scaled -log10(P) values and # occurrences\n"
	   << "  -v, --version                  Print the version information and exit\n"
           << "  -h, --help                     Display this helpful help\n"
           << "\n"
           << " output (sent to stdout) will be a .bed4 file with a scaled transformation of the P-value in field 4\n"
           << " input (received from stdin) requires IDs in field 4 and counts in field 5.\n"
           << endl
           << endl;
      return -1;
    }

  if (print_version)
    {
      cout << argv[0] << " version " << hotspot2_VERSION_MAJOR
           << '.' << hotspot2_VERSION_MINOR << endl;
      return 0;
    }

  ios_base::sync_with_stdio(false); // calling this static method in this way turns off checks, speeds up I/O

  if (!infilename.empty() && infilename != "-")
    {
      if (freopen(infilename.c_str(), "r", stdin) == NULL)
        {
          cerr << "Error: Couldn't open input file " << infilename << endl;
          return 1;
        }
    }
  if (!outfilename.empty() && outfilename != "-")
    {
      if (freopen(outfilename.c_str(), "w", stdout) == NULL)
        {
          cerr << "Error: Couldn't open output file " << outfilename << " for writing" << endl;
          return 1;
        }
    }

  ofstream ofsIntToChrnameMapping(outfilenameChromNames.c_str());
  if (!ofsIntToChrnameMapping)
    {
      cerr << "Error:  Unable to open file \"" << outfilenameChromNames << "\" for write."
	   << endl
	   << endl;
      return -1;
    }
  ofstream ofsPvals(outfilenamePvals.c_str());
  if (!ofsPvals)
    {
      cerr << "Error:  Unable to open file \"" << outfilenamePvals << "\" for write."
	   << endl
	   << endl;
      return -1;
    }
  
  if (!parseAndProcessInput(background_size, sampling_interval, smoothing_parameter,
			    ofsPvals))
    return -1;

  for (map<string*, int>::const_iterator it = chromAsInt.begin(); it != chromAsInt.end(); it++)
    ofsIntToChrnameMapping << it->second << '\t' << *(it->first) << '\n';
  
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x628, %rsp            # imm = 0x628
movq %rsi, %r14
movl %edi, %ebp
movl $0xc351, 0x10(%rsp)     # imm = 0xC351
movl $0x1, 0xc(%rsp)
andl $0x0, (%rsp)
movl $0x5, 0x8(%rsp)
andl $0x0, 0x4(%rsp)
leaq 0x34e3(%rip), %rbx      # 0x8835
leaq 0x40(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
movq %rbx, %rsi
callq 0x5e7e
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
movq %rbx, %rsi
callq 0x5e7e
leaq 0x34b2(%rip), %rsi      # 0x8835
leaq 0x80(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x5e7e
leaq 0x3496(%rip), %rsi      # 0x8835
leaq 0x60(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x5e7e
movb 0x7009(%rip), %al       # 0xc3c0
testb %al, %al
je 0x597f
leaq 0x4a0(%rsp), %rdi
callq 0x2160
movl 0x8(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x1c(%rsp)
leaq 0x34d7(%rip), %r12      # 0x88c2
leaq 0x6e8e(%rip), %r13      # 0xc280
leaq 0x2c57(%rip), %rbx      # 0x8050
movq 0x6bb0(%rip), %r15      # 0xbfb0
movl %ebp, %edi
movq %r14, %rsi
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x2320
shll $0x18, %eax
cmpl $0xff000000, %eax       # imm = 0xFF000000
je 0x54a9
sarl $0x18, %eax
leal -0x62(%rax), %ecx
cmpl $0x14, %ecx
ja 0x5448
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
leaq 0x40(%rsp), %rdi
jmpq *%rax
movq (%r15), %rdi
callq 0x22e0
movl %eax, 0x1c(%rsp)
jmp 0x5400
testl %eax, %eax
je 0x5400
cmpl $0x56, %eax
jne 0x545b
movl $0x1, 0x4(%rsp)
jmp 0x5400
movl $0x1, (%rsp)
jmp 0x5400
leaq 0x80(%rsp), %rdi
jmp 0x548b
leaq 0x60(%rsp), %rdi
jmp 0x548b
movq (%r15), %rdi
callq 0x22e0
movl %eax, 0x18(%rsp)
jmp 0x5400
leaq 0x20(%rsp), %rdi
movq (%r15), %rsi
callq 0x2390
jmp 0x5400
movq (%r15), %rdi
callq 0x22e0
movl %eax, 0x14(%rsp)
jmp 0x5400
movl 0x14(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%rsp)
movl (%rsp), %ecx
movl 0x4(%rsp), %eax
testl %ecx, %ecx
jne 0x5507
testl %eax, %eax
jne 0x5507
cmpq $0x0, 0x88(%rsp)
jne 0x5507
movq 0x6b0e(%rip), %rdi      # 0xbff0
leaq 0x33ef(%rip), %rsi      # 0x88d8
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
movl $0x1, (%rsp)
jmp 0x5519
movl %ecx, %edx
orl %eax, %edx
je 0x5677
testl %ecx, %ecx
je 0x578b
movq 0x6ad0(%rip), %rdi      # 0xbff0
leaq 0x3465(%rip), %rsi      # 0x898c
callq 0x21e0
movq (%r14), %rsi
movq %rax, %rdi
callq 0x21e0
leaq 0x3457(%rip), %rsi      # 0x8995
movq %rax, %rdi
callq 0x21e0
leaq 0x3482(%rip), %rsi      # 0x89cf
movq %rax, %rdi
callq 0x21e0
leaq 0x346a(%rip), %rsi      # 0x89c6
movq %rax, %rdi
callq 0x21e0
leaq 0x3466(%rip), %rsi      # 0x89d1
movq %rax, %rdi
callq 0x21e0
leaq 0x34a3(%rip), %rsi      # 0x8a1d
movq %rax, %rdi
callq 0x21e0
leaq 0x34e5(%rip), %rsi      # 0x8a6e
movq %rax, %rdi
callq 0x21e0
leaq 0x3526(%rip), %rsi      # 0x8abe
movq %rax, %rdi
callq 0x21e0
leaq 0x355b(%rip), %rsi      # 0x8b02
movq %rax, %rdi
callq 0x21e0
leaq 0x3591(%rip), %rsi      # 0x8b47
movq %rax, %rdi
callq 0x21e0
leaq 0x35d2(%rip), %rsi      # 0x8b97
movq %rax, %rdi
callq 0x21e0
leaq 0x3624(%rip), %rsi      # 0x8bf8
movq %rax, %rdi
callq 0x21e0
leaq 0x365e(%rip), %rsi      # 0x8c41
movq %rax, %rdi
callq 0x21e0
leaq 0x33dd(%rip), %rsi      # 0x89cf
movq %rax, %rdi
callq 0x21e0
leaq 0x367c(%rip), %rsi      # 0x8c7d
movq %rax, %rdi
callq 0x21e0
leaq 0x36d3(%rip), %rsi      # 0x8ce3
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
pushq $-0x1
popq %rbx
leaq 0x4a0(%rsp), %rdi
callq 0x2180
leaq 0x60(%rsp), %rdi
callq 0x20d0
leaq 0x80(%rsp), %rdi
callq 0x20d0
leaq 0x20(%rsp), %rdi
callq 0x20d0
leaq 0x40(%rsp), %rdi
callq 0x20d0
movl %ebx, %eax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x68(%rsp)
je 0x57e1
xorl %edi, %edi
callq 0x20b0
pushq $0x1
popq %rbx
cmpq $0x0, 0x48(%rsp)
je 0x56ce
leaq 0x369e(%rip), %rsi      # 0x8d3a
leaq 0x40(%rsp), %rdi
callq 0x5ef8
testb %al, %al
je 0x56ce
movq 0x40(%rsp), %rdi
movq 0x690a(%rip), %rax      # 0xbfc0
movq (%rax), %rdx
leaq 0x31ca(%rip), %rsi      # 0x888a
callq 0x2220
testq %rax, %rax
je 0x5878
cmpq $0x0, 0x28(%rsp)
je 0x570f
leaq 0x365d(%rip), %rsi      # 0x8d3a
leaq 0x20(%rsp), %rdi
callq 0x5ef8
testb %al, %al
je 0x570f
movq 0x20(%rsp), %rdi
movq 0x68a9(%rip), %rax      # 0xbfa0
movq (%rax), %rdx
leaq 0x365c(%rip), %rsi      # 0x8d5d
callq 0x2220
testq %rax, %rax
je 0x593f
movq 0x80(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x2230
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc0(%rsp,%rax)
je 0x5809
movq 0x68a8(%rip), %rdi      # 0xbff0
leaq 0x363f(%rip), %rsi      # 0x8d8e
callq 0x21e0
leaq 0x80(%rsp), %rsi
movq %rax, %rdi
callq 0x21c0
leaq 0x3641(%rip), %rsi      # 0x8dac
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
pushq $-0x1
popq %rbx
jmp 0x592d
testl %eax, %eax
je 0x5683
movq (%r14), %rsi
movq 0x682b(%rip), %rdi      # 0xbfc8
callq 0x21e0
leaq 0x3587(%rip), %rsi      # 0x8d30
movq %rax, %rdi
callq 0x21e0
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x2340
pushq $0x2e
popq %rsi
movq %rax, %rdi
callq 0x2260
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x2340
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20e0
jmp 0x562b
movq 0x6808(%rip), %rdi      # 0xbff0
leaq 0x3148(%rip), %rsi      # 0x8937
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
jmp 0x54fe
movq 0x60(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x2230
movq 0x2a0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x2c0(%rsp,%rax)
je 0x589d
movq 0x67b5(%rip), %rdi      # 0xbff0
leaq 0x354c(%rip), %rsi      # 0x8d8e
callq 0x21e0
leaq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x21c0
leaq 0x3551(%rip), %rsi      # 0x8dac
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x20e0
jmp 0x591d
movq 0x6771(%rip), %rdi      # 0xbff0
leaq 0x34b6(%rip), %rsi      # 0x8d3c
callq 0x21e0
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x21c0
jmp 0x596e
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x2a0(%rsp), %rcx
callq 0x4ff8
testb %al, %al
je 0x591d
movq 0x698c(%rip), %r14      # 0xc250
leaq 0x6975(%rip), %r12      # 0xc240
leaq 0xa0(%rsp), %rbx
pushq $0x9
popq %rbp
pushq $0xa
popq %r15
cmpq %r12, %r14
je 0x597b
movl 0x28(%r14), %esi
movq %rbx, %rdi
callq 0x2340
movq %rax, %rdi
movl %ebp, %esi
callq 0x2260
movq 0x20(%r14), %rsi
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
movl %r15d, %esi
callq 0x2260
movq %r14, %rdi
callq 0x2240
movq %rax, %r14
jmp 0x58da
pushq $-0x1
popq %rbx
leaq 0x2a0(%rsp), %rdi
callq 0x22c0
leaq 0xa0(%rsp), %rdi
callq 0x22c0
jmp 0x562b
movq 0x66aa(%rip), %rdi      # 0xbff0
leaq 0x3412(%rip), %rsi      # 0x8d5f
callq 0x21e0
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x21c0
leaq 0x341b(%rip), %rsi      # 0x8d81
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x20e0
jmp 0x562b
xorl %ebx, %ebx
jmp 0x5920
leaq 0x6a3a(%rip), %rdi      # 0xc3c0
callq 0x2370
testl %eax, %eax
je 0x53bf
leaq 0x2ebc(%rip), %rax      # 0x8856
movq %rax, 0x68df(%rip)      # 0xc280
pushq $0x1
popq %rax
movl %eax, 0x68de(%rip)      # 0xc288
andq $0x0, 0x68de(%rip)      # 0xc290
movl $0x62, 0x68dc(%rip)     # 0xc298
leaq 0x2ea3(%rip), %rcx      # 0x8866
movq %rcx, 0x68d6(%rip)      # 0xc2a0
movl %eax, 0x68d8(%rip)      # 0xc2a8
andq $0x0, 0x68d8(%rip)      # 0xc2b0
movl $0x6e, 0x68d6(%rip)     # 0xc2b8
leaq 0x2e8f(%rip), %rcx      # 0x8878
movq %rcx, 0x68d0(%rip)      # 0xc2c0
movl %eax, 0x68d2(%rip)      # 0xc2c8
andq $0x0, 0x68d2(%rip)      # 0xc2d0
movl $0x6d, 0x68d0(%rip)     # 0xc2d8
leaq 0x2e7d(%rip), %rcx      # 0x888c
movq %rcx, 0x68ca(%rip)      # 0xc2e0
movl %eax, 0x68cc(%rip)      # 0xc2e8
andq $0x0, 0x68cc(%rip)      # 0xc2f0
movl $0x69, 0x68ca(%rip)     # 0xc2f8
leaq 0x2e5d(%rip), %rcx      # 0x8892
movq %rcx, 0x68c4(%rip)      # 0xc300
movl %eax, 0x68c6(%rip)      # 0xc308
andq $0x0, 0x68c6(%rip)      # 0xc310
movl $0x6f, 0x68c4(%rip)     # 0xc318
leaq 0x2e3e(%rip), %rcx      # 0x8899
movq %rcx, 0x68be(%rip)      # 0xc320
movl %eax, 0x68c0(%rip)      # 0xc328
andq $0x0, 0x68c0(%rip)      # 0xc330
movl $0x63, 0x68be(%rip)     # 0xc338
leaq 0x2e28(%rip), %rcx      # 0x88a9
movq %rcx, 0x68b8(%rip)      # 0xc340
movl %eax, 0x68ba(%rip)      # 0xc348
andq $0x0, 0x68ba(%rip)      # 0xc350
movl $0x70, 0x68b8(%rip)     # 0xc358
leaq 0x2e0e(%rip), %rcx      # 0x88b5
movq %rcx, 0x68b2(%rip)      # 0xc360
andl $0x0, 0x68b3(%rip)      # 0xc368
movq %rsp, %rcx
movq %rcx, 0x68b1(%rip)      # 0xc370
movl %eax, 0x68b3(%rip)      # 0xc378
leaq 0x2dee(%rip), %rcx      # 0x88ba
movq %rcx, 0x68ad(%rip)      # 0xc380
andl $0x0, 0x68ae(%rip)      # 0xc388
leaq 0x4(%rsp), %rcx
movq %rcx, 0x68aa(%rip)      # 0xc390
movl %eax, 0x68ac(%rip)      # 0xc398
xorps %xmm0, %xmm0
movaps %xmm0, 0x68ba(%rip)     # 0xc3b0
movaps %xmm0, 0x68a3(%rip)     # 0xc3a0
leaq 0x68bc(%rip), %rdi      # 0xc3c0
callq 0x2120
jmp 0x53bf
jmp 0x5b14
jmp 0x5b4e
jmp 0x5b2d
movq %rax, %rbx
jmp 0x5b3d
movq %rax, %rbx
jmp 0x5b5e
movq %rax, %rbx
jmp 0x5b68
movq %rax, %rbx
jmp 0x5b75
movq %rax, %rbx
jmp 0x5b7f
movq %rax, %rbx
leaq 0x2a0(%rsp), %rdi
callq 0x22c0
leaq 0xa0(%rsp), %rdi
callq 0x22c0
jmp 0x5b51
jmp 0x5b4e
movq %rax, %rbx
leaq 0x4a0(%rsp), %rdi
callq 0x2180
leaq 0x60(%rsp), %rdi
callq 0x20d0
leaq 0x80(%rsp), %rdi
callq 0x20d0
leaq 0x20(%rsp), %rdi
callq 0x20d0
leaq 0x40(%rsp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2350
nop