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

```asm
<trim>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %rsi,-0x60(%rbp)
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,-0x20(%rbp)
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,-0x18(%rbp)
  movq   $0x0,-0x30(%rbp)
  movq   $0x0,-0x40(%rbp)
  jmp    L96
L30:
  movl   $0x0,-0x44(%rbp)
  movq   $0x0,-0x38(%rbp)
  jmp    L41
L121:
  mov    -0x60(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%edx
  mov    -0x58(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  add    %rcx,%rax
  movzbl (%rax),%eax
  cmp    %al,%dl
  jne    L56
  addq   $0x1,-0x30(%rbp)
  movl   $0x1,-0x44(%rbp)
  jmp    L7
L56:
  addq   $0x1,-0x38(%rbp)
L41:
  mov    -0x38(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L121
L7:
  cmpl   $0x0,-0x44(%rbp)
  je     L104
  addq   $0x1,-0x40(%rbp)
L96:
  mov    -0x40(%rbp),%rax
  cmp    -0x20(%rbp),%rax
  jb     L30
  jmp    L131
L104:
  nop
L131:
  mov    -0x20(%rbp),%rax
  sub    -0x30(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  mov    -0x20(%rbp),%rax
  sub    $0x1,%rax
  mov    %rax,-0x40(%rbp)
L2:
  movl   $0x0,-0x44(%rbp)
  movq   $0x0,-0x38(%rbp)
  jmp    L14
L81:
  mov    -0x60(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%edx
  mov    -0x58(%rbp),%rcx
  mov    -0x40(%rbp),%rax
  add    %rcx,%rax
  movzbl (%rax),%eax
  cmp    %al,%dl
  jne    L6
  subq   $0x1,-0x28(%rbp)
  movl   $0x1,-0x44(%rbp)
L6:
  addq   $0x1,-0x38(%rbp)
L14:
  mov    -0x38(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L81
  cmpl   $0x0,-0x44(%rbp)
  je     L93
  subq   $0x1,-0x40(%rbp)
  jmp    L2
L93:
  nop
  mov    -0x28(%rbp),%rax
  cmp    -0x30(%rbp),%rax
  jb     L136
  mov    -0x28(%rbp),%rax
  sub    -0x30(%rbp),%rax
  jmp    L108
L136:
  mov    $0x0,%eax
L108:
  mov    %rax,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x8(%rbp)
  mov    -0x8(%rbp),%rax
  mov    %rax,%rdi
  call   <assert@plt>
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x10(%rbp),%rdx
  mov    -0x8(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x8(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x8(%rbp),%rax
  leave
  ret
```

assistant: ```c
char *trim(char *s, const char *totrim) {
  int32_t i, j;
  int32_t start, end;
  int32_t slen, totrimlen, newlen;
  bool trimmed;
  char *news;
  slen = strlen(s);
  totrimlen = strlen(totrim);
  start = 0;
  for (i = 0; i < slen; i++) {
    trimmed = false;
    for (j = 0; j < totrimlen; j++)
      if (totrim[j] == s[i]) {
        start++;
        trimmed = true;
        break;
      }
    if (!trimmed)
      break;
  }
  end = slen - start;
  for (i = slen - 1; i >= 0; i--) {
    trimmed = false;
    for (j = 0; j < totrimlen; j++)
      if (totrim[j] == s[i]) {
        end--;
        trimmed = true;
      }
    if (!trimmed)
      break;
  }
  newlen = (end >= start) ? (end - start) : 0;
  news = malloc((newlen + 1) * sizeof(*news));
  assert(news);
  strncpy(news, s + start, newlen);
  news[newlen] = '\0';
  free(s);
  return news;
}
```