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

```asm
<encodeUTF8str>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x60,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x38(%rbp)
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %rax,-0x48(%rbp)
  movq   $0x0,-0x30(%rbp)
  movq   $0x0,-0x28(%rbp)
  mov    -0x48(%rbp),%rax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x38(%rbp)
  mov    -0x48(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    -0x38(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  jmp    L187
L168:
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  mov    %al,-0x49(%rbp)
  cmpb   $0x1f,-0x49(%rbp)
  jbe    L283
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x22,%al
  je     L283
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x5c,%al
  je     L283
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jne    L86
L283:
  movq   $0x0,-0x40(%rbp)
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  lea    -0x40(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %eax,%edi
  call   <encodeControlChar@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x40(%rbp),%rcx
  mov    -0x28(%rbp),%rdi
  mov    -0x10(%rbp),%rdx
  lea    -0x48(%rbp),%rsi
  mov    -0x38(%rbp),%rax
  mov    %rdi,%r8
  mov    %rax,%rdi
  call   <insertSubString@plt>
  mov    %rax,-0x38(%rbp)
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x40(%rbp),%rax
  add    %rax,-0x28(%rbp)
  addq   $0x1,-0x30(%rbp)
  jmp    L187
L86:
  movzbl -0x49(%rbp),%eax
  test   %al,%al
  jns    L69
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x40(%rbp)
  movq   $0x0,-0x20(%rbp)
  movzbl -0x49(%rbp),%eax
  test   %al,%al
  jns    L270
  movzbl -0x49(%rbp),%eax
  and    $0x40,%eax
  test   %eax,%eax
  jne    L270
  movq   $0x1,-0x20(%rbp)
  jmp    L19
L270:
  movzbl -0x49(%rbp),%eax
  test   %al,%al
  jns    L132
  movzbl -0x49(%rbp),%eax
  and    $0x40,%eax
  test   %eax,%eax
  je     L132
  movzbl -0x49(%rbp),%eax
  and    $0x20,%eax
  test   %eax,%eax
  jne    L132
  movq   $0x2,-0x20(%rbp)
  jmp    L19
L132:
  movzbl -0x49(%rbp),%eax
  test   %al,%al
  jns    L113
  movzbl -0x49(%rbp),%eax
  and    $0x40,%eax
  test   %eax,%eax
  je     L113
  movzbl -0x49(%rbp),%eax
  and    $0x20,%eax
  test   %eax,%eax
  je     L113
  movzbl -0x49(%rbp),%eax
  and    $0x10,%eax
  test   %eax,%eax
  jne    L113
  movq   $0x3,-0x20(%rbp)
  jmp    L19
L113:
  movzbl -0x49(%rbp),%eax
  test   %al,%al
  jns    L19
  movzbl -0x49(%rbp),%eax
  and    $0x40,%eax
  test   %eax,%eax
  je     L19
  movzbl -0x49(%rbp),%eax
  and    $0x20,%eax
  test   %eax,%eax
  je     L19
  movzbl -0x49(%rbp),%eax
  and    $0x10,%eax
  test   %eax,%eax
  je     L19
  movzbl -0x49(%rbp),%eax
  and    $0x8,%eax
  test   %eax,%eax
  jne    L19
  movq   $0x4,-0x20(%rbp)
L19:
  cmpq   $0x1,-0x20(%rbp)
  je     L159
  cmpq   $0x4,-0x20(%rbp)
  jne    L125
L159:
  mov    -0x20(%rbp),%rax
  add    %rax,-0x30(%rbp)
  jmp    L187
L125:
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  lea    -0x40(%rbp),%rdx
  mov    -0x20(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <highCharToUnicode@plt>
  mov    %rax,-0x18(%rbp)
  mov    -0x40(%rbp),%rcx
  mov    -0x28(%rbp),%rdi
  mov    -0x18(%rbp),%rdx
  lea    -0x48(%rbp),%rsi
  mov    -0x38(%rbp),%rax
  mov    %rdi,%r8
  mov    %rax,%rdi
  call   <insertSubString@plt>
  mov    %rax,-0x38(%rbp)
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x40(%rbp),%rax
  add    %rax,-0x28(%rbp)
  mov    -0x20(%rbp),%rax
  add    %rax,-0x30(%rbp)
  jmp    L187
L69:
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  mov    -0x38(%rbp),%rcx
  mov    -0x28(%rbp),%rdx
  add    %rcx,%rdx
  movzbl (%rax),%eax
  mov    %al,(%rdx)
  addq   $0x1,-0x28(%rbp)
  addq   $0x1,-0x30(%rbp)
L187:
  mov    -0x58(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L168
  mov    -0x38(%rbp),%rax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L257
  call   <__stack_chk_fail@plt>
L257:
  leave
  ret
```

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;
}
```