user: Translate the below assembly code into C programming language:

```asm
<str_replace>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,%rbp
  test   %rdi,%rdi
  je     L26
  mov    %rsi,%r13
  mov    %rdx,%r15
  mov    %ecx,%r12d
  test   %rsi,%rsi
  lea    D4(%rip),%rax
  cmove  %rax,%r13
  mov    %r13,%rdi
  call   <strlen@plt>
  mov    %eax,%r14d
  mov    %eax,0xc(%rsp)
  test   %eax,%eax
  je     L17
  test   %r15,%r15
  lea    D4(%rip),%rax
  cmove  %rax,%r15
  mov    %r15,%rdi
  call   <strlen@plt>
  mov    %eax,0x10(%rsp)
  mov    %rbp,%rdi
  mov    $0x0,%ebx
  movslq %r14d,%r14
  jmp    L53
L0:
  lea    (%rax,%r14,1),%rdi
  add    $0x1,%ebx
L53:
  mov    %r13,%rsi
  call   <strstr@plt>
  test   %rax,%rax
  jne    L0
  test   %r12d,%r12d
  je     L31
  cmp    %r12d,%ebx
  jbe    L31
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %eax,%edx
  mov    0x10(%rsp),%eax
  sub    0xc(%rsp),%eax
  imul   %r12d,%eax
  lea    0x1(%rax,%rdx,1),%edi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  lea    -0x1(%r12),%r14d
  test   %rax,%rax
  je     L16
L35:
  mov    0x18(%rsp),%r12
  movslq 0x10(%rsp),%rax
  mov    %rax,0x10(%rsp)
L88:
  mov    %r13,%rsi
  mov    %rbp,%rdi
  call   <strstr@plt>
  sub    %rbp,%rax
  mov    %rax,%rbx
  mov    %eax,%edx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  call   <strncpy@plt>
  movslq %ebx,%rdx
  lea    (%rax,%rdx,1),%rdi
  mov    %r15,%rsi
  call   <strcpy@plt>
  mov    0x10(%rsp),%rcx
  lea    (%rax,%rcx,1),%r12
  add    0xc(%rsp),%ebx
  movslq %ebx,%rbx
  add    %rbx,%rbp
  mov    %r14d,%eax
  sub    $0x1,%r14d
  test   %eax,%eax
  jne    L88
L118:
  mov    %rbp,%rsi
  mov    %r12,%rdi
  call   <strcpy@plt>
L16:
  mov    0x18(%rsp),%rax
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L31:
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %eax,%edx
  mov    0x10(%rsp),%eax
  sub    0xc(%rsp),%eax
  imul   %ebx,%eax
  lea    0x1(%rax,%rdx,1),%edi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  mov    %rax,%r12
  test   %rax,%rax
  je     L16
  lea    -0x1(%rbx),%r14d
  test   %ebx,%ebx
  jne    L35
  jmp    L118
L26:
  mov    %rdi,0x18(%rsp)
  jmp    L16
L17:
  movq   $0x0,0x18(%rsp)
  jmp    L16
```

tool_calls: name: parse_data
arguments: tag: D4
type_guessed: string

tool: 

assistant: ```c
char *str_replace(const char *orig, const char *rep, const char *with, unsigned int max_replacements) {
  char *result;
  const char *ins;
  char *tmp;
  int len_rep;
  int len_with;
  int len_front;
  int count;
  if (!orig)
    return NULL;
  if (!rep)
    rep = "";
  len_rep = strlen(rep);
  if (!len_rep) {
    return NULL;
  }
  if (!with)
    with = "";
  len_with = strlen(with);
  ins = orig;
  for (count = 0; (tmp = strstr(ins, rep)); ++count) {
    ins = tmp + len_rep;
  }
  if (max_replacements != 0 && count > max_replacements) {
    count = max_replacements;
  }
  tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
  if (!result)
    return NULL;
  while (count--) {
    ins = strstr(orig, rep);
    len_front = ins - orig;
    tmp = strncpy(tmp, orig, len_front) + len_front;
    tmp = strcpy(tmp, with) + len_with;
    orig += len_front + len_rep;
  }
  strcpy(tmp, orig);
  return result;
}
```