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

```asm
<search_and_replace_kw>:
  endbr64
  push   %r15
  xor    %r15d,%r15d
  push   %r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  mov    %rdx,%r12
  push   %rbp
  mov    %esi,%ebp
  push   %rbx
  movslq %r8d,%rbx
  sub    $0x38,%rsp
  mov    %rdi,0x10(%rsp)
  lea    0x0(,%rbx,4),%edi
  mov    %ebx,0x24(%rsp)
  call   <malloc@plt>
  mov    0x24(%rsp),%edx
  mov    %rax,%r14
  test   %edx,%edx
  jle    L114
L166:
  mov    (%r12,%r15,8),%rdi
  call   <strlen@plt>
  mov    %eax,(%r14,%r15,4)
  add    $0x1,%r15
  cmp    %r15,%rbx
  jne    L166
L114:
  movslq %ebp,%rax
  mov    0x10(%rsp),%r15
  mov    %rax,(%rsp)
  cmp    $0x50,%ebp
  jle    L188
  mov    %r12,0x28(%rsp)
  mov    %r15,%r12
  mov    %r14,%r15
L263:
  mov    0x10(%rsp),%rdx
  mov    %r12,%rdi
L89:
  add    $0x50,%r12
  mov    %r12,%rax
  sub    %rdx,%rax
  add    $0x50,%rax
  cmpb   $0x45,(%rdi)
  jne    L117
  cmpb   $0x4e,0x1(%rdi)
  jne    L117
  cmpb   $0x44,0x2(%rdi)
  jne    L117
  cmpb   $0x20,0x3(%rdi)
  jne    L117
  nopl   0x0(%rax,%rax,1)
L155:
  cmp    %rax,(%rsp)
  jle    L142
  movzbl (%r12),%ecx
  add    $0x50,%r12
  mov    %r12,%rax
  sub    %rdx,%rax
  add    $0x50,%rax
  cmp    $0x58,%cl
  jne    L155
  cmpb   $0x54,-0x4f(%r12)
  jne    L155
  cmpb   $0x45,-0x4e(%r12)
  jne    L155
  cmpb   $0x4e,-0x4d(%r12)
  jne    L155
  cmpb   $0x53,-0x4c(%r12)
  jne    L155
  cmpb   $0x49,-0x4b(%r12)
  jne    L155
  cmpb   $0x4f,-0x4a(%r12)
  jne    L155
  cmpb   $0x4e,-0x49(%r12)
  jne    L155
  cmp    %rax,(%rsp)
  jle    L142
  mov    %r12,%rdi
  jmp    L89
  nopl   0x0(%rax)
L117:
  mov    %rax,0x8(%rsp)
  mov    0x24(%rsp),%eax
  test   %eax,%eax
  jle    L180
  mov    0x28(%rsp),%rbp
  xor    %r14d,%r14d
  mov    %r12,0x18(%rsp)
  mov    %r13,%r12
  mov    %rbx,%r13
  mov    %r14,%rbx
  mov    %rbp,%r14
  mov    %rdi,%rbp
  nopl   0x0(%rax)
L59:
  mov    (%r15,%rbx,4),%ecx
  xor    %eax,%eax
  test   %ecx,%ecx
  jns    L44
  jmp    L0
  nopl   0x0(%rax)
L279:
  mov    (%r14),%rsi
  cmp    %dl,(%rsi,%rax,1)
  jne    L8
L175:
  add    $0x1,%rax
  cmp    %eax,%ecx
  jl     L0
L44:
  movzbl 0x0(%rbp,%rax,1),%edx
  cmp    %eax,%ecx
  jg     L279
  cmp    $0x3d,%dl
  je     L175
  cmp    $0x20,%dl
  je     L175
L8:
  add    $0x1,%rbx
  add    $0x8,%r14
  cmp    %rbx,%r13
  jne    L59
L3:
  mov    %r13,%rbx
  mov    %r12,%r13
  mov    0x18(%rsp),%r12
L180:
  mov    0x8(%rsp),%rdi
  cmp    %rdi,(%rsp)
  jg     L263
L142:
  mov    %r15,%r14
L188:
  mov    %r14,%rdi
  call   <free@plt>
  add    $0x38,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L0:
  mov    (%r12,%rbx,8),%rdx
  mov    (%r14),%rsi
  mov    %rbp,%rdi
  add    $0x1,%rbx
  add    $0x8,%r14
  call   <search_rep@plt>
  cmp    %rbx,%r13
  jne    L59
  jmp    L3
```

assistant: ```c
int search_and_replace_kw(char *buf, int bufsize, char **key_in, char **key_out, int nk) {
  char *w;
  int i, j;
  int in_header;
  int match_flag;
  int *keysizes;
  keysizes = malloc(nk * sizeof(int));
  for (i = 0; i < nk; i++)
    keysizes[i] = (int)strlen(key_in[i]);
  w = buf;
  in_header = 1;
  while ((w - buf + 80) < bufsize) {
    if (in_header) {
      if (w[0] == 'E' && w[1] == 'N' && w[2] == 'D' && w[3] == ' ') {
        in_header = 0;
      } else {
        for (i = 0; i < nk; i++) {
          match_flag = 1;
          for (j = 0; j <= keysizes[i]; j++) {
            if (j < keysizes[i]) {
              if (key_in[i][j] != w[j]) {
                match_flag = 0;
                break;
              }
            } else {
              if ((w[j] != '=') && (w[j] != ' ')) {
                match_flag = 0;
                break;
              }
            }
          }
          if (match_flag) {
            search_rep(w, key_in[i], key_out[i]);
          }
        }
      }
    } else {
      if (w[0] == 'X' && w[1] == 'T' && w[2] == 'E' && w[3] == 'N' && w[4] == 'S' && w[5] == 'I' && w[6] == 'O' && w[7] == 'N') {
        in_header = 1;
      }
    }
    w += 80;
  }
  free(keysizes);
  return 0;
}
```