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

```asm
<mpgedit_edit_make_output_filename>:
  endbr64
  push   %r15
  mov    %rdi,%r15
  push   %r14
  mov    %rdx,%r14
  push   %r13
  mov    %rsi,%r13
  mov    $0x2e,%esi
  push   %r12
  mov    %r13,%rdi
  push   %rbp
  push   %rbx
  mov    %rcx,%rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  call   <strrchr@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L122
  cmpb   $0x0,0x1(%rax)
  jne    L115
  xor    %ebp,%ebp
L122:
  mov    $0x11,%r12d
  test   %r15,%r15
  je     L113
  mov    %r15,%rdi
  call   <strlen@plt>
  lea    0x11(%rax),%r12d
L113:
  test   %r13,%r13
  je     L12
  mov    %r13,%rdi
  call   <strlen@plt>
  add    %eax,%r12d
L12:
  test   %r14,%r14
  je     L33
  mov    %r14,%rdi
  call   <strlen@plt>
  add    %eax,%r12d
L33:
  mov    %r12d,%edi
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L89
  movb   $0x0,(%rax)
  test   %r15,%r15
  je     L1
  mov    %r15,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  lea    D20(%rip),%rsi
  mov    %r12,%rdi
  call   <strcat@plt>
L1:
  test   %r13,%r13
  je     L36
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <strcat@plt>
L36:
  test   %rbx,%rbx
  je     L37
  lea    D3(%rip),%rsi
  mov    %r12,%rdi
  lea    0xc(%rsp),%r13
  call   <strcat@plt>
  mov    (%rbx),%edx
  lea    D23(%rip),%rsi
  mov    %r13,%rdi
  call   <sprintf@plt>
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <strcat@plt>
  addl   $0x1,(%rbx)
L37:
  test   %r14,%r14
  je     L89
  lea    D28(%rip),%rsi
  mov    %r12,%rdi
  call   <strcat@plt>
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <strcat@plt>
L89:
  test   %rbp,%rbp
  je     L68
  mov    %rbp,%rdi
  call   <free@plt>
L68:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L117
  add    $0x28,%rsp
  mov    %r12,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L115:
  mov    %r13,%rdi
  sub    %r13,%rbp
  lea    0x1(%rax),%r14
  call   <strdup@plt>
  movb   $0x0,(%rax,%rbp,1)
  mov    %rax,%r13
  mov    %rax,%rbp
  jmp    L122
L117:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: tag: D20
type: string
name: read_data
arguments: tag: D3
type: string
name: read_data
arguments: tag: D23
type: string
name: read_data
arguments: tag: D28
type: string

tool: D20: /

tool: D3: _

tool: D23: %d

tool: D28: .

assistant: ```c
char *mpgedit_edit_make_output_filename(char *dir, char *base, char *ext, int *index) {
  char *file;
  char *cp;
  char *cp2 = NULL;
  int dirlen;
  int baselen;
  int extlen;
  char fmtbuf[12];
  cp = strrchr(base, '.');
  if (cp && cp[1]) {
    ext = cp + 1;
    cp2 = strdup(base);
    cp2[cp - base] = '\0';
    base = cp2;
  }
  dirlen = dir ? strlen(dir) : 0;
  baselen = base ? strlen(base) : 0;
  extlen = ext ? strlen(ext) : 0;
  file = malloc(dirlen + sizeof("/") + baselen + sizeof("_") + 11 + sizeof(".") + extlen);
  if (file) {
    file[0] = '\0';
    if (dir) {
      strcat(file, dir);
      strcat(file, "/");
    }
    if (base) {
      strcat(file, base);
    }
    if (index) {
      strcat(file, "_");
      sprintf(fmtbuf, "%d", *index);
      strcat(file, fmtbuf);
      (*index)++;
    }
    if (ext) {
      strcat(file, ".");
      strcat(file, ext);
    }
  }
  if (cp2) {
    free(cp2);
  }
  return file;
}
```