// File: ncbi[P]amr/common.cpp
// Function: Common_sp::(anonymous namespace)::getStack[abi:cxx11]()
string getStack ()
// Print function names:   // --> exec() ??
{
#ifdef _MSC_VER
  return "Stack trace is not implemented";
#else
  string s;
  constexpr size_t size = 100;  // PAR
  void* buffer [size];
  const int nptrs = backtrace (buffer, size);
  if (nptrs <= 1)  // *this function must be the first one
    errorExit (("backtrace size is " + to_string (nptrs)). c_str ());
  char** strings = backtrace_symbols (buffer, nptrs);
  if (strings /*&& ! which ("addr2line"). empty ()*/) 
  {
    FOR_START /*FOR_REV_END*/ (int, i, 1, nptrs)  // From top to bottom of the stack
      s += string (strings [i]) + "\n";  
    s += "Use: addr2line -f -C -e " + programArgs [0] + "  -a <address>";
  //free (strings);
  }
  else
    s = "Cannot get stack trace";

  return s;
#endif
}

// Assembly:
subq $0x458, %rsp            # imm = 0x458
movq %rdi, 0x18(%rsp)
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq %rdi, 0x450(%rsp)
movb $0x0, 0x44f(%rsp)
callq 0xca10
movq $0x64, 0x440(%rsp)
leaq 0x120(%rsp), %rdi
movl $0x64, %esi
callq 0xcac0
movl %eax, 0x2c(%rsp)
jmp 0x3eb0d
movl 0x2c(%rsp), %eax
movl %eax, 0x11c(%rsp)
cmpl $0x1, 0x11c(%rsp)
jg 0x3ebd5
movl 0x11c(%rsp), %esi
leaq 0xc8(%rsp), %rdi
callq 0x2ded0
jmp 0x3eb3c
leaq 0x91435(%rip), %rsi     # 0xcff78
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rdx
callq 0x2a340
jmp 0x3eb5a
leaq 0xe8(%rsp), %rdi
callq 0xc300
movq %rax, %rdi
xorl %esi, %esi
callq 0x3daf0
jmp 0x3eb73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x3ee0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x3ebc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xce98
leaq 0xc8(%rsp), %rdi
callq 0xce98
jmp 0x3ee0c
leaq 0x120(%rsp), %rdi
movl 0x11c(%rsp), %esi
callq 0xcaf0
movq %rax, 0xc0(%rsp)
cmpq $0x0, 0xc0(%rsp)
je 0x3edce
movl $0x1, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
cmpl 0x11c(%rsp), %eax
jge 0x3ed29
movq 0xc0(%rsp), %rax
movslq 0xbc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
leaq 0x77(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xcd00
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x78(%rsp), %rdi
callq 0x29fd0
jmp 0x3ec5d
leaq 0x90db9(%rip), %rdx     # 0xcfa1d
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2a2f0
jmp 0x3ec78
movq 0x18(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0xc960
jmp 0x3ec8c
leaq 0x98(%rsp), %rdi
callq 0xce98
leaq 0x78(%rsp), %rdi
callq 0xce98
leaq 0x77(%rsp), %rdi
callq 0xc7a0
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x3ec0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x3ed1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x3ed10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0xce98
leaq 0x78(%rsp), %rdi
callq 0xce98
leaq 0x77(%rsp), %rdi
callq 0xc7a0
jmp 0x3ee0c
leaq 0xc7f10(%rip), %rdi     # 0x106c40
xorl %eax, %eax
movl %eax, %esi
callq 0x35ee0
movq %rax, %rdx
leaq 0x91248(%rip), %rsi     # 0xcff8b
leaq 0x30(%rsp), %rdi
callq 0x2a1c0
jmp 0x3ed4f
leaq 0x9124e(%rip), %rdx     # 0xcffa4
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2a2f0
jmp 0x3ed67
movq 0x18(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xc960
jmp 0x3ed78
leaq 0x50(%rsp), %rdi
callq 0xce98
leaq 0x30(%rsp), %rdi
callq 0xce98
jmp 0x3ede3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
jmp 0x3edc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xce98
leaq 0x30(%rsp), %rdi
callq 0xce98
jmp 0x3ee0c
movq 0x18(%rsp), %rdi
leaq 0x911d9(%rip), %rsi     # 0xcffb3
callq 0xca00
jmp 0x3ede1
jmp 0x3ede3
movb $0x1, 0x44f(%rsp)
testb $0x1, 0x44f(%rsp)
jne 0x3edff
movq 0x18(%rsp), %rdi
callq 0xce98
movq 0x20(%rsp), %rax
addq $0x458, %rsp            # imm = 0x458
retq
movq 0x18(%rsp), %rdi
callq 0xce98
movq 0x110(%rsp), %rdi
callq 0xccf0
nopw %cs:(%rax,%rax)