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

```asm
<base32_encode>:
  endbr64
  test   %rcx,%rcx
  je     L271
  push   %r15
  push   %r14
  mov    %rsi,%r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rcx,%rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x8,%rsp
  test   %rsi,%rsi
  je     L178
  mov    %rdi,%r12
  lea    D3(%rip),%r13
L186:
  movsbl (%r12),%edi
  call   <to_uchar@plt>
  sar    $0x3,%eax
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,(%rbx)
  cmp    $0x1,%rbp
  je     L128
  movsbl (%r12),%edi
  call   <to_uchar@plt>
  lea    0x0(,%rax,4),%r15d
  cmp    $0x1,%r14
  jne    L244
  mov    %r15d,%eax
  and    $0x1c,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x1(%rbx)
  cmp    $0x2,%rbp
  je     L128
  movb   $0x3d,0x2(%rbx)
  cmp    $0x3,%rbp
  je     L128
  movb   $0x3d,0x3(%rbx)
  cmp    $0x4,%rbp
  je     L128
L223:
  movb   $0x3d,0x4(%rbx)
  cmp    $0x5,%rbp
  je     L128
L243:
  movb   $0x3d,0x5(%rbx)
  cmp    $0x6,%rbp
  je     L128
  movb   $0x3d,0x6(%rbx)
  cmp    $0x7,%rbp
  je     L128
L120:
  movb   $0x3d,0x7(%rbx)
  add    $0x8,%rbx
  cmp    $0x8,%rbp
  je     L128
L126:
  movb   $0x0,(%rbx)
L128:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L244:
  movsbl 0x1(%r12),%edi
  call   <to_uchar@plt>
  sar    $0x6,%eax
  add    %r15d,%eax
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x1(%rbx)
  cmp    $0x2,%rbp
  je     L128
  movsbl 0x1(%r12),%edi
  call   <to_uchar@plt>
  sar    %eax
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x2(%rbx)
  cmp    $0x3,%rbp
  je     L128
  movsbl 0x1(%r12),%edi
  call   <to_uchar@plt>
  shl    $0x4,%eax
  mov    %eax,%r15d
  cmp    $0x2,%r14
  jne    L115
  and    $0x10,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x3(%rbx)
  cmp    $0x4,%rbp
  jne    L223
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L115:
  movsbl 0x2(%r12),%edi
  call   <to_uchar@plt>
  sar    $0x4,%eax
  add    %r15d,%eax
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x3(%rbx)
  cmp    $0x4,%rbp
  je     L128
  movsbl 0x2(%r12),%edi
  call   <to_uchar@plt>
  lea    (%rax,%rax,1),%r15d
  cmp    $0x3,%r14
  jne    L25
  mov    %r15d,%eax
  and    $0x1e,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x4(%rbx)
  cmp    $0x5,%rbp
  je     L128
  jmp    L243
  nopw   0x0(%rax,%rax,1)
L25:
  movsbl 0x3(%r12),%edi
  call   <to_uchar@plt>
  sar    $0x7,%eax
  add    %r15d,%eax
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x4(%rbx)
  cmp    $0x5,%rbp
  je     L128
  movsbl 0x3(%r12),%edi
  call   <to_uchar@plt>
  sar    $0x2,%eax
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x5(%rbx)
  cmp    $0x6,%rbp
  je     L128
  movsbl 0x3(%r12),%edi
  call   <to_uchar@plt>
  lea    0x0(,%rax,8),%r15d
  cmp    $0x4,%r14
  jne    L6
  mov    %r15d,%eax
  and    $0x18,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x6(%rbx)
  cmp    $0x7,%rbp
  jne    L120
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L6:
  movsbl 0x4(%r12),%edi
  call   <to_uchar@plt>
  sar    $0x5,%eax
  add    %r15d,%eax
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,0x6(%rbx)
  cmp    $0x7,%rbp
  je     L128
  movsbl 0x4(%r12),%edi
  add    $0x8,%rbx
  call   <to_uchar@plt>
  and    $0x1f,%eax
  movzbl 0x0(%r13,%rax,1),%eax
  mov    %al,-0x1(%rbx)
  sub    $0x8,%rbp
  je     L128
  sub    $0x5,%r14
  je     L126
  add    $0x5,%r12
  jmp    L186
L178:
  test   %rcx,%rcx
  jne    L126
  jmp    L128
  nopl   (%rax)
L271:
  ret
```

assistant: ```c
void base32_encode(const char *restrict in, size_t inlen, char *restrict out, size_t outlen) {
  static const char b32str[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
  while (inlen && outlen) {
    *out++ = b32str[(to_uchar(in[0]) >> 3) & 0x1f];
    if (!--outlen)
      break;
    *out++ = b32str[((to_uchar(in[0]) << 2) + (--inlen ? to_uchar(in[1]) >> 6 : 0)) & 0x1f];
    if (!--outlen)
      break;
    *out++ = (inlen ? b32str[(to_uchar(in[1]) >> 1) & 0x1f] : '=');
    if (!--outlen)
      break;
    *out++ = (inlen ? b32str[((to_uchar(in[1]) << 4) + (--inlen ? to_uchar(in[2]) >> 4 : 0)) & 0x1f] : '=');
    if (!--outlen)
      break;
    *out++ = (inlen ? b32str[((to_uchar(in[2]) << 1) + (--inlen ? to_uchar(in[3]) >> 7 : 0)) & 0x1f] : '=');
    if (!--outlen)
      break;
    *out++ = (inlen ? b32str[(to_uchar(in[3]) >> 2) & 0x1f] : '=');
    if (!--outlen)
      break;
    *out++ = (inlen ? b32str[((to_uchar(in[3]) << 3) + (--inlen ? to_uchar(in[4]) >> 5 : 0)) & 0x1f] : '=');
    if (!--outlen)
      break;
    *out++ = inlen ? b32str[to_uchar(in[4]) & 0x1f] : '=';
    if (!--outlen)
      break;
    if (inlen)
      inlen--;
    if (inlen)
      in += 5;
  }
  if (outlen)
    *out = '\0';
}
```