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

```asm
<ttynameCheckDir>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,-0x58(%rbp)
  mov    %rsi,-0x60(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  mov    D90(%rip),%eax
  test   %eax,%eax
  jne    L85
  mov    $0x32,%edi
  call   <malloc@plt>
  mov    %rax,D12(%rip)
  mov    D12(%rip),%rax
  test   %rax,%rax
  jne    L171
  mov    $0x0,%eax
  jmp    L158
L171:
  movl   $0x32,D90(%rip)
L85:
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <opendir@plt>
  mov    %rax,-0x40(%rbp)
  cmpq   $0x0,-0x40(%rbp)
  jne    L100
  mov    $0x0,%eax
  jmp    L158
L100:
  movl   $0x0,-0x48(%rbp)
  jmp    L43
L169:
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  lea    0x1(%rax),%ebx
  mov    -0x38(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  add    %ebx,%eax
  add    $0x1,%eax
  mov    %eax,-0x44(%rbp)
  mov    D90(%rip),%eax
  cmp    %eax,-0x44(%rbp)
  jle    L173
  mov    D12(%rip),%rax
  mov    -0x44(%rbp),%edx
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,D20(%rip)
  mov    D20(%rip),%rax
  test   %rax,%rax
  je     L2
  mov    -0x44(%rbp),%eax
  mov    %eax,D20(%rip)
L173:
  mov    -0x38(%rbp),%rax
  mov    (%rax),%rcx
  mov    D20(%rip),%esi
  mov    D20(%rip),%rax
  mov    -0x60(%rbp),%rdx
  mov    %rcx,%r8
  mov    %rdx,%rcx
  lea    D20(%rip),%rdx
  mov    %rax,%rdi
  call   <snprintf@plt>
  mov    D20(%rip),%rax
  lea    -0x30(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <stat@plt>
  cmp    $0xffffffff,%eax
  jne    L52
  jmp    L43
L52:
  mov    -0x28(%rbp),%eax
  mov    %eax,%edi
  call   <S_ISCHR@plt>
  test   %rax,%rax
  je     L43
  mov    -0x58(%rbp),%rax
  mov    (%rax),%rdx
  mov    -0x30(%rbp),%rax
  cmp    %rax,%rdx
  jne    L43
  movl   $0x1,-0x48(%rbp)
  jmp    L119
L43:
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <readdir@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jne    L169
  jmp    L119
L2:
  nop
L119:
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <closedir@plt>
  cmpl   $0x0,-0x48(%rbp)
  je     L33
  mov    D20(%rip),%rax
  jmp    L158
L33:
  mov    $0x0,%eax
L158:
  mov    -0x18(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L91
  call   <__stack_chk_fail@plt>
L91:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D20
type_infered: string

tool: D20: %s/%s

assistant: ```c
char *ttynameCheckDir(const struct stat *fdStat, const char *devDir) {
  DIR *dirh;
  struct dirent *dent;
  static char *ttyPath;
  static int ttyLen = 0;
  struct stat devStat;
  int found;
  int requiredLen;
  if (ttyLen == 0) {
    ttyPath = malloc(50);
    if (ttyPath == NULL)
      return NULL;
    ttyLen = 50;
  }
  dirh = opendir(devDir);
  if (dirh == NULL)
    return NULL;
  found = 0;
  while ((dent = readdir(dirh)) != NULL) {
    requiredLen = strlen(devDir) + 1 + strlen(dent->d_name) + 1;
    if (requiredLen > ttyLen) {
      ttyPath = realloc(ttyPath, requiredLen);
      if (ttyPath == NULL)
        break;
      ttyLen = requiredLen;
    }
    snprintf(ttyPath, ttyLen, "%s/%s", devDir, dent->d_name);
    if (stat(ttyPath, &devStat) == -1)
      continue;
    if (S_ISCHR(devStat.st_mode) && fdStat->st_rdev == devStat.st_rdev) {
      found = 1;
      break;
    }
  }
  closedir(dirh);
  return found ? ttyPath : NULL;
}
```