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

```asm
<func_basename_dir>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,-0x20(%rbp)
  movl   $0x0,-0x2c(%rbp)
  movl   $0x0,-0x30(%rbp)
  lea    D29(%rip),%rax
  cmp    %rax,-0x48(%rbp)
  je     L85
  mov    -0x48(%rbp),%rax
  movzbl (%rax),%eax
  mov    $0x62,%edx
  cmp    %dl,%al
  jne    L175
  mov    -0x48(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L85
  lea    D5(%rip),%rax
  mov    -0x48(%rbp),%rdx
  add    $0x1,%rdx
  mov    %rax,%rsi
  mov    %edx,%edi
  call   <strcmp@plt>
  test   %eax,%eax
  jne    L175
L85:
  mov    $0x1,%eax
  jmp    L145
L175:
  mov    $0x0,%eax
L145:
  mov    %eax,-0x28(%rbp)
  cmpl   $0x0,-0x28(%rbp)
  sete   %al
  movzbl %al,%eax
  mov    %eax,-0x24(%rbp)
  jmp    L128
L209:
  mov    -0x30(%rbp),%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x18(%rbp)
  jmp    L69
L30:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  je     L34
  subq   $0x1,-0x18(%rbp)
L69:
  mov    -0x18(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  jb     L146
  cmpl   $0x0,-0x28(%rbp)
  je     L30
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  jne    L30
  jmp    L146
L34:
  nop
L146:
  mov    -0x18(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  jb     L32
  cmpl   $0x0,-0x24(%rbp)
  je     L32
  addq   $0x1,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  sub    -0x10(%rbp),%rax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rcx
  mov    -0x38(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <variable_buffer_output@plt>
  mov    %rax,-0x38(%rbp)
  jmp    L171
L32:
  mov    -0x18(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  jb     L223
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  jne    L223
  mov    -0x18(%rbp),%rax
  sub    -0x10(%rbp),%rax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rcx
  mov    -0x38(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <variable_buffer_output@plt>
  mov    %rax,-0x38(%rbp)
  jmp    L171
L223:
  cmpl   $0x0,-0x24(%rbp)
  je     L194
  mov    -0x38(%rbp),%rax
  mov    $0x2,%edx
  lea    D14(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <variable_buffer_output@plt>
  mov    %rax,-0x38(%rbp)
  jmp    L171
L194:
  mov    -0x30(%rbp),%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rcx
  mov    -0x38(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <variable_buffer_output@plt>
  mov    %rax,-0x38(%rbp)
L171:
  mov    -0x38(%rbp),%rax
  mov    $0x1,%edx
  lea    D19(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <variable_buffer_output@plt>
  mov    %rax,-0x38(%rbp)
  movl   $0x1,-0x2c(%rbp)
L128:
  lea    -0x30(%rbp),%rdx
  lea    -0x20(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <find_next_token@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L209
  cmpl   $0x0,-0x2c(%rbp)
  je     L20
  subq   $0x1,-0x38(%rbp)
L20:
  mov    -0x38(%rbp),%rax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L23
  call   <__stack_chk_fail@plt>
L23:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: data_label: D29
type_infered: string
name: disassemble_data
arguments: data_label: D5
type_infered: string
name: disassemble_data
arguments: data_label: D14
type_infered: string
name: disassemble_data
arguments: data_label: D19
type_infered: string

tool: D29: basename

tool: D5: asename

tool: D14: ./

tool: D19:  

assistant: ```c
char *func_basename_dir(char *o, char **argv, const char *funcname) {
  const char *p3 = argv[0];
  const char *p2;
  int doneany = 0;
  unsigned int len = 0;
  int is_basename = ((funcname) == ("basename") || (*(funcname) == *("basename") && (*(funcname) == '\0' || !strcmp((funcname) + 1, ("basename") + 1))));
  int is_dir = !is_basename;
  while ((p2 = find_next_token(&p3, &len)) != 0) {
    const char *p = p2 + len;
    while (p >= p2 && (!is_basename || *p != '.')) {
      if (((*p) == '/'))
        break;
      --p;
    }
    if (p >= p2 && (is_dir))
      o = variable_buffer_output(o, p2, ++p - p2);
    else if (p >= p2 && (*p == '.'))
      o = variable_buffer_output(o, p2, p - p2);
    else if (is_dir)
      o = variable_buffer_output(o, "./", 2);
    else
      o = variable_buffer_output(o, p2, len);
    o = variable_buffer_output(o, " ", 1);
    doneany = 1;
  }
  if (doneany)
    --o;
  return o;
}
```