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

```asm
<replaceNWord>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdx,0x10(%rsp)
  test   %rdi,%rdi
  je     L31
  mov    %rdi,%rbx
  mov    %rsi,%rbp
  mov    %rdx,%r14
  mov    %ecx,%r12d
  test   %rsi,%rsi
  je     L31
  test   %rdx,%rdx
  je     L285
  test   %ecx,%ecx
  je     L285
  mov    %rsi,%rdi
  call   <strlen@plt>
  mov    %eax,%r13d
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %eax,0x4(%rsp)
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    %eax,%r14d
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <countWordInBuff@plt>
  test   %r12d,%r12d
  jle    L207
  cmp    %eax,%r12d
  jg     L207
  mov    %r12d,%eax
L189:
  mov    0x4(%rsp),%edx
  sub    %r13d,%edx
  imul   %edx,%eax
  lea    0x1(%r14,%rax,1),%edi
  call   <malloc@plt>
  mov    %rax,%r15
  mov    $0x0,%r8d
  mov    %rax,0x8(%rsp)
  mov    %rax,%rcx
  lea    D12(%rip),%rdx
  lea    D16(%rip),%rsi
  mov    $0x86,%edi
  call   <printOpt@plt>
  mov    0x8(%rsp),%r11
  test   %r11,%r11
  je     L202
  test   %r14d,%r14d
  jle    L158
  mov    $0x0,%edi
  mov    $0x0,%edx
  mov    $0x0,%esi
  mov    $0x0,%eax
  mov    $0x0,%ecx
  mov    %r12d,%r8d
  shr    $0x1f,%r8d
  mov    0x4(%rsp),%r9d
  add    %r9,%r11
  jmp    L144
L207:
  mov    $0x0,%r15d
  test   %eax,%eax
  je     L171
  jmp    L189
L206:
  cmp    %edi,%r12d
  setg   %r10b
  or     %r8b,%r10b
  je     L30
  cmp    %esi,%r13d
  jle    L30
  test   %esi,%esi
  jne    L275
  cmp    $0x1,%r13d
  jle    L275
  mov    %eax,%ecx
  mov    $0x0,%esi
L53:
  add    $0x1,%esi
  jmp    L124
L275:
  lea    0x1(%rsi),%r9d
  cmp    %r13d,%r9d
  jne    L53
  cmpl   $0x0,0x4(%rsp)
  jle    L287
  movslq %edx,%r9
  mov    0x8(%rsp),%rsi
  add    %r9,%rsi
  mov    %rsi,%r10
  add    %r11,%r9
  mov    %rsi,0x18(%rsp)
  mov    0x10(%rsp),%rsi
  sub    %r10,%rsi
  mov    %rsi,%r10
  mov    0x18(%rsp),%rsi
  mov    %eax,0x18(%rsp)
L168:
  movzbl (%r10,%rsi,1),%eax
  mov    %al,(%rsi)
  add    $0x1,%rsi
  cmp    %r9,%rsi
  jne    L168
  mov    0x18(%rsp),%eax
  mov    0x4(%rsp),%esi
  add    %esi,%edx
L212:
  add    $0x1,%edi
  jmp    L53
L287:
  mov    $0x0,%esi
  jmp    L212
L84:
  movslq %ecx,%rax
  movzbl (%rbx,%rax,1),%esi
  movslq %edx,%rax
  mov    %sil,(%r15,%rax,1)
  lea    0x1(%rdx),%edx
  mov    %ecx,%eax
  mov    $0x0,%esi
L124:
  add    $0x1,%eax
  cmp    %eax,%r14d
  jle    L178
L144:
  movslq %eax,%r9
  movzbl (%rbx,%r9,1),%r9d
  movslq %esi,%r10
  cmp    0x0(%rbp,%r10,1),%r9b
  je     L206
L30:
  cmp    %esi,%r13d
  jle    L94
  test   %esi,%esi
  jg     L84
L94:
  movslq %edx,%rsi
  mov    %r9b,(%r15,%rsi,1)
  lea    0x1(%rdx),%edx
  mov    $0x0,%esi
  jmp    L124
L158:
  mov    $0x0,%edx
L178:
  movslq %edx,%rdx
  mov    0x8(%rsp),%rax
  movb   $0x0,(%rax,%rdx,1)
L171:
  mov    %r15,%rax
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L31:
  mov    $0x0,%r15d
  jmp    L171
L285:
  mov    $0x0,%r15d
  jmp    L171
L202:
  mov    $0x0,%r15d
  jmp    L171
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D12
type_infered: string
name: extract_symbolic_data
arguments: data_tag: D16
type_infered: string

tool: D12: replaceWord.c

tool: D16: replaceNWord

assistant: ```c
char *replaceNWord(const char *buffer, const char *old, const char *nw, int count) {
  int numOldWord = 0;
  int firstPos = 0;
  int index = 0, index2 = 0, index3 = 0;
  int numRep = 0;
  char *newBuff = NULL;
  int sizeOldBuff = 0;
  int sizeOldWord = 0;
  int sizeNewBuff = 0;
  int sizeNewWord = 0;
  char fact1 = 0;
  if (buffer == NULL || old == NULL || nw == NULL || count == 0) {
    return NULL;
  } else {
  }
  sizeOldWord = strlen(old);
  sizeNewWord = strlen(nw);
  sizeOldBuff = strlen(buffer);
  numOldWord = countWordInBuff(buffer, old);
  if (count > 0 && count <= numOldWord) {
    numOldWord = count;
  } else {
  }
  if (numOldWord == 0) {
    return 0;
  } else {
  }
  sizeNewBuff = 1 + sizeOldBuff + (sizeNewWord - sizeOldWord) * numOldWord;
  newBuff = (char *)malloc(sizeof(char) * sizeNewBuff);
  printOpt(135 - 1, "replaceNWord", "replaceWord.c", (void *)newBuff, 0);
  if (newBuff == NULL) {
    return NULL;
  } else {
  }
  for (index = 0; index < sizeOldBuff; index++) {
    fact1 = (numRep < count) || count < 0;
    if (buffer[index] == old[index2] && index2 < sizeOldWord && fact1) {
      if (index2 == 0 && sizeOldWord > 1) {
        firstPos = index;
      } else if (index2 + 1 == sizeOldWord) {
        for (index2 = 0; index2 < sizeNewWord; index2++) {
          newBuff[index3++] = nw[index2];
        }
        numRep++;
      } else {
      }
      index2++;
    } else if (index2 < sizeOldWord && index2 > 0) {
      index = firstPos;
      index2 = 0;
      newBuff[index3++] = buffer[index];
    } else {
      newBuff[index3++] = buffer[index];
      index2 = 0;
    }
  }
  newBuff[index3] = '\0';
  return newBuff;
}
```