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

```asm
<encodeUTF8str>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  call   <strlen@plt>
  lea    0x1(%rax),%edi
  mov    %rax,0x8(%rsp)
  call   <malloc@plt>
  xor    %esi,%esi
  mov    %rax,%rbp
  mov    0x8(%rsp),%rax
  mov    %rbp,%rdi
  lea    0x1(%rax),%rdx
  call   <memset@plt>
  movsbl (%rbx),%edi
  test   %dil,%dil
  je     L184
  mov    %rbx,%r8
  xor    %r15d,%r15d
  xor    %r14d,%r14d
  movabs $0x400000000002001,%r12
  jmp    L189
  xchg   %ax,%ax
L182:
  lea    -0x22(%rdi),%eax
  cmp    $0x3a,%al
  ja     L44
  bt     %rax,%r12
  jb     L57
L53:
  mov    %dil,0x0(%rbp,%r15,1)
  add    $0x1,%r14
  add    $0x1,%r15
L171:
  lea    (%rbx,%r14,1),%r8
  movsbl (%r8),%edi
  test   %dil,%dil
  je     L184
L189:
  cmp    $0x1f,%dil
  ja     L182
L57:
  lea    0x10(%rsp),%rsi
  add    $0x1,%r14
  movq   $0x0,0x10(%rsp)
  call   <encodeControlChar@plt>
  mov    0x10(%rsp),%rcx
  mov    %r15,%r8
  mov    %rbp,%rdi
  mov    %rax,%r13
  lea    0x8(%rsp),%rsi
  mov    %rax,%rdx
  call   <insertSubString@plt>
  mov    %r13,%rdi
  mov    %rax,%rbp
  call   <free@plt>
  lea    (%rbx,%r14,1),%r8
  add    0x10(%rsp),%r15
  movsbl (%r8),%edi
  test   %dil,%dil
  jne    L189
L184:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L153
  add    $0x28,%rsp
  mov    %rbp,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L44:
  test   %dil,%dil
  jns    L53
  movq   $0x0,0x10(%rsp)
  test   $0x40,%dil
  je     L129
  mov    %edi,%eax
  and    $0x60,%eax
  cmp    $0x40,%al
  je     L174
  cmp    $0x60,%al
  je     L45
L128:
  and    $0x78,%edi
  xor    %esi,%esi
  cmp    $0x70,%dil
  je     L89
L179:
  mov    %r8,%rdi
  lea    0x10(%rsp),%rdx
  call   <highCharToUnicode@plt>
  mov    0x10(%rsp),%rcx
  mov    %r15,%r8
  mov    %rbp,%rdi
  mov    %rax,%r13
  lea    0x8(%rsp),%rsi
  mov    %rax,%rdx
  call   <insertSubString@plt>
  mov    %r13,%rdi
  mov    %rax,%rbp
  call   <free@plt>
  add    0x10(%rsp),%r15
  jmp    L171
  nopl   (%rax)
L129:
  mov    $0x1,%eax
L56:
  add    %rax,%r14
  jmp    L171
  nopl   (%rax)
L174:
  add    $0x2,%r14
  mov    $0x2,%esi
  jmp    L179
  nopl   0x0(%rax,%rax,1)
L45:
  test   $0x10,%dil
  jne    L128
  add    $0x3,%r14
  mov    $0x3,%esi
  jmp    L179
  nopl   0x0(%rax)
L89:
  mov    $0x4,%eax
  jmp    L56
L153:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
char *encodeUTF8str(const char *str) {
  char *out = NULL;
  size_t len = strlen(str);
  size_t i = 0, o = 0;
  out = malloc(sizeof(char) * (len + 1));
  memset(out, 0, len + 1);
  while (str[i] != '\0') {
    unsigned char s = (unsigned char)str[i];
    if (s < 32 || str[i] == '"' || str[i] == '\\' || str[i] == '/') {
      size_t sublen = 0;
      char *substr = encodeControlChar(str[i], &sublen);
      out = insertSubString(out, &len, substr, sublen, o);
      free(substr);
      o += sublen;
      i++;
    } else if (s & 128) {
      char *substr = NULL;
      size_t sublen = 0;
      size_t ulen = 0;
      if ((s & 128) && !(s & 64)) {
        ulen = 1;
      } else if ((s & 128) && (s & 64) && !(s & 32)) {
        ulen = 2;
      } else if ((s & 128) && (s & 64) && (s & 32) && !(s & 16)) {
        ulen = 3;
      } else if ((s & 128) && (s & 64) && (s & 32) && (s & 16) && !(s & 8)) {
        ulen = 4;
      }
      if (ulen == 1 || ulen == 4) {
        i += ulen;
        continue;
      }
      substr = highCharToUnicode(&str[i], ulen, &sublen);
      out = insertSubString(out, &len, substr, sublen, o);
      free(substr);
      o += sublen;
      i += ulen;
    } else {
      out[o] = str[i];
      o++;
      i++;
    }
  }
  return out;
}
```