user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<tilde_expansion>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x48(%rbp)
  movq   $0x0,-0x38(%rbp)
  cmpq   $0x0,-0x48(%rbp)
  jne    L4
  mov    $0x0,%eax
  jmp    L104
L4:
  mov    -0x48(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x7e,%al
  je     L25
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strdup@plt>
  jmp    L104
L25:
  mov    -0x48(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  je     L112
  mov    -0x48(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L15
L112:
  lea    D1(%rip),%rax
  mov    %rax,%rdi
  call   <getenv@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jne    L109
  mov    $0x0,%eax
  call   <getuid@plt>
  mov    %eax,%edi
  call   <getpwuid@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  je     L109
  mov    -0x20(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,-0x38(%rbp)
L109:
  mov    -0x48(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,-0x30(%rbp)
  jmp    L24
L15:
  mov    -0x48(%rbp),%rax
  mov    $0x2f,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  mov    %rax,-0x30(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  jne    L52
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  movslq %eax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x30(%rbp)
L52:
  mov    -0x30(%rbp),%rax
  sub    -0x48(%rbp),%rax
  mov    %eax,-0x3c(%rbp)
  mov    -0x3c(%rbp),%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x28(%rbp)
  mov    -0x3c(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    -0x48(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    -0x28(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    -0x3c(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movb   $0x0,(%rax)
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <getpwnam@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  je     L87
  mov    -0x20(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,-0x38(%rbp)
L87:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L24:
  cmpq   $0x0,-0x38(%rbp)
  jne    L42
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strdup@plt>
  jmp    L104
L42:
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %ebx,%eax
  add    $0x1,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  mov    -0x38(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcpy@plt>
  mov    -0x30(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x18(%rbp),%rax
L104:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_label: D1
type_guessed: string

tool: D1: HOME

assistant: ```c
char *tilde_expansion(const char *str) {
  char *prefix = NULL;
  const char *replace;
  char *user, *ret;
  struct passwd *pw;
  int len;
  if (!str)
    return NULL;
  if (str[0] != '~')
    return strdup(str);
  if ((str[1] == '/') || (str[1] == '\0')) {
    prefix = getenv("HOME");
    if (!prefix) {
      pw = getpwuid(getuid());
      if (pw)
        prefix = pw->pw_dir;
    }
    replace = str + 1;
  } else {
    replace = strchr(str, '/');
    if (!replace)
      replace = str + strlen(str);
    len = replace - str;
    user = malloc(len + 1);
    strncpy(user, str + 1, len - 1);
    user[len] = '\0';
    pw = getpwnam(user);
    if (pw)
      prefix = pw->pw_dir;
    free(user);
  }
  if (!prefix)
    return strdup(str);
  ret = malloc(strlen(prefix) + strlen(replace) + 1);
  strcpy(ret, prefix);
  strcat(ret, replace);
  return ret;
}
```