user: Converte this assembly snippet into its equivalent C code:

```asm
<strsub>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x818,%rsp
  mov    %rdi,%rbx
  mov    %rdx,%r12
  mov    %fs:0x28,%rax
  mov    %rax,0x808(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%rdi
  mov    $0xff,%ecx
  rep stos %rax,%es:(%rdi)
  test   %rsi,%rsi
  sete   %al
  test   %rdx,%rdx
  sete   %dl
  or     %dl,%al
  jne    L29
  mov    %rsi,%r14
  test   %rbx,%rbx
  je     L29
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    %eax,%r15d
  mov    %eax,0xc(%rsp)
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    %eax,%ebp
  mov    %eax,0x8(%rsp)
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    %eax,0x4(%rsp)
  cmp    %ebp,%r15d
  jl     L58
  mov    %rbx,%rdi
  mov    $0x0,%r13d
  jmp    L144
L150:
  mov    %r14,%rdi
  call   <strlen@plt>
  movslq %eax,%rdi
  add    %rbp,%rdi
  mov    %r15,%r13
L144:
  mov    %r13d,(%rsp)
  mov    %r14,%rsi
  call   <strstr@plt>
  mov    %rax,%rbp
  mov    %rax,0x10(%rsp,%r13,8)
  lea    0x1(%r13),%r15
  test   %rax,%rax
  jne    L150
  test   %r13d,%r13d
  je     L31
  mov    0x4(%rsp),%r15d
  mov    %r15d,%edi
  sub    0x8(%rsp),%edi
  imul   %r13d,%edi
  add    0xc(%rsp),%edi
  call   <malloc@plt>
  mov    %rax,%r9
  test   %rax,%rax
  je     L31
  test   %r13d,%r13d
  jle    L172
  lea    0x10(%rsp),%rdi
  lea    -0x1(%r13),%eax
  lea    0x18(%rsp,%rax,8),%r11
  mov    %r9,%rdx
  mov    %r15d,%esi
  lea    -0x1(%r15),%r10d
  add    $0x1,%r10
  movslq 0x8(%rsp),%rbp
  jmp    L120
L4:
  movzbl (%rbx,%rax,1),%ecx
  mov    %cl,(%rdx,%rax,1)
  add    $0x1,%rax
  cmp    %r13,%rax
  jne    L4
  add    %r13,%rdx
L178:
  cmpl   $0x0,0x4(%rsp)
  je     L80
  mov    $0x0,%eax
L24:
  movzbl (%r12,%rax,1),%ecx
  mov    %cl,(%rdx,%rax,1)
  add    $0x1,%rax
  cmp    %rax,%rsi
  jne    L24
  add    %r10,%rdx
L80:
  lea    (%r8,%rbp,1),%rbx
  add    $0x8,%rdi
  cmp    %r11,%rdi
  je     L199
L120:
  mov    (%rdi),%r8
  mov    %r8,%r13
  sub    %rbx,%r13
  mov    $0x0,%eax
  cmp    %rbx,%r8
  ja     L4
  mov    %rbx,%r8
  jmp    L178
L172:
  mov    %rax,%rdx
L199:
  movzbl (%rbx),%eax
  test   %al,%al
  je     L106
L158:
  add    $0x1,%rbx
  add    $0x1,%rdx
  mov    %al,-0x1(%rdx)
  movzbl (%rbx),%eax
  test   %al,%al
  jne    L158
L106:
  movb   $0x0,(%rdx)
  mov    %r9,%rbp
L31:
  mov    0x808(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L48
  mov    %rbp,%rax
  add    $0x818,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L29:
  mov    $0x0,%ebp
  jmp    L31
L58:
  mov    $0x0,%ebp
  jmp    L31
L48:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
char *strsub(char *str, char *old, char *new) {
  int tl, ol, nl, sl, i = 0, j;
  char *gs[255] = {
      NULL,
  };
  char *sp = str;
  char *tn;
  char *tnp;
  if (str == NULL || old == NULL || new == NULL)
    return NULL;
  sl = strlen(str);
  ol = strlen(old);
  nl = strlen(new);
  if (sl < ol)
    return NULL;
  while (gs[i] = strstr(sp, old))
    sp = gs[i++] + strlen(old);
  if (i == 0)
    return NULL;
  tl = sl + i * (nl - ol);
  tn = (char *)malloc(tl);
  if (tn == NULL)
    return NULL;
  sp = str;
  tnp = tn;
  j = 0;
  while (j < i) {
    int tmp = nl;
    char *np = new;
    while (sp < gs[j])
      *tnp++ = *sp++;
    while (tmp--)
      *tnp++ = *np++;
    sp = sp + ol;
    j++;
  }
  while (*sp != '\0')
    *tnp++ = *sp++;
  *tnp = '\0';
  return tn;
}
```