user: 请从给定的汇编指令推导出C源代码：

```asm
<replace_str>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x78,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    %rsi,-0x70(%rbp)
  mov    %rdx,-0x78(%rbp)
  mov    -0x70(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  mov    %rax,-0x38(%rbp)
  mov    -0x78(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  mov    %rax,-0x30(%rbp)
  mov    -0x38(%rbp),%rax
  cmp    -0x30(%rbp),%rax
  je     L43
  movq   $0x0,-0x48(%rbp)
  mov    -0x68(%rbp),%rax
  mov    %rax,-0x50(%rbp)
  jmp    L24
L52:
  addq   $0x1,-0x48(%rbp)
  mov    -0x28(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x50(%rbp)
L24:
  mov    -0x70(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strstr@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  jne    L52
  mov    -0x50(%rbp),%rax
  sub    -0x68(%rbp),%rax
  mov    %rax,%rbx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  add    %rbx,%rax
  mov    %rax,%rdx
  mov    -0x30(%rbp),%rax
  sub    -0x38(%rbp),%rax
  imul   -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x40(%rbp)
  jmp    L62
L43:
  mov    -0x68(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  mov    %rax,-0x40(%rbp)
L62:
  mov    -0x40(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L58
  mov    $0x0,%eax
  jmp    L59
L58:
  mov    -0x20(%rbp),%rax
  mov    %rax,-0x58(%rbp)
  mov    -0x68(%rbp),%rax
  mov    %rax,-0x50(%rbp)
  jmp    L6
L47:
  mov    -0x28(%rbp),%rax
  sub    -0x50(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x18(%rbp),%rdx
  mov    -0x50(%rbp),%rcx
  mov    -0x58(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x18(%rbp),%rax
  add    %rax,-0x58(%rbp)
  mov    -0x30(%rbp),%rdx
  mov    -0x78(%rbp),%rcx
  mov    -0x58(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x30(%rbp),%rax
  add    %rax,-0x58(%rbp)
  mov    -0x28(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x50(%rbp)
L6:
  mov    -0x70(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strstr@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  jne    L47
  mov    -0x50(%rbp),%rdx
  mov    -0x58(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcpy@plt>
  mov    -0x20(%rbp),%rax
L59:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
char *replace_str(const char *str, const char *old, const char *new) {
  char *ret, *r;
  const char *p, *q;
  size_t oldlen = strlen(old);
  size_t count, retlen, newlen = strlen(new);
  if (oldlen != newlen) {
    for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen)
      count++;
    retlen = p - str + strlen(p) + count * (newlen - oldlen);
  } else
    retlen = strlen(str);
  if ((ret = malloc(retlen + 1)) == NULL)
    return NULL;
  for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) {
    ptrdiff_t l = q - p;
    memcpy(r, p, l);
    r += l;
    memcpy(r, new, newlen);
    r += newlen;
  }
  strcpy(r, p);
  return ret;
}
```