user: Please show me the C implementation that matches the assembly code listed below:

```asm
<Q_replace>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r14
  mov    %rsi,%r12
  mov    %ecx,%r15d
  mov    %rdi,%rsi
  mov    %rdx,(%rsp)
  mov    %rdx,%rdi
  call   <strstr@plt>
  mov    $0x0,%r13d
  test   %rax,%rax
  je     L41
  mov    %rax,%rbx
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %eax,%r13d
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    %eax,%ebp
  mov    %r13d,0x8(%rsp)
  sub    %r13d,%ebp
  test   %ebp,%ebp
  jg     L73
  mov    $0x0,%r13d
  js     L168
L5:
  movzbl (%r12),%eax
  test   %al,%al
  je     L49
  mov    %r12,%rdx
L81:
  add    $0x1,%rdx
  add    $0x1,%rbx
  mov    %al,-0x1(%rbx)
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L81
L49:
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strstr@plt>
  mov    %rax,%rbx
  add    $0x1,%r13d
  test   %rax,%rax
  jne    L5
L41:
  mov    %r13d,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L73:
  movslq %r15d,%r15
  mov    (%rsp),%r13
  add    %r13,%r15
  mov    %r13,%rdi
  call   <strlen@plt>
  movslq %ebp,%rdi
  mov    %rdi,(%rsp)
  movslq %eax,%rbp
  add    %r13,%rbp
  mov    $0x0,%r13d
  movslq 0x8(%rsp),%rax
  mov    %rax,0x8(%rsp)
  jmp    L161
L184:
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strstr@plt>
  mov    %rax,%rbx
  add    $0x1,%r13d
  test   %rax,%rax
  je     L41
L161:
  mov    %rbp,%rsi
  add    (%rsp),%rbp
  mov    %rbp,%rdi
  cmp    %rbp,%r15
  jbe    L41
  mov    0x8(%rsp),%rcx
  add    %rbx,%rcx
  cmp    %rcx,%rsi
  jb     L35
  sub    %rsi,%rcx
  mov    $0x0,%eax
L162:
  movzbl (%rsi,%rax,1),%edx
  mov    %dl,(%rdi,%rax,1)
  mov    %rax,%rdx
  sub    $0x1,%rax
  cmp    %rdx,%rcx
  jne    L162
L35:
  movzbl (%r12),%eax
  test   %al,%al
  je     L184
  mov    %r12,%rdx
L185:
  add    $0x1,%rdx
  add    $0x1,%rbx
  mov    %al,-0x1(%rbx)
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L185
  jmp    L184
L168:
  movslq 0x8(%rsp),%r15
  movslq %eax,%rbp
L114:
  lea    (%rbx,%r15,1),%rsi
  lea    (%rbx,%rbp,1),%rcx
  mov    $0x0,%eax
L108:
  movzbl (%rsi,%rax,1),%edx
  mov    %dl,(%rcx,%rax,1)
  add    $0x1,%rax
  test   %dl,%dl
  jne    L108
  movzbl (%r12),%eax
  test   %al,%al
  je     L158
  mov    %r12,%rdx
L52:
  add    $0x1,%rdx
  add    $0x1,%rbx
  mov    %al,-0x1(%rbx)
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L52
L158:
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strstr@plt>
  mov    %rax,%rbx
  add    $0x1,%r13d
  test   %rax,%rax
  jne    L114
  jmp    L41
```

assistant: ```c
int Q_replace(const char *str1, const char *str2, char *src, int max_len) {
  int len1, len2, d, count;
  const char *s0, *s1, *s2, *max;
  char *match, *dst;
  match = strstr(src, str1);
  if (!match)
    return 0;
  count = 0;
  len1 = strlen(str1);
  len2 = strlen(str2);
  d = len2 - len1;
  if (d > 0) {
    max = src + max_len;
    src += strlen(src);
    do {
      s1 = src;
      src += d;
      if (src >= max)
        return count;
      dst = src;
      s0 = match + len1;
      while (s1 >= s0)
        *dst-- = *s1--;
      s2 = str2;
      while (*s2) {
        *match++ = *s2++;
      }
      match = strstr(match, str1);
      count++;
    } while (match);
    return count;
  } else if (d < 0) {
    do {
      s1 = match + len1;
      dst = match + len2;
      while ((*dst++ = *s1++) != '\0')
        ;
      s2 = str2;
      while (*s2) {
        *match++ = *s2++;
      }
      match = strstr(match, str1);
      count++;
    } while (match);
    return count;
  } else
    do {
      s2 = str2;
      while (*s2) {
        *match++ = *s2++;
      }
      match = strstr(match, str1);
      count++;
    } while (match);
  return count;
}
```