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

```asm
<b64_encode>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x70,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %rsi,-0x60(%rbp)
  mov    %rdx,-0x68(%rbp)
  mov    %ecx,-0x6c(%rbp)
  mov    %r8d,-0x70(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  cmpq   $0x0,-0x68(%rbp)
  jne    L157
  mov    $0x0,%eax
  jmp    L51
L157:
  movq   $0x0,-0x38(%rbp)
  movq   $0x0,-0x30(%rbp)
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L83
  movq   $0x40,-0x30(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x38(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,%rdx
  mov    -0x68(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L83
  mov    $0x0,%eax
  jmp    L51
L83:
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,-0x28(%rbp)
  movl   $0x0,-0x48(%rbp)
  movl   $0x0,-0x44(%rbp)
  movl   $0x0,-0x40(%rbp)
  jmp    L147
L98:
  mov    -0x40(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%ecx
  mov    -0x48(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x48(%rbp)
  mov    %ecx,%edx
  cltq
  mov    %dl,-0xc(%rbp,%rax,1)
  mov    -0x48(%rbp),%eax
  cmp    $0x3,%eax
  jne    L58
  mov    -0x70(%rbp),%r8d
  mov    -0x6c(%rbp),%edi
  lea    -0x44(%rbp),%rcx
  lea    -0x48(%rbp),%rdx
  lea    -0xc(%rbp),%rsi
  mov    -0x28(%rbp),%rax
  mov    %r8d,%r9d
  mov    %edi,%r8d
  mov    %rax,%rdi
  call   <encode_base64@plt>
  mov    %rax,-0x20(%rbp)
  mov    -0x20(%rbp),%rax
  add    %rax,-0x28(%rbp)
  mov    -0x20(%rbp),%rax
  sub    %rax,-0x30(%rbp)
L58:
  cmpq   $0x0,-0x38(%rbp)
  je     L111
  cmpq   $0x7,-0x30(%rbp)
  ja     L111
  shlq   -0x38(%rbp)
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x28(%rbp),%rax
  sub    %rdx,%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x38(%rbp),%rax
  sub    -0x18(%rbp),%rax
  mov    %rax,-0x30(%rbp)
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rax
  mov    -0x38(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,%rdx
  mov    -0x68(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  jne    L34
  mov    $0x0,%eax
  jmp    L51
L34:
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x28(%rbp)
L111:
  addl   $0x1,-0x40(%rbp)
L147:
  mov    -0x40(%rbp),%eax
  cltq
  cmp    %rax,-0x60(%rbp)
  ja     L98
  mov    -0x48(%rbp),%eax
  test   %eax,%eax
  je     L158
  mov    -0x48(%rbp),%eax
  mov    %eax,-0x3c(%rbp)
  jmp    L66
L1:
  mov    -0x3c(%rbp),%eax
  cltq
  movb   $0x0,-0xc(%rbp,%rax,1)
  addl   $0x1,-0x3c(%rbp)
L66:
  cmpl   $0x2,-0x3c(%rbp)
  jle    L1
  mov    -0x70(%rbp),%r8d
  mov    -0x6c(%rbp),%edi
  lea    -0x44(%rbp),%rcx
  lea    -0x48(%rbp),%rdx
  lea    -0xc(%rbp),%rsi
  mov    -0x28(%rbp),%rax
  mov    %r8d,%r9d
  mov    %edi,%r8d
  mov    %rax,%rdi
  call   <encode_base64@plt>
  add    %rax,-0x28(%rbp)
L158:
  mov    -0x28(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x68(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x28(%rbp),%rax
  sub    %rdx,%rax
L51:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L75
  call   <__stack_chk_fail@plt>
L75:
  leave
  ret
```

assistant: ```c
size_t b64_encode(const char *s, size_t nbytes, char **pdst, int line_breaks, int cr) {
  if (!pdst)
    return 0;
  size_t max_len = 0, bytes_left = 0;
  if (!*pdst) {
    *pdst = (char *)malloc(max_len = bytes_left = 64);
    if (!*pdst)
      return 0;
  }
  char *dst = *pdst;
  int inbuf_size = 0, line_len = 0;
  unsigned char inbuf[4];
  for (int i = 0; i < nbytes; i++) {
    inbuf[inbuf_size++] = s[i];
    if (inbuf_size == 3) {
      size_t len = encode_base64(dst, inbuf, &inbuf_size, &line_len, line_breaks, cr);
      dst += len;
      bytes_left -= len;
    }
    if (max_len && (bytes_left < 8)) {
      max_len *= 2;
      size_t nbytes = dst - *pdst;
      bytes_left = max_len - nbytes;
      *pdst = (char *)realloc(*pdst, max_len);
      if (!*pdst)
        return 0;
      dst = *pdst + nbytes;
    }
  }
  if (inbuf_size) {
    for (int i = inbuf_size; i < 3; i++)
      inbuf[i] = 0;
    dst += encode_base64(dst, inbuf, &inbuf_size, &line_len, line_breaks, cr);
  }
  *dst = 0;
  return dst - *pdst;
}
```