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

```asm
<encode_devnode_name>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %rdx,-0x38(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  je     L71
  cmpq   $0x0,-0x30(%rbp)
  jne    L28
L71:
  mov    $0xffffffff,%eax
  jmp    L6
L28:
  movq   $0x0,-0x10(%rbp)
  movq   $0x0,-0x8(%rbp)
  jmp    L163
L21:
  mov    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,%rdi
  call   <utf8_encoded_valid_unichar@plt>
  mov    %eax,-0x14(%rbp)
  cmpl   $0x1,-0x14(%rbp)
  jle    L173
  mov    -0x38(%rbp),%rax
  sub    -0x8(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x14(%rbp),%eax
  cltq
  cmp    %rax,%rdx
  jb     L161
  mov    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  lea    (%rdx,%rax,1),%rsi
  mov    -0x30(%rbp),%rdx
  mov    -0x8(%rbp),%rax
  lea    (%rdx,%rax,1),%rcx
  mov    -0x14(%rbp),%eax
  mov    %eax,%edx
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x14(%rbp),%eax
  cltq
  add    %rax,-0x8(%rbp)
  mov    -0x14(%rbp),%eax
  sub    $0x1,%eax
  cltq
  add    %rax,-0x10(%rbp)
  jmp    L137
L173:
  mov    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x5c,%al
  je     L54
  mov    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    $0x0,%esi
  mov    %eax,%edi
  call   <whitelisted_char_for_devnode@plt>
  test   %eax,%eax
  jne    L179
L54:
  mov    -0x38(%rbp),%rax
  sub    -0x8(%rbp),%rax
  cmp    $0x3,%rax
  jbe    L174
  mov    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  mov    -0x30(%rbp),%rcx
  mov    -0x8(%rbp),%rdx
  add    %rdx,%rcx
  mov    %eax,%edx
  lea    D8(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <sprintf@plt>
  addq   $0x4,-0x8(%rbp)
  jmp    L137
L179:
  mov    -0x38(%rbp),%rax
  cmp    -0x8(%rbp),%rax
  je     L24
  mov    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    -0x30(%rbp),%rcx
  mov    -0x8(%rbp),%rdx
  add    %rcx,%rdx
  movzbl (%rax),%eax
  mov    %al,(%rdx)
  addq   $0x1,-0x8(%rbp)
L137:
  addq   $0x1,-0x10(%rbp)
L163:
  mov    -0x28(%rbp),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L21
  mov    -0x38(%rbp),%rax
  cmp    -0x8(%rbp),%rax
  je     L78
  mov    -0x30(%rbp),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    $0x0,%eax
  jmp    L6
L161:
  nop
  jmp    L23
L174:
  nop
  jmp    L23
L24:
  nop
  jmp    L23
L78:
  nop
L23:
  mov    $0xffffffff,%eax
L6:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: data_tag: D8
type_infered: string

tool: D8: \x%02x

assistant: ```c
int encode_devnode_name(const char *str, char *str_enc, size_t len) {
  size_t i, j;
  if (str == NULL || str_enc == NULL)
    return -1;
  for (i = 0, j = 0; str[i] != '\0'; i++) {
    int seqlen;
    seqlen = utf8_encoded_valid_unichar(&str[i]);
    if (seqlen > 1) {
      if (len - j < (size_t)seqlen)
        goto err;
      memcpy(&str_enc[j], &str[i], seqlen);
      j += seqlen;
      i += (seqlen - 1);
    } else if (str[i] == '\\' || !whitelisted_char_for_devnode(str[i], NULL)) {
      if (len - j < 4)
        goto err;
      sprintf(&str_enc[j], "\\x%02x", (unsigned char)str[i]);
      j += 4;
    } else {
      if (len - j < 1)
        goto err;
      str_enc[j] = str[i];
      j++;
    }
  }
  if (len - j < 1)
    goto err;
  str_enc[j] = '\0';
  return 0;
err:
  return -1;
}
```