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

```asm
<str_replace>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r12
  push   %rbx
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %edx,-0x44(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %r8,-0x58(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  je     L107
  cmpq   $0x0,-0x40(%rbp)
  je     L107
  cmpl   $0x0,-0x44(%rbp)
  jle    L107
  cmpq   $0x0,-0x50(%rbp)
  je     L107
  cmpq   $0x0,-0x58(%rbp)
  jne    L74
L107:
  mov    $0x0,%eax
  jmp    L93
L74:
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cmp    %eax,%ebx
  jne    L57
  mov    -0x58(%rbp),%rdx
  mov    -0x50(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L57
  mov    $0x0,%eax
  jmp    L93
L57:
  mov    -0x44(%rbp),%edx
  mov    -0x38(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  jmp    L98
L4:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%r12d
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  sub    %eax,%ebx
  mov    %ebx,%edx
  lea    (%r12,%rdx,1),%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  mov    -0x20(%rbp),%rax
  sub    -0x28(%rbp),%rax
  mov    %eax,%edx
  mov    -0x28(%rbp),%rcx
  mov    -0x18(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x20(%rbp),%rax
  sub    -0x28(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x58(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  movslq %eax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rax,%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x44(%rbp),%edx
  mov    -0x18(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x40(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L98:
  mov    -0x50(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strstr@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L4
  mov    -0x40(%rbp),%rax
L93:
  add    $0x50,%rsp
  pop    %rbx
  pop    %r12
  pop    %rbp
  ret
```

assistant: ```c
char *str_replace(const char *src, char *buf, int len, const char *oldstr, const char *newstr) {
  char *needle;
  char *tmp;
  const char *replaced;
  if (src == NULL || buf == NULL || len <= 0 || oldstr == NULL || newstr == NULL) {
    return NULL;
  }
  if (strlen(oldstr) == strlen(newstr) && strcmp(oldstr, newstr) == 0) {
    return NULL;
  }
  strncpy(buf, src, len);
  replaced = src;
  while ((needle = strstr(replaced, oldstr))) {
    tmp = (char *)malloc(strlen(replaced) + (strlen(newstr) - strlen(oldstr)) + 1);
    strncpy(tmp, replaced, needle - replaced);
    tmp[needle - replaced] = '\0';
    strcat(tmp, newstr);
    strcat(tmp, needle + strlen(oldstr));
    strncpy(buf, tmp, len);
    replaced = buf;
    free(tmp);
  }
  return buf;
}
```