user: Converte this assembly snippet into its equivalent C code:

```asm
<repl_str>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0xa8,%rsp
  mov    %rdi,-0x98(%rbp)
  mov    %rsi,-0xa0(%rbp)
  mov    %rdx,-0xa8(%rbp)
  movq   $0x10,-0x90(%rbp)
  movq   $0x2,-0x40(%rbp)
  movq   $0x100000,-0x38(%rbp)
  movq   $0x0,-0x80(%rbp)
  mov    -0x98(%rbp),%rax
  mov    %rax,-0x78(%rbp)
  movq   $0x0,-0x68(%rbp)
  movq   $0x0,-0x60(%rbp)
  movq   $0x0,-0x58(%rbp)
  mov    -0xa0(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  mov    %rax,-0x30(%rbp)
  jmp    L163
L3:
  addq   $0x1,-0x68(%rbp)
  mov    -0x58(%rbp),%rax
  cmp    -0x68(%rbp),%rax
  jae    L161
  mov    -0x90(%rbp),%rax
  add    %rax,-0x58(%rbp)
  mov    -0x58(%rbp),%rax
  shl    $0x2,%eax
  mov    %eax,%edx
  mov    -0x60(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x60(%rbp)
  cmpq   $0x0,-0x60(%rbp)
  je     L75
  mov    -0x90(%rbp),%rax
  imul   -0x40(%rbp),%rax
  mov    %rax,-0x90(%rbp)
  mov    -0x90(%rbp),%rax
  cmp    -0x38(%rbp),%rax
  jbe    L161
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x90(%rbp)
L161:
  mov    -0x28(%rbp),%rax
  sub    -0x98(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x68(%rbp),%rax
  shl    $0x2,%rax
  lea    -0x4(%rax),%rcx
  mov    -0x60(%rbp),%rax
  add    %rcx,%rax
  mov    %edx,(%rax)
  mov    -0x28(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x78(%rbp)
L163:
  mov    -0xa0(%rbp),%rdx
  mov    -0x78(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strstr@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  jne    L3
  mov    -0x78(%rbp),%rax
  sub    -0x98(%rbp),%rax
  mov    %rax,%rbx
  mov    -0x78(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  add    %rbx,%rax
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x68(%rbp)
  je     L168
  mov    -0xa8(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  mov    %rax,-0x48(%rbp)
  mov    -0x48(%rbp),%rax
  sub    -0x30(%rbp),%rax
  imul   -0x68(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x50(%rbp)
  jmp    L138
L168:
  mov    -0x20(%rbp),%rax
  mov    %rax,-0x50(%rbp)
L138:
  mov    -0x50(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x80(%rbp)
  cmpq   $0x0,-0x80(%rbp)
  je     L107
  cmpq   $0x0,-0x68(%rbp)
  jne    L149
  mov    -0x98(%rbp),%rdx
  mov    -0x80(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcpy@plt>
  jmp    L144
L149:
  mov    -0x80(%rbp),%rax
  mov    %rax,-0x88(%rbp)
  mov    -0x60(%rbp),%rax
  mov    (%rax),%eax
  movslq %eax,%rdx
  mov    -0x98(%rbp),%rcx
  mov    -0x88(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x60(%rbp),%rax
  mov    (%rax),%eax
  cltq
  add    %rax,-0x88(%rbp)
  movq   $0x0,-0x70(%rbp)
  jmp    L25
L145:
  mov    -0x48(%rbp),%rdx
  mov    -0xa8(%rbp),%rcx
  mov    -0x88(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x48(%rbp),%rax
  add    %rax,-0x88(%rbp)
  mov    -0x70(%rbp),%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x60(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  movslq %eax,%rdx
  mov    -0x30(%rbp),%rax
  add    %rax,%rdx
  mov    -0x98(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x78(%rbp)
  mov    -0x68(%rbp),%rax
  sub    $0x1,%rax
  cmp    %rax,-0x70(%rbp)
  je     L106
  mov    -0x70(%rbp),%rax
  add    $0x1,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x60(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  cltq
  jmp    L16
L106:
  mov    -0x20(%rbp),%rax
L16:
  mov    -0x70(%rbp),%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x60(%rbp),%rdx
  add    %rcx,%rdx
  mov    (%rdx),%edx
  movslq %edx,%rdx
  sub    %rdx,%rax
  sub    -0x30(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x18(%rbp),%rdx
  mov    -0x78(%rbp),%rcx
  mov    -0x88(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x18(%rbp),%rax
  add    %rax,-0x88(%rbp)
  addq   $0x1,-0x70(%rbp)
L25:
  mov    -0x70(%rbp),%rax
  cmp    -0x68(%rbp),%rax
  jb     L145
  mov    -0x80(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  jmp    L144
L75:
  nop
  jmp    L144
L107:
  nop
L144:
  cmpq   $0x0,-0x60(%rbp)
  jne    L41
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L41:
  mov    -0x80(%rbp),%rax
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
char *repl_str(const char *str, const char *old, const char *new) {
  size_t cache_sz_inc = 16;
  const size_t cache_sz_inc_factor = 2;
  const size_t cache_sz_inc_max = 1048576;
  char *pret, *ret = NULL;
  const char *pstr2, *pstr = str;
  size_t i, count = 0;
  ptrdiff_t *pos_cache = NULL;
  size_t cache_sz = 0;
  size_t cpylen, orglen, retlen, newlen, oldlen = strlen(old);
  while ((pstr2 = strstr(pstr, old)) != NULL) {
    count++;
    if (cache_sz < count) {
      cache_sz += cache_sz_inc;
      pos_cache = realloc(pos_cache, sizeof(*pos_cache) * cache_sz);
      if (pos_cache == NULL) {
        goto end_repl_str;
      }
      cache_sz_inc *= cache_sz_inc_factor;
      if (cache_sz_inc > cache_sz_inc_max) {
        cache_sz_inc = cache_sz_inc_max;
      }
    }
    pos_cache[count - 1] = pstr2 - str;
    pstr = pstr2 + oldlen;
  }
  orglen = pstr - str + strlen(pstr);
  if (count > 0) {
    newlen = strlen(new);
    retlen = orglen + (newlen - oldlen) * count;
  } else
    retlen = orglen;
  ret = malloc(retlen + 1);
  if (ret == NULL) {
    goto end_repl_str;
  }
  if (count == 0) {
    strcpy(ret, str);
  } else {
    pret = ret;
    memcpy(pret, str, pos_cache[0]);
    pret += pos_cache[0];
    for (i = 0; i < count; i++) {
      memcpy(pret, new, newlen);
      pret += newlen;
      pstr = str + pos_cache[i] + oldlen;
      cpylen = (i == count - 1 ? orglen : pos_cache[i + 1]) - pos_cache[i] - oldlen;
      memcpy(pret, pstr, cpylen);
      pret += cpylen;
    }
    ret[retlen] = '\0';
  }
end_repl_str:
  if (!pos_cache)
    free(pos_cache);
  return ret;
}
```