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

```asm
<getmap>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %esi,-0x48(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x30(%rbp)
  movq   $0x0,-0x28(%rbp)
  cmpl   $0xffffffff,-0x44(%rbp)
  jne    L7
  cmpl   $0x0,-0x48(%rbp)
  jne    L5
  lea    D81(%rip),%rax
  jmp    L43
L5:
  lea    D19(%rip),%rax
L43:
  mov    %rax,%rsi
  lea    D41(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <string@plt>
  mov    %rax,-0x18(%rbp)
  jmp    L104
L7:
  cmpl   $0x0,-0x48(%rbp)
  jne    L3
  lea    D81(%rip),%rax
  jmp    L59
L3:
  lea    D19(%rip),%rax
L59:
  mov    -0x44(%rbp),%ecx
  mov    %rax,%rdx
  mov    %ecx,%esi
  lea    D36(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <string@plt>
  mov    %rax,-0x18(%rbp)
L104:
  mov    -0x18(%rbp),%rax
  lea    D118(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L102
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdx
  lea    D103(%rip),%rax
  mov    %rax,%rsi
  mov    $0x0,%edi
  call   <die@plt>
  jmp    L102
L52:
  mov    -0x30(%rbp),%rax
  lea    -0x3c(%rbp),%rsi
  lea    -0x34(%rbp),%rcx
  lea    -0x38(%rbp),%rdx
  mov    %rsi,%r8
  lea    D37(%rip),%rsi
  mov    %rax,%rdi
  call   <sscanf@plt>
  cmp    $0x3,%eax
  je     L111
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdx
  lea    D124(%rip),%rax
  mov    %rax,%rsi
  mov    $0x0,%edi
  call   <die@plt>
L111:
  mov    -0x3c(%rbp),%esi
  mov    -0x34(%rbp),%ecx
  mov    -0x38(%rbp),%edx
  mov    -0x28(%rbp),%rax
  test   %rax,%rax
  je     L109
  lea    D24(%rip),%rax
  jmp    L123
L109:
  lea    D96(%rip),%rax
L123:
  lea    -0x28(%rbp),%rdi
  mov    %esi,%r9d
  mov    %ecx,%r8d
  mov    %edx,%ecx
  mov    %rax,%rdx
  lea    D9(%rip),%rax
  mov    %rax,%rsi
  call   <append@plt>
L102:
  mov    -0x10(%rbp),%rdx
  lea    -0x20(%rbp),%rcx
  lea    -0x30(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <getline@plt>
  test   %rax,%rax
  jns    L52
  mov    -0x28(%rbp),%rax
  test   %rax,%rax
  jne    L0
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdx
  lea    D124(%rip),%rax
  mov    %rax,%rsi
  mov    $0x0,%edi
  call   <die@plt>
L0:
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x28(%rbp),%rax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L46
  call   <__stack_chk_fail@plt>
L46:
  leave
  ret
```

tool_calls: name: read_data
arguments: data_label: D81
type_guessed: string
name: read_data
arguments: data_label: D19
type_guessed: string
name: read_data
arguments: data_label: D41
type_guessed: string
name: read_data
arguments: data_label: D36
type_guessed: string
name: read_data
arguments: data_label: D118
type_guessed: string
name: read_data
arguments: data_label: D103
type_guessed: string
name: read_data
arguments: data_label: D37
type_guessed: string
name: read_data
arguments: data_label: D124
type_guessed: string
name: read_data
arguments: data_label: D24
type_guessed: string
name: read_data
arguments: data_label: D96
type_guessed: string
name: read_data
arguments: data_label: D9
type_guessed: string

tool: D81: gid_map

tool: D19: uid_map

tool: D41: /proc/self/%s

tool: D36: /proc/%d/%s

tool: D118: r

tool: D103: Cannot read %s

tool: D37:  %u %u %u

tool: D124: Invalid map data in %s

tool: D24: ,

tool: 

tool: D9: %s%u:%u:%u

assistant: ```c
char *getmap(pid_t pid, int type) {
  char *line = NULL, *result = NULL, *path;
  size_t size;
  unsigned count, first, lower;
  FILE *file;
  if (pid == -1)
    path = string("/proc/self/%s", ((type) == 0 ? "gid_map" : "uid_map"));
  else
    path = string("/proc/%d/%s", pid, ((type) == 0 ? "gid_map" : "uid_map"));
  if (!(file = fopen(path, "r")))
    die(0, "Cannot read %s", path);
  while (getline(&line, &size, file) >= 0) {
    if (sscanf(line, " %u %u %u", &first, &lower, &count) != 3)
      die(0, "Invalid map data in %s", path);
    append(&result, "%s%u:%u:%u", result ? "," : "", first, lower, count);
  }
  if (!result)
    die(0, "Invalid map data in %s", path);
  fclose(file);
  free(line);
  free(path);
  return result;
}
```