// File: /workspace/github_cpp_makefile_star2_O1/gpertea[P]gclib/GStr.cpp
// Function: GStr::replace(char const*, char const*)
GStr&  GStr::replace(const char *rfrom, const char* rto) {
 if (length() == 0 || rfrom==NULL || strlen(rfrom)==0)
        return *this;
 unsigned int l=strlen(rfrom);
 unsigned int tl= (rto==NULL)?0:strlen(rto);
 make_unique(); //edit operation ahead
 char* p;
 char* dest;
 char* newdest=NULL;
 char* s = my_data->chars;
 if (tl!=l) { //reallocation
   if (tl>l) {  //possible enlargement
       GMALLOC(newdest, length()*(tl-l+1)+1);
       }
      else  {//delete or replace with a shorter string
       GMALLOC(newdest, length() + 1);
       }
      dest=newdest;
      if (tl==0) {//deletion
           while ((p=strstr(s,rfrom))!=NULL) {
               //rfrom found at position p
                memcpy(dest,s,p-s);
                dest+=p-s;
                s+=p-s+l; //s positioned in string after rfrom
                }
           //no more occurences, copy the remaining string
           strcpy(dest, s);
          }
        else { //replace with another string
          while ((p=strstr(s,rfrom))!=NULL) {
              memcpy(dest,s,p-s); //copy up rto the match
              dest+=p-s;
              memcpy(dest,rto,tl); //put the replacement string
              dest+=tl;
              s+=p-s+l;
              }
          //not found any more, copy rto end of string
          strcpy(dest, s);
          }
       Data* data=new_data(newdest);
       replace_data(data);
       GFREE(newdest);
       }
  else { //inplace editing: no need rto reallocate
    while ((p=strstr(s,rfrom))!=NULL) {
        memcpy(p,rto,l);
        s+=p-s+l;
        }
   }
 return *this;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r15
testq %rsi, %rsi
je 0x6a46
movq 0x20(%r15), %rax
cmpl $0x0, 0x8(%rax)
je 0x6a46
movq %rdx, %rbp
movq %rsi, %r14
movq %rsi, %rdi
callq 0x2140
testq %rax, %rax
je 0x6a46
movq %rax, %r12
testq %rbp, %rbp
je 0x68ae
movq %rbp, %rdi
callq 0x2140
movq %rax, %rbx
jmp 0x68b0
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x4b0e
movq 0x20(%r15), %rax
leaq 0xc(%rax), %r13
movl %ebx, %ecx
subl %r12d, %ecx
jne 0x690a
movq %r13, %rdi
movq %r14, %rsi
callq 0x2090
testq %rax, %rax
je 0x6a46
movq %rax, %rbx
movl %r12d, %r12d
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x21e0
addq %r12, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2090
movq %rax, %rbx
testq %rax, %rax
jne 0x68e1
jmp 0x6a46
movl 0x8(%rax), %eax
movq %r12, 0x8(%rsp)
movq %rbx, (%rsp)
jbe 0x6925
incl %ecx
imull %ecx, %eax
incl %eax
je 0x6929
movl %eax, %edi
jmp 0x6931
incl %eax
jne 0x692e
xorl %r12d, %r12d
jmp 0x6939
movslq %eax, %rdi
callq 0x2330
movq %rax, %r12
testq %r12, %r12
jne 0x694c
leaq 0x76db(%rip), %rdi      # 0xe020
xorl %eax, %eax
callq 0x289c
movq %r13, %rdi
movq %r14, %rsi
callq 0x2090
movq %rax, %rbx
cmpl $0x0, (%rsp)
movq %r15, 0x18(%rsp)
movq %r12, 0x10(%rsp)
je 0x69ce
testq %rbx, %rbx
je 0x69c9
movq %rbp, 0x20(%rsp)
movl (%rsp), %ebp
movl 0x8(%rsp), %eax
movq %rax, (%rsp)
movq %r12, %r15
movq %rbx, %r12
subq %r13, %r12
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x21e0
addq %r15, %r12
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq %rbp, %rdx
callq 0x21e0
addq %rbp, %r12
movq %rbx, %r13
addq (%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x2090
movq %rax, %rbx
movq %r12, %r15
testq %rax, %rax
jne 0x6982
movq %r12, %rdi
jmp 0x6a12
testq %rbx, %rbx
je 0x6a0c
movl 0x8(%rsp), %ebp
movq %r12, %r15
movq %rbx, %r12
subq %r13, %r12
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x21e0
addq %r12, %r15
movq %rbx, %r13
addq %rbp, %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x2090
movq %rax, %rbx
testq %rax, %rax
jne 0x69da
jmp 0x6a0f
movq %r12, %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x2220
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x498e
movq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x4b54
testq %rbx, %rbx
je 0x6a46
movq %rbx, %rdi
callq 0x22e0
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq