// File: /workspace/github_cpp_makefile_star2_O2/gasparfm[P]anapache/lib/gcommon/gstr.cpp
// Function: GCommon::replace(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>, int, int, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string replace(std::string source, std::map<std::string,std::string>strMap, int offset, int times, bool delimiters, std::string before, std::string after)
  {
    int total = 0;
    std::string::size_type pos=offset;
    std::string::size_type newPos;
    std::string::size_type lowerPos;
    std::string::size_type delsize;

    if (strMap.size() == 0)
      return source;

    if (delimiters)
      delsize = before.length() + after.length();

    do
      {
	std::string rep;
	for (auto i=strMap.begin(); i!=strMap.end(); ++i)
	  {
	    auto fromStr = i->first;
	    newPos = (delimiters)?
	      source.find(before + fromStr + after, pos):
	      source.find(fromStr, pos);

	    if ( (i==strMap.begin()) || (newPos<lowerPos) )
	      {
		rep = fromStr;
		lowerPos = newPos;
	      }
	  }

	pos = lowerPos;
	if (pos == std::string::npos)
	  break;

	std::string toStr = strMap[rep];
	source.replace(pos, rep.length()+((delimiters)?delsize:0), toStr);
	pos+=toStr.size();

      } while ( (times==0) || (++total<times) );

    return source;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r8d, 0x4(%rsp)
movq %rdi, %rbx
movq %rdx, 0x18(%rsp)
cmpq $0x0, 0x28(%rdx)
je 0x7d1a
movq 0x108(%rsp), %rax
movq 0x100(%rsp), %rdx
testb %r9b, %r9b
movq %rbx, 0x58(%rsp)
movq %rsi, 0x8(%rsp)
movl %r9d, 0x2c(%rsp)
je 0x7d22
movq $0x0, 0x20(%rsp)
movq 0x8(%rax), %rax
addq 0x8(%rdx), %rax
movq %rax, 0x30(%rsp)
jmp 0x7d34
movq %rbx, %rdi
jmp 0x7ecb
movq $0x0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movslq %ecx, %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
leaq 0x68(%rsp), %r13
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
andq $0x0, 0x40(%rsp)
movb $0x0, 0x48(%rsp)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rbp
cmpq 0x60(%rsp), %rbp
je 0x7e35
leaq 0x20(%rbp), %rsi
movq %r13, %rdi
callq 0x3460
cmpb $0x0, 0x2c(%rsp)
je 0x7de8
leaq 0x88(%rsp), %r12
movq %r12, %rdi
movq 0x100(%rsp), %rsi
movq %r13, %rdx
callq 0x8226
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq 0x108(%rsp), %rdx
callq 0x8207
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x35c0
movq %rax, %rbx
movq %r15, %rdi
callq 0x35d8
movq %r12, %rdi
callq 0x35d8
jmp 0x7dfd
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
callq 0x35c0
movq %rax, %rbx
movq 0x18(%rsp), %rax
cmpq 0x18(%rax), %rbp
je 0x7e0d
cmpq %r14, %rbx
jae 0x7e1d
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x31f0
movq %rbx, %r14
movq %r13, %rdi
callq 0x35d8
movq %rbp, %rdi
callq 0x3220
movq %rax, %rbp
jmp 0x7d6d
pushq $-0x1
popq %r15
movq %r15, 0x10(%rsp)
cmpq $-0x1, %r14
je 0x7e8d
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x6446
movq %r13, %rdi
movq %rax, %rsi
callq 0x3460
movq 0x40(%rsp), %rdx
addq 0x30(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rcx
callq 0x3130
movq 0x70(%rsp), %rax
addq %r14, %rax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
callq 0x35d8
leaq 0x38(%rsp), %rdi
callq 0x35d8
cmpq $-0x1, %r14
je 0x7ebe
cmpl $0x0, 0x4(%rsp)
je 0x7d4f
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
cmpl 0x4(%rsp), %eax
jl 0x7d4f
movq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x3430
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7efd
jmp 0x7f0c
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x35d8
jmp 0x7f00
jmp 0x7efd
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x35d8
jmp 0x7f0f
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x35d8
movq %rbx, %rdi
callq 0x3530