// File: ncbi[P]amr/common.cpp
// Function: Common_sp::ShellApplication::getBlastThreadsParam(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned long) const
string ShellApplication::getBlastThreadsParam (const string &blast,
                                               size_t threads_max_max) const
{
  ASSERT (! tmp. empty ());

  const size_t t = min (threads_max, threads_max_max);
  if (t <= 1)  // One thread is main
    return noString;
  
	bool num_threadsP = false;
	bool mt_modeP = false;
	{
	  const string blast_help (tmp + "/blast_help");
    exec (fullProg (blast) + " -help > " + blast_help);
    LineInput f (blast_help);
    while (f. nextLine ())
    {
      trim (f. line);
      if (contains (f. line, "-num_threads "))
        num_threadsP = true;
      if (contains (f. line, "-mt_mode "))
        mt_modeP = true;
    }
  }
  
  if (! num_threadsP)
    return noString;
  
  string s ("  -num_threads " + to_string (t));
  
  bool mt_mode_works = true;
#ifdef __APPLE__
  {
    mt_mode_works = false;
    const string blast_version (tmp + "/blast_version");
    exec (fullProg (blast) + " -version > " + blast_version);
    LineInput f (blast_version);
    while (f. nextLine ())
    {
      trim (f. line);
      const string prefix (blast + ": ");
      if (isLeft (f. line, prefix))
      {
        trimSuffix (f. line, "+");
        Istringstream iss;
        iss. reset (f. line. substr (prefix. size ()));
        const SoftwareVersion v (iss);
      //PRINT (v);  
        iss. reset ("2.13.0");  // PD-4560
        const SoftwareVersion threshold (iss);;
      //PRINT (threshold);  
        mt_mode_works = (threshold <= v);
      }
      break;
    }
  }
#endif

  if (mt_modeP && mt_mode_works)  
    s += "  -mt_mode 1";
    
  return s;
}

// Assembly:
subq $0x558, %rsp            # imm = 0x558
movq %rdi, 0x50(%rsp)
movq %rdi, %rax
movq %rax, 0x58(%rsp)
movq %rdi, 0x550(%rsp)
movq %rsi, 0x548(%rsp)
movq %rdx, 0x540(%rsp)
movq %rcx, 0x538(%rsp)
movq 0x548(%rsp), %rax
movq %rax, 0x60(%rsp)
callq 0xc090
movq 0x60(%rsp), %rdi
movl $0x0, (%rax)
addq $0x168, %rdi            # imm = 0x168
callq 0xcc10
testb $0x1, %al
jne 0x72a96
jmp 0x72d1d
callq 0xc8c0
cmpl $0x0, %eax
jne 0x72d13
leaq 0x497(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xcd00
movq 0x48(%rsp), %rdx
leaq 0x5af57(%rip), %rsi     # 0xcda19
leaq 0x498(%rsp), %rdi
callq 0x29fd0
jmp 0x72ad1
leaq 0x460(%rsp), %rdi
movl $0x1148, %esi           # imm = 0x1148
callq 0x2ded0
jmp 0x72ae5
leaq 0x4b8(%rsp), %rdi
leaq 0x498(%rsp), %rsi
leaq 0x460(%rsp), %rdx
callq 0x2dde0
jmp 0x72b04
leaq 0x59096(%rip), %rdx     # 0xcbba1
leaq 0x4d8(%rsp), %rdi
leaq 0x4b8(%rsp), %rsi
callq 0x2a2f0
jmp 0x72b22
leaq 0x41f(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xcd00
movq 0x40(%rsp), %rdx
leaq 0x5d391(%rip), %rsi     # 0xcfed1
leaq 0x420(%rsp), %rdi
callq 0x29fd0
jmp 0x72b4f
leaq 0x5aec0(%rip), %rdx     # 0xcda16
leaq 0x440(%rsp), %rdi
leaq 0x420(%rsp), %rsi
callq 0x2a2f0
jmp 0x72b6d
leaq 0x4f8(%rsp), %rdi
leaq 0x4d8(%rsp), %rsi
leaq 0x440(%rsp), %rdx
callq 0x2dde0
jmp 0x72b8c
leaq 0x5d287(%rip), %rdx     # 0xcfe1a
leaq 0x518(%rsp), %rdi
leaq 0x4f8(%rsp), %rsi
callq 0x2a2f0
jmp 0x72baa
leaq 0x518(%rsp), %rdi
callq 0x3e9b0
jmp 0x72bb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72d01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72cf4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72ce7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72cda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72cc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72cb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72ca6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72c99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
leaq 0x518(%rsp), %rdi
callq 0xce98
leaq 0x4f8(%rsp), %rdi
callq 0xce98
leaq 0x440(%rsp), %rdi
callq 0xce98
leaq 0x420(%rsp), %rdi
callq 0xce98
leaq 0x41f(%rsp), %rdi
callq 0xc7a0
leaq 0x4d8(%rsp), %rdi
callq 0xce98
leaq 0x4b8(%rsp), %rdi
callq 0xce98
leaq 0x460(%rsp), %rdi
callq 0xce98
leaq 0x498(%rsp), %rdi
callq 0xce98
leaq 0x497(%rsp), %rdi
callq 0xc7a0
jmp 0x731d3
movl $0x1, %edi
callq 0xc8d0
leaq 0x93a54(%rip), %rdi     # 0x106778
leaq 0x538(%rsp), %rsi
callq 0x2fb00
movq (%rax), %rax
movq %rax, 0x410(%rsp)
cmpq $0x1, 0x410(%rsp)
ja 0x72d5d
movq 0x50(%rsp), %rdi
leaq 0x93f45(%rip), %rsi     # 0x106c98
callq 0xc320
jmp 0x731c6
movq 0x60(%rsp), %rsi
movb $0x0, 0x40f(%rsp)
movb $0x0, 0x40e(%rsp)
addq $0x168, %rsi            # imm = 0x168
leaq 0x5d1a8(%rip), %rdx     # 0xcff28
leaq 0x3e8(%rsp), %rdi
callq 0x2d9a0
movq 0x60(%rsp), %rsi
movq 0x540(%rsp), %rdx
leaq 0x388(%rsp), %rdi
callq 0x71360
jmp 0x72da9
leaq 0x5d184(%rip), %rdx     # 0xcff34
leaq 0x3a8(%rsp), %rdi
leaq 0x388(%rsp), %rsi
callq 0x2a2f0
jmp 0x72dc7
leaq 0x3c8(%rsp), %rdi
leaq 0x3a8(%rsp), %rsi
leaq 0x3e8(%rsp), %rdx
callq 0x2e220
jmp 0x72de6
leaq 0x93eab(%rip), %rsi     # 0x106c98
leaq 0x3c8(%rsp), %rdi
callq 0x4a960
jmp 0x72dfc
leaq 0x3c8(%rsp), %rdi
callq 0xce98
leaq 0x3a8(%rsp), %rdi
callq 0xce98
leaq 0x388(%rsp), %rdi
callq 0xce98
leaq 0xe0(%rsp), %rdi
leaq 0x3e8(%rsp), %rsi
xorl %edx, %edx
callq 0x2f200
jmp 0x72e3c
jmp 0x72e3e
leaq 0xe0(%rsp), %rdi
callq 0x3d390
movb %al, 0x3f(%rsp)
jmp 0x72e51
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x72e5e
jmp 0x730a5
leaq 0x348(%rsp), %rdi
callq 0x73800
jmp 0x72e6d
leaq 0x348(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xcd00
movq 0x30(%rsp), %rdx
leaq 0x5d0b2(%rip), %rsi     # 0xcff4a
leaq 0xc0(%rsp), %rdi
callq 0x29fd0
jmp 0x72ea7
movq 0x28(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x2f5d0
movb %al, 0x27(%rsp)
jmp 0x72ebf
leaq 0xc0(%rsp), %rdi
callq 0xce98
leaq 0xbf(%rsp), %rdi
callq 0xc7a0
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x72ee6
jmp 0x72fda
movb $0x1, 0x40f(%rsp)
jmp 0x72fda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x730ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72f66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72f59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
leaq 0x3c8(%rsp), %rdi
callq 0xce98
leaq 0x3a8(%rsp), %rdi
callq 0xce98
leaq 0x388(%rsp), %rdi
callq 0xce98
jmp 0x730ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x730df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x72fc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0xce98
leaq 0xbf(%rsp), %rdi
callq 0xc7a0
jmp 0x730df
leaq 0x348(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x97(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xcd00
movq 0x18(%rsp), %rdx
leaq 0x5cf39(%rip), %rsi     # 0xcff3e
leaq 0x98(%rsp), %rdi
callq 0x29fd0
jmp 0x73014
movq 0x10(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x2f5d0
movb %al, 0xf(%rsp)
jmp 0x7302c
leaq 0x98(%rsp), %rdi
callq 0xce98
leaq 0x97(%rsp), %rdi
callq 0xc7a0
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x73050
jmp 0x730a0
movb $0x1, 0x40e(%rsp)
jmp 0x730a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
jmp 0x73091
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
leaq 0x98(%rsp), %rdi
callq 0xce98
leaq 0x97(%rsp), %rdi
callq 0xc7a0
jmp 0x730df
jmp 0x72e3e
leaq 0xe0(%rsp), %rdi
callq 0x2f490
leaq 0x3e8(%rsp), %rdi
callq 0xce98
testb $0x1, 0x40f(%rsp)
jne 0x730fe
movq 0x50(%rsp), %rdi
leaq 0x93bc3(%rip), %rsi     # 0x106c98
callq 0xc320
jmp 0x731c6
leaq 0xe0(%rsp), %rdi
callq 0x2f490
leaq 0x3e8(%rsp), %rdi
callq 0xce98
jmp 0x731d3
movb $0x0, 0x96(%rsp)
movq 0x410(%rsp), %rsi
leaq 0x70(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x2bf10
movq 0x50(%rsp), %rdi
movq (%rsp), %rdx
leaq 0x5ce1c(%rip), %rsi     # 0xcff48
callq 0x2a340
jmp 0x73133
leaq 0x70(%rsp), %rdi
callq 0xce98
movb $0x1, 0x6f(%rsp)
testb $0x1, 0x40e(%rsp)
je 0x731a8
testb $0x1, 0x6f(%rsp)
je 0x731a8
movq 0x50(%rsp), %rdi
leaq 0x5cdf9(%rip), %rsi     # 0xcff58
callq 0xc6e0
jmp 0x73166
jmp 0x731a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
leaq 0x70(%rsp), %rdi
callq 0xce98
jmp 0x731d3
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x488(%rsp)
movl %eax, 0x484(%rsp)
callq 0xce98
jmp 0x731d3
movb $0x1, 0x96(%rsp)
testb $0x1, 0x96(%rsp)
jne 0x731c4
movq 0x50(%rsp), %rdi
callq 0xce98
jmp 0x731c6
movq 0x58(%rsp), %rax
addq $0x558, %rsp            # imm = 0x558
retq
movq 0x488(%rsp), %rdi
callq 0xccf0