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

```asm
<Q_replace>:
  endbr64
  push   %r15
  xor    %r15d,%r15d
  push   %r14
  mov    %rdx,%r14
  push   %r13
  movslq %ecx,%r13
  push   %r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %rsi,%rbx
  mov    %rdi,%rsi
  mov    %rdx,%rdi
  sub    $0x18,%rsp
  call   <strstr@plt>
  test   %rax,%rax
  mov    %rax,(%rsp)
  je     L170
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %rbx,%rdi
  movslq %eax,%r12
  call   <strlen@plt>
  mov    (%rsp),%r8
  mov    %eax,%r15d
  sub    %r12d,%r15d
  test   %r15d,%r15d
  jg     L123
  jne    L70
  nopl   (%rax)
L104:
  movzbl (%rbx),%eax
  test   %al,%al
  je     L116
  mov    %rbx,%rdx
  xchg   %ax,%ax
L177:
  add    $0x1,%rdx
  mov    %al,(%r8)
  add    $0x1,%r8
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L177
  mov    %r8,%rdi
  mov    %rbp,%rsi
  add    $0x1,%r15d
  call   <strstr@plt>
  mov    %rax,%r8
  test   %rax,%rax
  jne    L104
L170:
  add    $0x18,%rsp
  mov    %r15d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L123:
  lea    (%r14,%r13,1),%rax
  mov    %r14,%rdi
  mov    %r8,0x8(%rsp)
  movslq %r15d,%r13
  mov    %rax,(%rsp)
  xor    %r15d,%r15d
  call   <strlen@plt>
  mov    0x8(%rsp),%r8
  cltq
  add    %rax,%r14
  nopl   (%rax)
L85:
  mov    %r14,%rcx
  add    %r13,%r14
  cmp    %r14,(%rsp)
  jbe    L170
  lea    (%r8,%r12,1),%rdx
  xor    %eax,%eax
  mov    %rdx,%rsi
  sub    %rcx,%rsi
  cmp    %rdx,%rcx
  jb     L196
  nopl   (%rax)
L78:
  movzbl (%rcx,%rax,1),%edx
  mov    %dl,(%r14,%rax,1)
  mov    %rax,%rdx
  sub    $0x1,%rax
  cmp    %rdx,%rsi
  jne    L78
L196:
  movzbl (%rbx),%eax
  mov    %rbx,%rdx
  test   %al,%al
  je     L198
  cs nopw 0x0(%rax,%rax,1)
L16:
  add    $0x1,%rdx
  mov    %al,(%r8)
  add    $0x1,%r8
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L16
L198:
  mov    %r8,%rdi
  mov    %rbp,%rsi
  add    $0x1,%r15d
  call   <strstr@plt>
  mov    %rax,%r8
  test   %rax,%rax
  jne    L85
  jmp    L170
  xchg   %ax,%ax
L116:
  mov    %rbp,%rsi
  mov    %r8,%rdi
  jmp    L161
  nopl   0x0(%rax,%rax,1)
L160:
  mov    %rbp,%rsi
L161:
  call   <strstr@plt>
  add    $0x1,%r15d
  mov    %rax,%rdi
  test   %rax,%rax
  jne    L160
  jmp    L170
L70:
  movslq %eax,%r13
  xor    %r15d,%r15d
  nop
L127:
  lea    (%r8,%r12,1),%rsi
  lea    (%r8,%r13,1),%rcx
  xor    %eax,%eax
  nopw   0x0(%rax,%rax,1)
L28:
  movzbl (%rsi,%rax,1),%edx
  mov    %dl,(%rcx,%rax,1)
  add    $0x1,%rax
  test   %dl,%dl
  jne    L28
  movzbl (%rbx),%eax
  test   %al,%al
  je     L157
  mov    %rbx,%rdx
  nopl   0x0(%rax)
L169:
  add    $0x1,%rdx
  mov    %al,(%r8)
  add    $0x1,%r8
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L169
L157:
  mov    %r8,%rdi
  mov    %rbp,%rsi
  add    $0x1,%r15d
  call   <strstr@plt>
  mov    %rax,%r8
  test   %rax,%rax
  jne    L127
  jmp    L170
```

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;
}
```