user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<xstrreplace>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %rdx,-0x58(%rbp)
  movq   $0x0,-0x30(%rbp)
  movq   $0x0,-0x38(%rbp)
  movq   $0x0,-0x28(%rbp)
  cmpq   $0x0,-0x50(%rbp)
  je     L50
  cmpq   $0x0,-0x58(%rbp)
  jne    L39
L50:
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrdup@plt>
  jmp    L12
L39:
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrdup@plt>
  mov    %rax,-0x38(%rbp)
  jmp    L48
L31:
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  mov    %eax,%ebx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  sub    %eax,%ebx
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  add    %ebx,%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <xmalloc@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jne    L63
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <xfree@plt>
  mov    $0x0,%eax
  jmp    L12
L63:
  mov    -0x30(%rbp),%rax
  sub    -0x28(%rbp),%rax
  mov    %eax,%edx
  mov    -0x28(%rbp),%rcx
  mov    -0x38(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  mov    %eax,%edx
  mov    -0x30(%rbp),%rax
  sub    -0x28(%rbp),%rax
  mov    %rax,%rcx
  mov    -0x38(%rbp),%rax
  add    %rax,%rcx
  mov    -0x58(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  mov    %eax,%ebx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  mov    %eax,%edx
  mov    %ebx,%eax
  sub    %edx,%eax
  mov    %eax,%edx
  mov    -0x30(%rbp),%rax
  sub    -0x28(%rbp),%rax
  mov    %eax,%ecx
  mov    %edx,%eax
  sub    %ecx,%eax
  mov    %eax,%r12d
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  movslq %eax,%rdx
  mov    -0x30(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x30(%rbp),%rax
  sub    -0x28(%rbp),%rax
  mov    %rax,%r13
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  cltq
  lea    0x0(%r13,%rax,1),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    %r12d,%edx
  mov    %rbx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  movslq %eax,%rbx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  cltq
  sub    %rax,%rbx
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <xstrlen@plt>
  cltq
  lea    (%rbx,%rax,1),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    $0x1,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <xfree@plt>
L48:
  mov    -0x50(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strstr@plt>
  mov    %rax,-0x30(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  jne    L31
  mov    -0x38(%rbp),%rax
L12:
  add    $0x48,%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %rbp
  ret
```

assistant: ```c
char *xstrreplace(const char *string, const char *substr, const char *replacement) {
  char *tok = NULL;
  char *newstr = NULL;
  char *oldstr = NULL;
  if (substr == NULL || replacement == NULL) {
    return xstrdup(string);
  }
  newstr = xstrdup(string);
  while ((tok = strstr(newstr, substr))) {
    oldstr = newstr;
    newstr = xmalloc(xstrlen(oldstr) - xstrlen(substr) + xstrlen(replacement) + 1);
    if (newstr == NULL) {
      xfree(oldstr);
      return NULL;
    }
    memcpy(newstr, oldstr, tok - oldstr);
    memcpy(newstr + (tok - oldstr), replacement, xstrlen(replacement));
    memcpy(newstr + (tok - oldstr) + xstrlen(replacement), tok + xstrlen(substr), xstrlen(oldstr) - xstrlen(substr) - (tok - oldstr));
    memset(newstr + xstrlen(oldstr) - xstrlen(substr) + xstrlen(replacement), 0, 1);
    xfree(oldstr);
  }
  return newstr;
}
```