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

```asm
<generate_trap_h>:
  endbr64
  push   %rbp
  push   %rbx
  sub    $0x418,%rsp
  mov    %rdi,%rcx
  mov    %esi,%ebp
  mov    %fs:0x28,%rax
  mov    %rax,0x408(%rsp)
  xor    %eax,%eax
  mov    %rsp,%rbx
  mov    %esi,%r8d
  lea    D102(%rip),%rdx
  mov    $0x400,%esi
  mov    %rbx,%rdi
  call   <snprintf@plt>
  lea    D106(%rip),%rsi
  mov    %rbx,%rdi
  call   <fopen@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L9
L19:
  lea    D44(%rip),%rsi
  mov    %rbx,%rdi
  call   <print_head@plt>
  mov    %ebp,%edx
  lea    D32(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %ebp,%edx
  lea    D98(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %rbx,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
  mov    %rbx,%rcx
  mov    $0x14,%edx
  mov    $0x1,%esi
  lea    D90(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbx,%rcx
  mov    $0x16,%edx
  mov    $0x1,%esi
  lea    D86(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbx,%rcx
  mov    $0x7,%edx
  mov    $0x1,%esi
  lea    D31(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbx,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
  mov    %rbx,%rcx
  mov    $0xe,%edx
  mov    $0x1,%esi
  lea    D99(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbx,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
  mov    %ebp,%esi
  mov    %rbx,%rdi
  call   <generate_traps_as_macros@plt>
  mov    %rbx,%rcx
  mov    $0xc,%edx
  mov    $0x1,%esi
  lea    D96(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbx,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
  mov    %ebp,%edx
  lea    D35(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <fprintf@plt>
  mov    %rbx,%rdi
  call   <fclose@plt>
  mov    0x408(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L17
  add    $0x418,%rsp
  pop    %rbx
  pop    %rbp
  ret
L9:
  lea    D57(%rip),%rdi
  call   <perror@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L19
L17:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: data_tag: D102
type: string
name: disassemble_data
arguments: data_tag: D106
type: string
name: disassemble_data
arguments: data_tag: D44
type: string
name: disassemble_data
arguments: data_tag: D32
type: string
name: disassemble_data
arguments: data_tag: D98
type: string
name: disassemble_data
arguments: data_tag: D90
type: string
name: disassemble_data
arguments: data_tag: D86
type: string
name: disassemble_data
arguments: data_tag: D31
type: string
name: disassemble_data
arguments: data_tag: D99
type: string
name: disassemble_data
arguments: data_tag: D96
type: string
name: disassemble_data
arguments: data_tag: D35
type: string
name: disassemble_data
arguments: data_tag: D57
type: string

tool: D102: %s/trap%i.h

tool: D106: w+

tool: D44: gen-syscall

tool: D32: #ifndef _MINT_TRAP%i_H


tool: D98: #define _MINT_TRAP%i_H


tool: D90: #ifndef _COMPILER_H


tool: D86: #include <compiler.h>


tool: D31: #endif


tool: D99: __BEGIN_DECLS


tool: D96: __END_DECLS


tool: D35: #endif /* _MINT_TRAP%i_H */


tool: D57: fopen

assistant: ```c
void generate_trap_h(const char *path, int nr) {
  char buf[1024];
  FILE *f;
  snprintf(buf, sizeof(buf), "%s/trap%i.h", path, nr);
  f = fopen(buf, "w+");
  if (!f) {
    perror("fopen");
    exit(1);
  }
  print_head(f, "gen-syscall");
  fprintf(f, "#ifndef _MINT_TRAP%i_H\n", nr);
  fprintf(f, "#define _MINT_TRAP%i_H\n", nr);
  fprintf(f, "\n");
  fprintf(f, "#ifndef _COMPILER_H\n");
  fprintf(f, "#include <compiler.h>\n");
  fprintf(f, "#endif\n");
  fprintf(f, "\n");
  fprintf(f, "__BEGIN_DECLS\n");
  fprintf(f, "\n");
  if (1)
    generate_traps_as_macros(f, nr);
  else
    generate_trap_protos(f, nr);
  fprintf(f, "__END_DECLS\n");
  fprintf(f, "\n");
  fprintf(f, "#endif /* _MINT_TRAP%i_H */\n", nr);
  fclose(f);
}
```