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

```asm
<main>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x20,%rsp
  mov    %rsi,%rbx
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  cmp    $0x1,%edi
  jle    L79
L24:
  mov    0x8(%rbx),%rbx
  lea    0x8(%rsp),%rdi
  mov    %rbx,%rdx
  lea    D53(%rip),%rsi
  call   <asprintf@plt>
  lea    0x10(%rsp),%rdi
  mov    %rbx,%rdx
  lea    D88(%rip),%rsi
  call   <asprintf@plt>
  lea    D41(%rip),%rsi
  mov    0x8(%rsp),%rdi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L19
  lea    D41(%rip),%rsi
  mov    0x10(%rsp),%rdi
  call   <fopen@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L72
  lea    D118(%rip),%rsi
  mov    %r12,%rdi
  call   <fprintf@plt>
  lea    D80(%rip),%rsi
  mov    %rbx,%rdi
  call   <fprintf@plt>
  mov    %rbx,%rsi
  lea    D107(%rip),%rdi
  call   <exec_cmd@plt>
  mov    $0x1,%ebp
  test   %rax,%rax
  je     L16
L77:
  mov    %r12,%rdi
  call   <fclose@plt>
  test   %rbx,%rbx
  je     L15
  mov    %rbx,%rdi
  call   <fclose@plt>
L15:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    0x10(%rsp),%rdi
  call   <free@plt>
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L73
  mov    %ebp,%eax
  add    $0x20,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L79:
  lea    D87(%rip),%rdi
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L24
L19:
  mov    0x8(%rsp),%rsi
  lea    D29(%rip),%rdi
  call   <warn@plt>
  mov    $0x1,%ebp
  jmp    L15
L72:
  mov    0x10(%rsp),%rsi
  lea    D29(%rip),%rdi
  call   <warn@plt>
  mov    $0x1,%ebp
  jmp    L77
L16:
  lea    D8(%rip),%rsi
  mov    %rbx,%rdi
  call   <fprintf@plt>
  lea    D28(%rip),%rsi
  mov    %rbx,%rdi
  call   <fprintf@plt>
  mov    %rbx,%rsi
  lea    D55(%rip),%rdi
  call   <exec_cmd@plt>
  test   %rax,%rax
  jne    L77
  lea    D8(%rip),%rsi
  mov    %rbx,%rdi
  call   <fprintf@plt>
  mov    $0x0,%ebp
  jmp    L77
L73:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: data_tag: D53
type_guessed: string
name: parse_data
arguments: data_tag: D88
type_guessed: string
name: parse_data
arguments: data_tag: D41
type_guessed: string
name: parse_data
arguments: data_tag: D118
type_guessed: string
name: parse_data
arguments: data_tag: D80
type_guessed: string
name: parse_data
arguments: data_tag: D107
type_guessed: string
name: parse_data
arguments: data_tag: D87
type_guessed: string
name: parse_data
arguments: data_tag: D29
type_guessed: string
name: parse_data
arguments: data_tag: D8
type_guessed: string
name: parse_data
arguments: data_tag: D28
type_guessed: string
name: parse_data
arguments: data_tag: D55
type_guessed: string

tool: D53: %s/version.h

tool: D88: %s/version.c

tool: D41: wt

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


tool: D80: const char app_version[] = "

tool: D107: git describe --tags --long

tool: D87: usage: mkversion OUTDIR


tool: D29: cannot open %s

tool: D8: ";


tool: D28: const char app_date[] = "

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

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;
}
```