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

```asm
<read_tree>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  add    $0xffffffffffffff80,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    %rsi,-0x70(%rbp)
  mov    %edx,-0x74(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  lea    -0x48(%rbp),%rdx
  lea    -0x20(%rbp),%rcx
  mov    -0x68(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <read_sha1_file@plt>
  cltq
  mov    %rax,-0x40(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  jne    L22
  mov    $0xffffffff,%eax
  jmp    L111
L22:
  lea    -0x20(%rbp),%rax
  lea    D13(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  je     L60
  mov    $0xffffffff,%eax
  jmp    L111
L69:
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    $0x1,%eax
  mov    %eax,-0x54(%rbp)
  mov    -0x54(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x40(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x38(%rbp)
  mov    -0x40(%rbp),%rax
  mov    $0x20,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  add    $0x1,%rax
  mov    %rax,-0x30(%rbp)
  mov    -0x54(%rbp),%eax
  add    $0x14,%eax
  movslq %eax,%rdx
  mov    -0x48(%rbp),%rax
  cmp    %rax,%rdx
  ja     L112
  lea    -0x58(%rbp),%rdx
  mov    -0x40(%rbp),%rax
  lea    D15(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  cmp    $0x1,%eax
  je     L11
L112:
  mov    $0xffffffff,%eax
  jmp    L111
L11:
  mov    -0x38(%rbp),%rax
  add    $0x14,%rax
  mov    %rax,-0x40(%rbp)
  mov    -0x48(%rbp),%rax
  mov    -0x54(%rbp),%edx
  add    $0x14,%edx
  movslq %edx,%rdx
  sub    %rdx,%rax
  mov    %rax,-0x48(%rbp)
  mov    -0x58(%rbp),%eax
  mov    %eax,%edi
  mov    $0x0,%eax
  call   <S_ISDIR@plt>
  test   %eax,%eax
  je     L91
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x50(%rbp)
  mov    -0x74(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    -0x50(%rbp),%eax
  add    %edx,%eax
  cltq
  mov    %rax,%rdi
  call   <malloc@plt>
  mov    %rax,-0x28(%rbp)
  mov    -0x74(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x70(%rbp),%rcx
  mov    -0x28(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x50(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x74(%rbp),%eax
  movslq %eax,%rcx
  mov    -0x28(%rbp),%rax
  add    %rax,%rcx
  mov    -0x30(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    -0x74(%rbp),%edx
  mov    -0x50(%rbp),%eax
  add    %edx,%eax
  movslq %eax,%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  movb   $0x2f,(%rax)
  mov    -0x74(%rbp),%edx
  mov    -0x50(%rbp),%eax
  add    %edx,%eax
  lea    0x1(%rax),%edx
  mov    -0x28(%rbp),%rcx
  mov    -0x38(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <read_tree>
  mov    %eax,-0x4c(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  cmpl   $0x0,-0x4c(%rbp)
  je     L9
  mov    $0xffffffff,%eax
  jmp    L111
L91:
  mov    -0x58(%rbp),%edi
  mov    -0x30(%rbp),%rcx
  mov    -0x74(%rbp),%edx
  mov    -0x70(%rbp),%rsi
  mov    -0x38(%rbp),%rax
  mov    %edi,%r8d
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <read_one_entry@plt>
  test   %eax,%eax
  jns    L60
  mov    $0xffffffff,%eax
  jmp    L111
L9:
  nop
L60:
  mov    -0x48(%rbp),%rax
  test   %rax,%rax
  jne    L69
  mov    $0x0,%eax
L111:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L12
  call   <__stack_chk_fail@plt>
L12:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_tag: D13
type_infered: string
name: retrieve_data
arguments: data_tag: D15
type_infered: string

tool: D13: tree

tool: D15: %o

assistant: ```c
int read_tree(unsigned char *sha1, const char *base, int baselen) {
  void *buffer;
  unsigned long size;
  char type[20];
  buffer = read_sha1_file(sha1, type, &size);
  if (!buffer)
    return -1;
  if (strcmp(type, "tree"))
    return -1;
  while (size) {
    int len = strlen(buffer) + 1;
    unsigned char *sha1 = buffer + len;
    char *path = strchr(buffer, ' ') + 1;
    unsigned int mode;
    if (size < len + 20 || sscanf(buffer, "%o", &mode) != 1)
      return -1;
    buffer = sha1 + 20;
    size -= len + 20;
    if (S_ISDIR(mode)) {
      int retval;
      int pathlen = strlen(path);
      char *newbase = malloc(baselen + 1 + pathlen);
      memcpy(newbase, base, baselen);
      memcpy(newbase + baselen, path, pathlen);
      newbase[baselen + pathlen] = '/';
      retval = read_tree(sha1, newbase, baselen + pathlen + 1);
      free(newbase);
      if (retval)
        return -1;
      continue;
    }
    if (read_one_entry(sha1, base, baselen, path, mode) < 0)
      return -1;
  }
  return 0;
}
```