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

```asm
<kvp_mac_to_if_name>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  lea    D6(%rip),%rbp
  push   %rbx
  sub    $0x238,%rsp
  mov    %rdi,0x18(%rsp)
  mov    %rbp,%rdi
  mov    %fs:0x28,%rax
  mov    %rax,0x228(%rsp)
  xor    %eax,%eax
  call   <opendir@plt>
  mov    %rax,0x8(%rsp)
  test   %rax,%rax
  je     L90
  lea    0x120(%rsp),%r14
  mov    %rbp,%rcx
  mov    $0x100,%esi
  lea    D0(%rip),%rdx
  mov    %r14,%rdi
  call   <snprintf@plt>
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %eax,%eax
  add    %r14,%rax
  mov    %rax,0x10(%rsp)
  nopl   0x0(%rax,%rax,1)
L40:
  mov    0x8(%rsp),%rdi
  call   <readdir@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L100
  mov    0x10(%rsp),%rax
  mov    %r14,%rdi
  movb   $0x0,(%rax)
  mov    (%r12),%rsi
  call   <strcat@plt>
  lea    D25(%rip),%rsi
  mov    %r14,%rdi
  call   <strcat@plt>
  lea    D28(%rip),%rsi
  mov    %r14,%rdi
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L40
  lea    0x20(%rsp),%rdi
  mov    %rax,%rdx
  mov    $0x100,%esi
  call   <fgets@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  jne    L29
L72:
  mov    %r13,%rdi
  call   <fclose@plt>
  jmp    L40
  nopl   0x0(%rax)
L29:
  mov    $0xa,%esi
  mov    %rax,%rdi
  call   <strchr@plt>
  test   %rax,%rax
  je     L32
  movb   $0x0,(%rax)
L32:
  xor    %ebx,%ebx
  jmp    L30
  nopl   0x0(%rax)
L51:
  mov    %ebx,%edx
  add    $0x1,%ebx
  lea    0x0(%rbp,%rdx,1),%r15
  movsbl (%r15),%edi
  call   <toupper@plt>
  mov    %al,(%r15)
L30:
  mov    %rbp,%rdi
  call   <strlen@plt>
  cmp    %ebx,%eax
  ja     L51
  mov    0x18(%rsp),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  jne    L72
  mov    (%r12),%rdi
  call   <strdup@plt>
  mov    %r13,%rdi
  mov    %rax,%r12
  call   <fclose@plt>
L100:
  mov    0x8(%rsp),%rdi
  call   <closedir@plt>
L101:
  mov    0x228(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L45
  add    $0x238,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L90:
  xor    %r12d,%r12d
  jmp    L101
L45:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: tag: D6
type_infered: string
name: parse_data
arguments: tag: D0
type_infered: string
name: parse_data
arguments: tag: D25
type_infered: string
name: parse_data
arguments: tag: D28
type_infered: string

tool: D6: /sys/class/net/

tool: D0: %s

tool: D25: /address

tool: D28: r

assistant: ```c
char *kvp_mac_to_if_name(char *mac) {
  DIR *dir;
  struct dirent *entry;
  FILE *file;
  char *p, *q, *x;
  char *if_name = NULL;
  char buf[256];
  char *kvp_net_dir = "/sys/class/net/";
  char dev_id[256];
  unsigned int i;
  dir = opendir(kvp_net_dir);
  if (dir == NULL)
    return NULL;
  snprintf(dev_id, sizeof(dev_id), "%s", kvp_net_dir);
  q = dev_id + strlen(kvp_net_dir);
  while ((entry = readdir(dir)) != NULL) {
    *q = '\0';
    strcat(dev_id, entry->d_name);
    strcat(dev_id, "/address");
    file = fopen(dev_id, "r");
    if (file == NULL)
      continue;
    p = fgets(buf, sizeof(buf), file);
    if (p) {
      x = strchr(p, '\n');
      if (x)
        *x = '\0';
      for (i = 0; i < strlen(p); i++)
        p[i] = toupper(p[i]);
      if (!strcmp(p, mac)) {
        if_name = strdup(entry->d_name);
        fclose(file);
        break;
      }
    }
    fclose(file);
  }
  closedir(dir);
  return if_name;
}
```