user: 请将以下的汇编代码转换成C语言代码:

```asm
<readranges>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  movq   $0x0,0x8(%rsp)
  test   %edi,%edi
  jne    L108
  call   <getgid@plt>
  mov    %eax,%esi
  lea    D13(%rip),%rdi
  call   <string@plt>
  lea    D68(%rip),%rdi
L67:
  mov    %rax,0x10(%rsp)
  lea    D79(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%rbp
  mov    0x10(%rsp),%rax
  test   %rbp,%rbp
  je     L17
  lea    D88(%rip),%rdi
  call   <getenv@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L25
L104:
  mov    %rbx,%rdi
  call   <getpwnam@plt>
  test   %rax,%rax
  je     L68
  mov    (%rax),%r12
  mov    $0x0,%eax
  call   <getuid@plt>
  cmp    %rax,%r12
  jne    L68
  jmp    L107
L108:
  mov    $0x0,%eax
  call   <getuid@plt>
  mov    %eax,%esi
  lea    D13(%rip),%rdi
  call   <string@plt>
  lea    D106(%rip),%rdi
  jmp    L67
L25:
  lea    D105(%rip),%rdi
  call   <getenv@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  jne    L104
  mov    $0x0,%eax
  call   <getlogin@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  jne    L104
L68:
  mov    $0x0,%eax
  call   <getuid@plt>
  mov    %rax,%rdi
  call   <getpwuid@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L30
L100:
  mov    0x8(%rbx),%rbx
L107:
  mov    $0x0,%eax
  call   <endpwent@plt>
  lea    D63(%rip),%r14
  lea    D75(%rip),%r15
L7:
  lea    0x20(%rsp),%r13
  lea    0x8(%rsp),%r12
L14:
  mov    %rbp,%rdx
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <getline@plt>
  test   %rax,%rax
  js     L162
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    %rax,%rdx
  mov    %rbx,%rsi
  mov    0x8(%rsp),%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L14
  mov    %rbx,%rdi
  call   <strlen@plt>
  mov    %rsp,%rcx
  lea    0x4(%rsp),%rdx
  add    0x8(%rsp),%rax
  mov    %rax,%rdi
  lea    0x18(%rsp),%r8
  mov    %r14,%rsi
  call   <sscanf@plt>
  cmp    $0x1,%eax
  jle    L14
  mov    %rbx,%rdi
  call   <strlen@plt>
  add    0x8(%rsp),%rax
  add    0x18(%rsp),%rax
  movsbl 0x1(%rax),%esi
  mov    %r15,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  je     L14
  lea    0x10(%rsp),%rdi
  mov    (%rsp),%ecx
  mov    0x4(%rsp),%edx
  lea    D17(%rip),%rsi
  call   <append@plt>
  jmp    L7
L30:
  lea    D67(%rip),%rdx
  mov    $0x0,%esi
  mov    $0x1,%edi
  call   <error@plt>
  jmp    L100
L162:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    0x10(%rsp),%rax
L17:
  mov    0x28(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L0
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L0:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D13
datatype: string
name: extract_symbolic_data
arguments: data_tag: D68
datatype: string
name: extract_symbolic_data
arguments: data_tag: D79
datatype: string
name: extract_symbolic_data
arguments: data_tag: D88
datatype: string
name: extract_symbolic_data
arguments: data_tag: D106
datatype: string
name: extract_symbolic_data
arguments: data_tag: D105
datatype: string
name: extract_symbolic_data
arguments: data_tag: D63
datatype: string
name: extract_symbolic_data
arguments: data_tag: D75
datatype: string
name: extract_symbolic_data
arguments: data_tag: D17
datatype: string
name: extract_symbolic_data
arguments: data_tag: D67
datatype: string

tool: D13: %u:1

tool: D68: /etc/subgid

tool: D79: r

tool: D88: USER

tool: D106: /etc/subuid

tool: D105: LOGNAME

tool: D63: :%u:%u%zn

tool: D75: :


tool: D17: ,%u:%u

tool: D67: Failed to validate your username

assistant: ```c
char *readranges(int type) {
  char *line = NULL, *range, *user;
  size_t end, size;
  struct passwd *passwd;
  unsigned length, start;
  FILE *file;
  range = string("%u:1", ((unsigned)((type) == 0 ? getgid() : getuid())));
  if (!(file = fopen(((type) == 0 ? "/etc/subgid" : "/etc/subuid"), "r")))
    return range;
  user = getenv("USER");
  user = user ? user : getenv("LOGNAME");
  user = user ? user : getlogin();
  if (!user || !(passwd = getpwnam(user)) || passwd->pw_uid != getuid()) {
    if (!(passwd = getpwuid(getuid())))
      error(1, 0, "Failed to validate your username");
    user = passwd->pw_name;
  }
  endpwent();
  while (getline(&line, &size, file) >= 0) {
    if (strncmp(line, user, strlen(user)))
      continue;
    if (sscanf(line + strlen(user), ":%u:%u%zn", &start, &length, &end) < 2)
      continue;
    if (strchr(":\n", line[end + strlen(user) + 1]))
      append(&range, ",%u:%u", start, length);
  }
  free(line);
  fclose(file);
  return range;
}
```