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

```asm
<main>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  mov    %rsi,%rbp
  sub    $0x20,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  cmp    $0x1,%edi
  jle    L66
L5:
  mov    0x8(%rbp),%r12
  lea    0x8(%rsp),%rdi
  lea    D7(%rip),%rsi
  lea    D55(%rip),%rbp
  mov    %r12,%rdx
  call   <asprintf@plt>
  mov    %r12,%rdx
  lea    0x10(%rsp),%rdi
  lea    D11(%rip),%rsi
  call   <asprintf@plt>
  mov    0x8(%rsp),%rdi
  mov    %rbp,%rsi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L7
  mov    0x10(%rsp),%rdi
  mov    %rbp,%rsi
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L25
  lea    D19(%rip),%rsi
  mov    %r12,%rdi
  call   <fprintf@plt>
  lea    D54(%rip),%rsi
  mov    %rbp,%rdi
  call   <fprintf@plt>
  mov    %rbp,%rsi
  lea    D83(%rip),%rdi
  call   <exec_cmd@plt>
  test   %rax,%rax
  je     L26
L79:
  mov    $0x1,%r13d
L14:
  mov    %r12,%rdi
  call   <fclose@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
L80:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    0x10(%rsp),%rdi
  call   <free@plt>
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L2
  add    $0x20,%rsp
  mov    %r13d,%eax
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L26:
  lea    D15(%rip),%r13
  mov    %rbp,%rdi
  mov    %r13,%rsi
  call   <fprintf@plt>
  lea    D118(%rip),%rsi
  mov    %rbp,%rdi
  call   <fprintf@plt>
  mov    %rbp,%rsi
  lea    D77(%rip),%rdi
  call   <exec_cmd@plt>
  test   %rax,%rax
  jne    L79
  mov    %r13,%rsi
  mov    %rbp,%rdi
  xor    %r13d,%r13d
  call   <fprintf@plt>
  jmp    L14
L66:
  lea    D60(%rip),%rdi
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L5
L7:
  mov    0x8(%rsp),%rsi
  lea    D48(%rip),%rdi
  mov    $0x1,%r13d
  call   <warn@plt>
  jmp    L80
L25:
  mov    0x10(%rsp),%rsi
  lea    D48(%rip),%rdi
  mov    $0x1,%r13d
  call   <warn@plt>
  mov    %r12,%rdi
  call   <fclose@plt>
  jmp    L80
L2:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: label: D7
type: string
name: extract_symbolic_data
arguments: label: D55
type: string
name: extract_symbolic_data
arguments: label: D11
type: string
name: extract_symbolic_data
arguments: label: D19
type: string
name: extract_symbolic_data
arguments: label: D54
type: string
name: extract_symbolic_data
arguments: label: D83
type: string
name: extract_symbolic_data
arguments: label: D15
type: string
name: extract_symbolic_data
arguments: label: D118
type: string
name: extract_symbolic_data
arguments: label: D77
type: string
name: extract_symbolic_data
arguments: label: D60
type: string
name: extract_symbolic_data
arguments: label: D48
type: string

tool: D7: %s/version.h

tool: D55: wt

tool: D11: %s/version.c

tool: D19: extern const char app_version[];
extern const char app_date[];


tool: D54: const char app_version[] = "

tool: D83: git describe --tags --long

tool: D15: ";


tool: D118: const char app_date[] = "

tool: D77: git log -n 1 --format=%ai

tool: D60: usage: mkversion OUTDIR


tool: D48: cannot open %s

assistant: ```c
int main(int argc, char **argv) {
  FILE *fh = NULL, *fc = NULL;
  char *hfile, *cfile;
  const char *outdir;
  int ret = 1;
  if (argc < 2) {
    printf("usage: mkversion OUTDIR\n");
    exit(1);
  }
  outdir = argv[1];
  asprintf(&hfile, "%s/version.h", outdir);
  asprintf(&cfile, "%s/version.c", outdir);
  fh = fopen(hfile, "wt");
  if (fh == NULL) {
    warn("cannot open %s", hfile);
    goto out;
  }
  fc = fopen(cfile, "wt");
  if (fc == NULL) {
    warn("cannot open %s", cfile);
    goto out;
  }
  fprintf(fh, "extern const char app_version[];\n"
              "extern const char app_date[];\n");
  fprintf(fc, "const char app_version[] = \"");
  if (exec_cmd("git describe --tags --long", fc) != 0)
    goto out;
  fprintf(fc, "\";\n");
  fprintf(fc, "const char app_date[] = \"");
  if (exec_cmd("git log -n 1 --format=%ai", fc) != 0)
    goto out;
  fprintf(fc, "\";\n");
  ret = 0;
out:
  if (fh != NULL)
    fclose(fh);
  if (fc != NULL)
    fclose(fc);
  free(hfile);
  free(cfile);
  return ret;
}
```