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

```asm
<smtp_chunk_split>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  test   %rsi,%rsi
  je     L61
  mov    %rdx,%r13
  mov    %rdi,%r12
  mov    %rsi,%rbx
  call   <strlen@plt>
  mov    %r13,%rdi
  mov    %rax,%r14
  call   <strlen@plt>
  mov    %rax,%rbp
  test   %r14,%r14
  je     L65
  lea    0x38(%rsp),%rdx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <smtp_si_add_size_t@plt>
  test   %rax,%rax
  jne    L135
  lea    0x30(%rsp),%rdx
  mov    $0x1,%esi
  mov    %r14,%rdi
  call   <smtp_si_add_size_t@plt>
  test   %rax,%rax
  jne    L135
  mov    %r14,%rax
  xor    %edx,%edx
  lea    0x40(%rsp),%r14
  mov    0x38(%rsp),%rdi
  div    %rbx
  mov    %r14,%rdx
  lea    0x1(%rax),%rsi
  mov    %rax,0x28(%rsp)
  call   <smtp_si_mul_size_t@plt>
  test   %rax,%rax
  jne    L135
  mov    0x30(%rsp),%rsi
  mov    0x40(%rsp),%rdi
  mov    %r14,%rdx
  call   <smtp_si_add_size_t@plt>
  test   %rax,%rax
  jne    L135
  mov    0x40(%rsp),%rsi
  mov    $0x1,%edi
  call   <calloc@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L135
  movq   $0x0,0x10(%rsp)
  movq   $0x0,0x8(%rsp)
  movq   $0x0,0x18(%rsp)
  jmp    L1
  nopl   (%rax)
L22:
  mov    0x18(%rsp),%rsi
  lea    (%rcx,%rbp,1),%rax
  mov    %rax,0x8(%rsp)
  lea    0x1(%rsi),%rax
  cmp    %rsi,0x28(%rsp)
  je     L39
  mov    %rax,0x18(%rsp)
L1:
  mov    0x10(%rsp),%rax
  mov    %rbx,%rsi
  lea    (%r12,%rax,1),%r15
  mov    %r15,%rdi
  call   <smtp_strnlen_utf8@plt>
  mov    %rax,%rdx
  cmp    $0xffffffffffffffff,%rax
  je     L100
  mov    0x8(%rsp),%rcx
  mov    %r15,%rsi
  mov    %rax,0x20(%rsp)
  lea    (%r14,%rcx,1),%rdi
  call   <memcpy@plt>
  mov    0x20(%rsp),%rdx
  mov    0x8(%rsp),%rcx
  cmpb   $0x1,(%r15)
  adc    %rdx,%rcx
  add    %rdx,0x10(%rsp)
  test   %rbp,%rbp
  je     L22
  lea    (%r14,%rcx,1),%rdi
  mov    %rbp,%rdx
  mov    %r13,%rsi
  mov    %rcx,0x8(%rsp)
  call   <memcpy@plt>
  mov    0x8(%rsp),%rcx
  jmp    L22
  nopw   0x0(%rax,%rax,1)
L135:
  xor    %r14d,%r14d
L39:
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L131
  add    $0x58,%rsp
  mov    %r14,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L65:
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L131
  add    $0x58,%rsp
  mov    %r13,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1150 <smtp_strdup@plt>
  xchg   %ax,%ax
L61:
  mov    D13(%rip),%rax
  xor    %r14d,%r14d
  mov    (%rax),%edx
  mov    D10(%rip),%rax
  mov    %edx,(%rax)
  jmp    L39
  nopw   0x0(%rax,%rax,1)
L100:
  mov    %r14,%rdi
  xor    %r14d,%r14d
  call   <free@plt>
  jmp    L39
L131:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
char *smtp_chunk_split(const char *const s, size_t chunklen, const char *const end) {
  char *snew;
  size_t bodylen;
  size_t bodylen_inc;
  size_t endlen;
  size_t endlen_inc;
  size_t snewlen;
  size_t chunk_i;
  size_t snew_i;
  size_t body_i;
  size_t body_copy_len;
  if (chunklen < 1) {
    errno = EINVAL;
    return NULL;
  }
  bodylen = strlen(s);
  endlen = strlen(end);
  if (bodylen < 1) {
    return smtp_strdup(end);
  }
  if (smtp_si_add_size_t(endlen, 1, &endlen_inc) || smtp_si_add_size_t(bodylen, 1, &bodylen_inc) || smtp_si_mul_size_t(endlen_inc, bodylen / chunklen + 1, &snewlen) || smtp_si_add_size_t(snewlen, bodylen_inc, &snewlen) || (snew = calloc(1, snewlen)) == NULL) {
    return NULL;
  }
  body_i = 0;
  snew_i = 0;
  for (chunk_i = 0; chunk_i < bodylen / chunklen + 1; chunk_i++) {
    body_copy_len = smtp_strnlen_utf8(&s[body_i], chunklen);
    if (body_copy_len == ((size_t)(-1))) {
      free(snew);
      return NULL;
    }
    memcpy(&snew[snew_i], &s[body_i], body_copy_len);
    snew_i += body_copy_len;
    if (s[body_i] == '\0') {
      snew_i += 1;
    }
    body_i += body_copy_len;
    if (endlen > 0) {
      memcpy(&snew[snew_i], end, endlen);
    }
    snew_i += endlen;
  }
  return snew;
}
```