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

```asm
<main>:
  endbr64
  push   %r15
  xor    %esi,%esi
  mov    $0x400,%edx
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x828,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x818(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%r15
  lea    0x410(%rsp),%r13
  mov    %r15,%rdi
  call   <memset@plt>
  xor    %esi,%esi
  mov    $0x400,%edx
  mov    %r13,%rdi
  call   <memset@plt>
  lea    D200(%rip),%rdi
  call   <getenv@plt>
  lea    D156(%rip),%rdi
  mov    %rax,%rbp
  call   <getenv@plt>
  test   %rbp,%rbp
  je     L74
  mov    %rax,%r12
  test   %rax,%rax
  je     L101
  mov    %rbp,%rdi
  call   <strlen@plt>
  cmp    $0x39c,%eax
  ja     L62
  mov    %rbp,%rsi
  mov    %r15,%rdi
  call   <strcat@plt>
  mov    $0x4,%edx
  lea    D0(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L88
L111:
  lea    D246(%rip),%rsi
  mov    %r15,%rdi
  call   <strcat@plt>
L182:
  mov    %rbp,%rsi
  mov    %r13,%rdi
  call   <strcat@plt>
  lea    D124(%rip),%rsi
  mov    %r13,%rdi
  call   <strcat@plt>
  lea    D138(%rip),%rsi
  mov    %r15,%rdi
  call   <fopen@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L120
  lea    D32(%rip),%rsi
  mov    %r13,%rdi
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L45
  mov    %rax,%rcx
  mov    $0x28,%edx
  mov    $0x1,%esi
  xor    %r13d,%r13d
  lea    D62(%rip),%r12
  lea    D142(%rip),%r15
  mov    %r12,%rdi
  call   <fwrite@plt>
  mov    %rbp,%rcx
  mov    $0x28,%edx
  mov    %r12,%rdi
  mov    $0x1,%esi
  lea    0xd(%rsp),%r12
  call   <fwrite@plt>
  mov    %rbp,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
  mov    %rbp,%rsi
  mov    $0xa,%edi
  call   <fputc@plt>
  mov    %rbp,%rcx
  mov    $0x1c,%edx
  mov    $0x1,%esi
  lea    D151(%rip),%rdi
  call   <fwrite@plt>
  jmp    L229
  nopw   0x0(%rax,%rax,1)
L78:
  add    $0x1,%r13d
L157:
  mov    %rbp,%rcx
  mov    $0x2,%edx
  mov    $0x1,%esi
  mov    %r15,%rdi
  call   <fwrite@plt>
  movzbl %bl,%edx
  lea    D56(%rip),%rsi
  mov    %r12,%rdi
  call   <sprintf@plt>
  mov    %rbp,%rsi
  mov    %r12,%rdi
  call   <fputs@plt>
  mov    %rbp,%rcx
  mov    $0x2,%edx
  mov    $0x1,%esi
  lea    D233(%rip),%rdi
  call   <fwrite@plt>
L229:
  mov    %r14,%rdi
  call   <getc@plt>
  mov    %r14,%rdi
  mov    %eax,%ebx
  call   <feof@plt>
  test   %rax,%rax
  jne    L163
  xor    %esi,%esi
  mov    $0x2,%edx
  mov    %r12,%rdi
  call   <memset@plt>
  cmp    $0x10,%r13d
  jne    L78
  mov    %rbp,%rsi
  mov    $0xa,%edi
  mov    $0x1,%r13d
  call   <fputc@plt>
  jmp    L157
  nopl   0x0(%rax,%rax,1)
L163:
  mov    %rbp,%rcx
  mov    $0x4,%edx
  mov    $0x1,%esi
  lea    D242(%rip),%rdi
  call   <fwrite@plt>
  mov    %r14,%rdi
  call   <fclose@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  xor    %edi,%edi
  call   <exit@plt>
  xor    %eax,%eax
L134:
  mov    0x818(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L46
  add    $0x828,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L88:
  mov    $0x4,%edx
  lea    D66(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  je     L65
  mov    $0x4,%edx
  lea    D238(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  je     L111
  mov    $0x4,%edx
  lea    D236(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  je     L65
  mov    $0x4,%edx
  lea    D114(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  je     L65
  mov    $0x4,%edx
  lea    D181(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  je     L65
  mov    $0x4,%edx
  lea    D14(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  je     L65
  mov    $0x9,%edx
  lea    D85(%rip),%rsi
  mov    %r12,%rdi
  call   <strncmp@plt>
  test   %rax,%rax
  jne    L111
L65:
  lea    D143(%rip),%rsi
  mov    %r15,%rdi
  call   <strcat@plt>
  jmp    L182
L62:
  lea    D60(%rip),%rdi
  call   <puts@plt>
L29:
  or     $0xffffffff,%eax
  jmp    L134
L101:
  lea    D97(%rip),%rdi
  call   <puts@plt>
  jmp    L29
L74:
  lea    D47(%rip),%rdi
  call   <puts@plt>
  jmp    L29
L45:
  mov    %r13,%rsi
  lea    D199(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L29
L120:
  mov    %r15,%rsi
  lea    D130(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L29
L46:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D200
type: string
name: extract_symbolic_data
arguments: data_label: D156
type: string
name: extract_symbolic_data
arguments: data_label: D0
type: string
name: extract_symbolic_data
arguments: data_label: D246
type: string
name: extract_symbolic_data
arguments: data_label: D124
type: string
name: extract_symbolic_data
arguments: data_label: D138
type: string
name: extract_symbolic_data
arguments: data_label: D32
type: string
name: extract_symbolic_data
arguments: data_label: D62
type: string
name: extract_symbolic_data
arguments: data_label: D142
type: string
name: extract_symbolic_data
arguments: data_label: D151
type: string
name: extract_symbolic_data
arguments: data_label: D56
type: string
name: extract_symbolic_data
arguments: data_label: D233
type: string
name: extract_symbolic_data
arguments: data_label: D242
type: string
name: extract_symbolic_data
arguments: data_label: D66
type: string
name: extract_symbolic_data
arguments: data_label: D238
type: string
name: extract_symbolic_data
arguments: data_label: D236
type: string
name: extract_symbolic_data
arguments: data_label: D114
type: string
name: extract_symbolic_data
arguments: data_label: D181
type: string
name: extract_symbolic_data
arguments: data_label: D14
type: string
name: extract_symbolic_data
arguments: data_label: D85
type: string
name: extract_symbolic_data
arguments: data_label: D143
type: string
name: extract_symbolic_data
arguments: data_label: D60
type: string
name: extract_symbolic_data
arguments: data_label: D97
type: string
name: extract_symbolic_data
arguments: data_label: D47
type: string
name: extract_symbolic_data
arguments: data_label: D199
type: string
name: extract_symbolic_data
arguments: data_label: D130
type: string

tool: D200: RT28xx_DIR

tool: D156: CHIPSET

tool: D0: 2860

tool: D246: /common/rt2860.bin

tool: D124: /include/firmware.h

tool: D138: r

tool: D32: w

tool: D62: /* AUTO GEN PLEASE DO NOT MODIFY IT */ 


tool: D142: 0x

tool: D151: UCHAR FirmwareImage [] = { 


tool: D56: %02x

tool: D233: , 

tool: D242: } ;


tool: D66: 2870

tool: D238: 3090

tool: D236: 2070

tool: D114: 3070

tool: D181: 3572

tool: D14: 3370

tool: D85: USB_COMBO

tool: D143: /common/rt2870.bin

tool: D60: Environment value "RT28xx_DIR" is too long!

tool: D97: Environment value "CHIPSET" not export 

tool: D47: Environment value "RT28xx_DIR" not export 

tool: D199: Can't open write file %s 


tool: D130: Can't read file %s 


assistant: ```c
int main(int argc, char *argv[]) {
  FILE *infile, *outfile;
  char infname[1024];
  char outfname[1024];
  char *rt28xxdir;
  char *chipset;
  int i = 0;
  unsigned char c;
  memset(infname, 0, 1024);
  memset(outfname, 0, 1024);
  rt28xxdir = (char *)getenv("RT28xx_DIR");
  chipset = (char *)getenv("CHIPSET");
  if (!rt28xxdir) {
    printf("Environment value \"RT28xx_DIR\" not export \n");
    return -1;
  }
  if (!chipset) {
    printf("Environment value \"CHIPSET\" not export \n");
    return -1;
  }
  if (strlen(rt28xxdir) > (sizeof(infname) - 100)) {
    printf("Environment value \"RT28xx_DIR\" is too long!\n");
    return -1;
  }
  strcat(infname, rt28xxdir);
  if (strncmp(chipset, "2860", 4) == 0)
    strcat(infname, "/common/rt2860.bin");
  else if (strncmp(chipset, "2870", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3090", 4) == 0)
    strcat(infname, "/common/rt2860.bin");
  else if (strncmp(chipset, "2070", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3070", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3572", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "3370", 4) == 0)
    strcat(infname, "/common/rt2870.bin");
  else if (strncmp(chipset, "USB_COMBO", 9) == 0)
    strcat(infname, "/common/rt2870.bin");
  else
    strcat(infname, "/common/rt2860.bin");
  strcat(outfname, rt28xxdir);
  strcat(outfname, "/include/firmware.h");
  infile = fopen(infname, "r");
  if (infile == (FILE *)NULL) {
    printf("Can't read file %s \n", infname);
    return -1;
  }
  outfile = fopen(outfname, "w");
  if (outfile == (FILE *)NULL) {
    printf("Can't open write file %s \n", outfname);
    return -1;
  }
  fputs("/* AUTO GEN PLEASE DO NOT MODIFY IT */ \n", outfile);
  fputs("/* AUTO GEN PLEASE DO NOT MODIFY IT */ \n", outfile);
  fputs("\n", outfile);
  fputs("\n", outfile);
  fputs("UCHAR FirmwareImage [] = { \n", outfile);
  while (1) {
    char cc[3];
    c = getc(infile);
    if (feof(infile))
      break;
    memset(cc, 0, 2);
    if (i >= 16) {
      fputs("\n", outfile);
      i = 0;
    }
    fputs("0x", outfile);
    sprintf(cc, "%02x", c);
    fputs(cc, outfile);
    fputs(", ", outfile);
    i++;
  }
  fputs("} ;\n", outfile);
  fclose(infile);
  fclose(outfile);
  exit(0);
}
```