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

```asm
<generate_filename>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rsi,%r13
  mov    %edx,0x18(%rsp)
  mov    %ecx,0x1c(%rsp)
  mov    %r8d,0xc(%rsp)
  mov    %r9,0x10(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  lea    0xffa(%rsi),%rbp
  lea    -0x1(%rdi),%rdx
  lea    -0x1(%rsi),%rax
  lea    0x20(%rsp),%r14
  lea    D5(%rip),%r15
L35:
  mov    %rdx,%r12
  add    $0x1,%rdx
  mov    %rax,%rbx
  add    $0x1,%rax
  movzbl (%rdx),%ecx
  mov    %cl,(%rax)
  cmp    %rax,%rbp
  jbe    L147
  test   %cl,%cl
  je     L147
  cmp    $0x25,%cl
  jne    L35
  movzbl 0x1(%rdx),%ecx
  cmp    $0x65,%cl
  je     L242
  jg     L76
  cmp    $0x25,%cl
  je     L287
  cmp    $0x63,%cl
  jne    L109
  cmpl   $0x0,0xc(%rsp)
  jne    L198
L197:
  lea    0x2(%r12),%rdx
  mov    %rbx,%rax
  jmp    L109
L76:
  cmp    $0x78,%cl
  je     L264
  cmp    $0x79,%cl
  jne    L109
  cmpl   $0x0,0xc(%rsp)
  jne    L68
L252:
  lea    0x2(%r12),%rdx
  mov    %rbx,%rax
  jmp    L109
L264:
  cmpl   $0x0,0xc(%rsp)
  jne    L285
L206:
  lea    0x2(%r12),%rdx
  mov    %rbx,%rax
L109:
  cmpb   $0x0,(%rdx)
  jne    L35
L147:
  movb   $0x0,(%rax)
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L135
  mov    %r13,%rax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L285:
  mov    0x18(%rsp),%edx
  mov    %r15,%rsi
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  lea    0x1f(%rsp),%rax
L81:
  add    $0x1,%rax
  mov    %rbx,%rcx
  add    $0x1,%rbx
  movzbl (%rax),%edx
  mov    %dl,(%rbx)
  cmp    %rbx,%rbp
  jbe    L122
  test   %dl,%dl
  jne    L81
L122:
  mov    %rcx,%rbx
  jmp    L206
L68:
  mov    0x1c(%rsp),%edx
  mov    %r15,%rsi
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  lea    0x1f(%rsp),%rax
L258:
  add    $0x1,%rax
  mov    %rbx,%rcx
  add    $0x1,%rbx
  movzbl (%rax),%edx
  mov    %dl,(%rbx)
  cmp    %rbx,%rbp
  jbe    L183
  test   %dl,%dl
  jne    L258
L183:
  mov    %rcx,%rbx
  jmp    L252
L198:
  mov    0x1c(%rsp),%ecx
  mov    0x18(%rsp),%edx
  lea    D2(%rip),%rsi
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  lea    0x1f(%rsp),%rax
L208:
  add    $0x1,%rax
  mov    %rbx,%rcx
  add    $0x1,%rbx
  movzbl (%rax),%edx
  mov    %dl,(%rbx)
  cmp    %rbx,%rbp
  jbe    L284
  test   %dl,%dl
  jne    L208
L284:
  mov    %rcx,%rbx
  jmp    L197
L242:
  mov    0x10(%rsp),%rax
  lea    -0x1(%rax),%rdx
L195:
  add    $0x1,%rdx
  mov    %rbx,%rax
  add    $0x1,%rbx
  movzbl (%rdx),%ecx
  mov    %cl,(%rbx)
  cmp    %rbx,%rbp
  jbe    L170
  test   %cl,%cl
  jne    L195
L170:
  lea    0x2(%r12),%rdx
  jmp    L109
L287:
  lea    0x2(%r12),%rdx
  mov    %rbx,%rax
  jmp    L109
L135:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: label: D5
datatype: string
name: parse_data
arguments: label: D2
datatype: string

tool: D5: %i

tool: D2: _%i_%i

assistant: ```c
char *generate_filename(const char *template, char *result, int x, int y, int pages, const char *extension) {
  char *a;
  const char *b;
  char *end = result + 4090;
  b = template - 1, a = result - 1;
  while ((*++a = *++b)) {
    if (a >= end)
      break;
    if (*b == '%') {
      switch (b[1]) {
      case 'x':
        a--;
        if (pages) {
          char text[8];
          char *e = text - 1;
          sprintf(text, "%i", x);
          while ((*++a = *++e))
            if (a >= end)
              break;
          a--;
        }
        b++;
        break;
      case 'y':
        a--;
        if (pages) {
          char text[8];
          char *e = text - 1;
          sprintf(text, "%i", y);
          while ((*++a = *++e))
            if (a >= end)
              break;
          a--;
        }
        b++;
        break;
      case 'c':
        a--;
        if (pages) {
          char text[8];
          char *e = text - 1;
          sprintf(text, "_%i_%i", x, y);
          while ((*++a = *++e))
            if (a >= end)
              break;
          a--;
        }
        b++;
        break;
      case 'e':
        a--;
        {
          const char *e = extension - 1;
          while ((*++a = *++e))
            if (a >= end)
              break;
          a--;
        }
        b++;
        break;
      case '%':
        a--;
        b++;
        break;
      }
      if (!*b)
        break;
    }
  }
  *a = 0;
  return result;
}
```