user: Please show me the C implementation that matches the assembly code listed below:

```asm
<userdefault>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x28(%rbp)
  movl   $0x0,-0x2c(%rbp)
  mov    $0x0,%eax
  call   <geteuid@plt>
  test   %rax,%rax
  je     L146
  cmpl   $0x0,-0x44(%rbp)
  jne    L118
  mov    $0x0,%eax
  call   <getgid@plt>
  jmp    L81
L118:
  mov    $0x0,%eax
  call   <getuid@plt>
L81:
  mov    %eax,%esi
  lea    D17(%rip),%rax
  mov    %rax,%rdi
  call   <string@plt>
  jmp    L142
L146:
  mov    -0x44(%rbp),%eax
  mov    %eax,%esi
  mov    $0xffffffff,%edi
  call   <getmap@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x44(%rbp),%eax
  mov    %eax,%edi
  call   <readranges@plt>
  mov    %rax,-0x18(%rbp)
  jmp    L121
L139:
  mov    -0x10(%rbp),%rax
  mov    %rax,-0x20(%rbp)
  jmp    L75
L0:
  mov    -0x30(%rbp),%edx
  mov    -0x38(%rbp),%eax
  add    %eax,%edx
  mov    -0x3c(%rbp),%eax
  cmp    %eax,%edx
  jbe    L75
  mov    -0x3c(%rbp),%edx
  mov    -0x40(%rbp),%eax
  add    %eax,%edx
  mov    -0x30(%rbp),%eax
  cmp    %eax,%edx
  ja     L19
  jmp    L75
L19:
  mov    -0x3c(%rbp),%edx
  mov    -0x40(%rbp),%eax
  add    %eax,%edx
  mov    -0x30(%rbp),%ecx
  mov    -0x38(%rbp),%eax
  add    %ecx,%eax
  cmp    %eax,%edx
  jae    L91
  mov    -0x30(%rbp),%eax
  mov    -0x3c(%rbp),%edx
  sub    %edx,%eax
  mov    %eax,%ecx
  mov    -0x40(%rbp),%eax
  add    %ecx,%eax
  mov    %eax,-0x38(%rbp)
L91:
  mov    -0x30(%rbp),%edx
  mov    -0x3c(%rbp),%eax
  cmp    %eax,%edx
  jae    L76
  mov    -0x3c(%rbp),%eax
  mov    -0x30(%rbp),%edx
  sub    %edx,%eax
  add    %eax,-0x2c(%rbp)
  mov    -0x30(%rbp),%eax
  mov    -0x3c(%rbp),%edx
  sub    %edx,%eax
  mov    %eax,%ecx
  mov    -0x38(%rbp),%eax
  add    %ecx,%eax
  mov    %eax,-0x38(%rbp)
  mov    -0x3c(%rbp),%eax
  mov    %eax,-0x30(%rbp)
L76:
  mov    -0x38(%rbp),%esi
  mov    -0x30(%rbp),%ecx
  mov    -0x28(%rbp),%rax
  test   %rax,%rax
  je     L54
  lea    D23(%rip),%rax
  jmp    L13
L54:
  lea    D37(%rip),%rax
L13:
  mov    -0x2c(%rbp),%edx
  lea    -0x28(%rbp),%rdi
  mov    %esi,%r9d
  mov    %ecx,%r8d
  mov    %edx,%ecx
  mov    %rax,%rdx
  lea    D16(%rip),%rax
  mov    %rax,%rsi
  call   <append@plt>
  mov    -0x38(%rbp),%eax
  add    %eax,-0x2c(%rbp)
L75:
  lea    -0x40(%rbp),%rcx
  lea    -0x34(%rbp),%rdx
  lea    -0x3c(%rbp),%rsi
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <mapitem@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L0
L121:
  lea    -0x38(%rbp),%rdx
  lea    -0x30(%rbp),%rcx
  mov    -0x18(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <rangeitem@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  jne    L139
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x28(%rbp),%rax
L142:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L129
  call   <__stack_chk_fail@plt>
L129:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: tag: D17
data_type: string
name: unpack_data
arguments: tag: D23
data_type: string
name: unpack_data
arguments: tag: D37
data_type: string
name: unpack_data
arguments: tag: D16
data_type: string

tool: D17: 0:%u:1

tool: D23: ,

tool: 

tool: D16: %s%u:%u:%u

assistant: ```c
char *userdefault(int type) {
  char *cursor, *map, *range, *result = NULL;
  unsigned count, first, index = 0, length, lower, start;
  if (geteuid() != 0)
    return string("0:%u:1", ((unsigned)((type) == 0 ? getgid() : getuid())));
  map = getmap(-1, type);
  range = readranges(type);
  while ((range = rangeitem(range, &start, &length))) {
    cursor = map;
    while ((cursor = mapitem(cursor, &first, &lower, &count))) {
      if (start + length <= first || first + count <= start)
        continue;
      if (first + count < start + length)
        length = start - first + count;
      if (start < first) {
        index += first - start;
        length -= first - start;
        start = first;
      }
      append(&result, "%s%u:%u:%u", result ? "," : "", index, start, length);
      index += length;
    }
  }
  free(map);
  free(range);
  return result;
}
```