// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdx, -0x148(%rbp)
movq %rsi, -0x150(%rbp)
movq %rdi, %rdx
movq -0x148(%rbp), %rdi
movq %rdx, -0x140(%rbp)
movb %r9b, %al
movq %rdx, %r9
movq %r9, -0x138(%rbp)
movq 0x18(%rbp), %r9
movq %r9, -0x130(%rbp)
movq 0x10(%rbp), %r9
movq %r9, -0x128(%rbp)
movq %rdx, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
movslq -0x1c(%rbp), %rax
movq %rax, -0x30(%rbp)
callq 0x12b60
cmpq $0x0, %rax
jne 0x12067
movq -0x150(%rbp), %rsi
movq -0x140(%rbp), %rdi
callq 0x4280
jmp 0x1241a
testb $0x1, -0x21(%rbp)
je 0x1209d
movq -0x128(%rbp), %rdi
callq 0x4630
movq -0x130(%rbp), %rdi
movq %rax, -0x158(%rbp)
callq 0x4630
movq %rax, %rcx
movq -0x158(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x48(%rbp)
jmp 0x1209f
leaq -0x68(%rbp), %rdi
callq 0x45e0
movq -0x148(%rbp), %rdi
callq 0x12b80
movq %rax, -0x70(%rbp)
movq -0x148(%rbp), %rdi
callq 0x8af0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x12bb0
testb $0x1, %al
jne 0x120de
jmp 0x122b6
leaq -0x70(%rbp), %rdi
callq 0x8b50
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x41e0
jmp 0x120f8
movb -0x21(%rbp), %al
movb $0x0, -0xe9(%rbp)
movb $0x0, -0xea(%rbp)
testb $0x1, %al
je 0x12173
movq -0x128(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
leaq -0x98(%rbp), %rdx
callq 0x12c30
jmp 0x12129
movq -0x130(%rbp), %rdx
movb $0x1, -0xe9(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x12be0
jmp 0x1214c
movq -0x150(%rbp), %rdi
movb $0x1, -0xea(%rbp)
movq -0x30(%rbp), %rdx
leaq -0xc8(%rbp), %rsi
callq 0x4790
movq %rax, -0x160(%rbp)
jmp 0x12191
movq -0x150(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq -0x98(%rbp), %rsi
callq 0x4790
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x38(%rbp)
testb $0x1, -0xea(%rbp)
jne 0x121a7
jmp 0x121b3
leaq -0xc8(%rbp), %rdi
callq 0x47a8
testb $0x1, -0xe9(%rbp)
jne 0x121be
jmp 0x121ca
leaq -0xe8(%rbp), %rdi
callq 0x47a8
movq -0x148(%rbp), %rdi
callq 0x12b80
movq %rax, -0xf8(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x8ac0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x161(%rbp)
jne 0x1220d
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
setb %al
movb %al, -0x161(%rbp)
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x12219
jmp 0x1228b
leaq -0x68(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4060
jmp 0x1222b
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x1228b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1240f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x122a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
testb $0x1, -0xe9(%rbp)
jne 0x1227d
jmp 0x12289
leaq -0xe8(%rbp), %rdi
callq 0x47a8
jmp 0x122a5
leaq -0x98(%rbp), %rdi
callq 0x47a8
leaq -0x70(%rbp), %rdi
callq 0xd550
jmp 0x120b8
leaq -0x98(%rbp), %rdi
callq 0x47a8
jmp 0x1240f
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $-0x1, -0x30(%rbp)
jne 0x122d4
movl $0x2, -0xfc(%rbp)
jmp 0x12392
movq -0x148(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xcc50
movq %rax, -0x170(%rbp)
jmp 0x122ed
movq -0x170(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x41e0
jmp 0x12302
movq -0x30(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x4630
movq %rax, -0x178(%rbp)
testb $0x1, -0x21(%rbp)
je 0x12330
movq -0x48(%rbp), %rax
movq %rax, -0x188(%rbp)
jmp 0x1233b
xorl %eax, %eax
movq %rax, -0x188(%rbp)
jmp 0x1233b
movq -0x180(%rbp), %rsi
movq -0x150(%rbp), %rdi
movq -0x178(%rbp), %rdx
movq -0x188(%rbp), %rax
addq %rax, %rdx
leaq -0x120(%rbp), %rcx
callq 0x4180
jmp 0x12368
leaq -0x120(%rbp), %rdi
callq 0x42d0
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x47a8
movl $0x0, -0xfc(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x47a8
movl -0xfc(%rbp), %eax
testl %eax, %eax
je 0x123a9
jmp 0x123a7
jmp 0x123dc
jmp 0x123ab
movb $0x1, %al
cmpl $0x0, -0x20(%rbp)
movb %al, -0x189(%rbp)
je 0x123ce
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
cmpl -0x20(%rbp), %eax
setl %al
movb %al, -0x189(%rbp)
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x1209f
movq -0x150(%rbp), %rsi
movq -0x140(%rbp), %rdi
callq 0x4280
jmp 0x1241a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x47a8
leaq -0x68(%rbp), %rdi
callq 0x47a8
jmp 0x1242a
movq -0x138(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x46c0
nopw %cs:(%rax,%rax)