user: Please show me the C implementation that matches the assembly code listed below:

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x1028(%rsp)
  xor    %eax,%eax
  mov    %rsi,%rbx
  cmp    $0x3,%edi
  je     L51
  lea    D77(%rip),%rdi
  call   <puts@plt>
  or     $0xffffffff,%edi
  call   <exit@plt>
L51:
  mov    0x8(%rbx),%rdi
  lea    D71(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L86
L41:
  mov    0x10(%rbx),%rdi
  lea    D57(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,(%rsp)
  test   %rax,%rax
  je     L52
L90:
  lea    D39(%rip),%rdi
  lea    0x101e(%rsp),%rbx
  call   <puts@plt>
  mov    %r12,%rdx
  mov    $0xa,%esi
  mov    %rbx,%rdi
  lea    D10(%rip),%r13
  lea    0x6a(%rsp),%rbp
  call   <fgets@plt>
  lea    0x10(%rsp),%rax
  mov    %r13,%rsi
  mov    %rbx,%rdi
  lea    0x12(%rsp),%rdx
  mov    %rax,0x8(%rsp)
  lea    0x472(%rsp),%r14
  call   <sscanf@plt>
  nopl   0x0(%rax,%rax,1)
L66:
  lea    -0x56(%rbp),%r15
  nopl   0x0(%rax)
L62:
  mov    %r12,%rdx
  mov    $0xa,%esi
  mov    %rbx,%rdi
  call   <fgets@plt>
  mov    %r15,%rdx
  mov    %r13,%rsi
  mov    %rbx,%rdi
  call   <sscanf@plt>
  add    $0x2,%r15
  cmp    %rbp,%r15
  jne    L62
  lea    0x56(%r15),%rbp
  cmp    %r14,%rbp
  jne    L66
  mov    (%rsp),%r14
  mov    0x8(%rsp),%rbx
  mov    $0x206,%edx
  xor    %r13d,%r13d
  mov    $0x2,%esi
  mov    $0x205,%eax
  mov    %r14,%rcx
  mov    %rbx,%rdi
  mov    %ax,0x10(%rsp)
  add    $0x10,%rbx
  call   <fwrite@plt>
  mov    %r12,%rdi
  mov    %rbx,%rbp
  lea    D84(%rip),%r12
  call   <fclose@plt>
  mov    %r14,%rdi
  lea    D72(%rip),%r14
  call   <fclose@plt>
  movzwl 0x824(%rsp),%edx
  mov    $0x40c,%esi
  xor    %eax,%eax
  lea    D19(%rip),%rdi
  call   <printf@plt>
  nopl   0x0(%rax,%rax,1)
L31:
  lea    0x0(%r13,%r13,1),%esi
  mov    %r14,%rdi
  lea    -0x10(%rbp),%rbx
  xor    %eax,%eax
  call   <printf@plt>
  nopl   0x0(%rax,%rax,1)
L60:
  movzwl (%rbx),%esi
  mov    %r12,%rdi
  xor    %eax,%eax
  add    $0x2,%rbx
  call   <printf@plt>
  cmp    %rbx,%rbp
  jne    L60
  mov    $0xa,%edi
  add    $0x8,%r13d
  add    $0x10,%rbp
  call   <putchar@plt>
  cmp    $0x208,%r13d
  jne    L31
  mov    $0xa,%edi
  call   <putchar@plt>
  mov    0x1028(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L32
  add    $0x1038,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L86:
  mov    0x8(%rbx),%rsi
  lea    D82(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  or     $0xffffffff,%edi
  call   <exit@plt>
  jmp    L41
L52:
  mov    0x10(%rbx),%rsi
  lea    D91(%rip),%rdi
  call   <printf@plt>
  or     $0xffffffff,%edi
  call   <exit@plt>
  jmp    L90
L32:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D77
type: string
name: retrieve_data
arguments: data_tag: D71
type: string
name: retrieve_data
arguments: data_tag: D57
type: string
name: retrieve_data
arguments: data_tag: D39
type: string
name: retrieve_data
arguments: data_tag: D10
type: string
name: retrieve_data
arguments: data_tag: D84
type: string
name: retrieve_data
arguments: data_tag: D72
type: string
name: retrieve_data
arguments: data_tag: D19
type: string
name: retrieve_data
arguments: data_tag: D82
type: string
name: retrieve_data
arguments: data_tag: D91
type: string

tool: D77: Invalid argument count

tool: D71: r

tool: D57: wb

tool: D39: Starting into the file

tool: D10: %04x


tool: D84:  %04x

tool: D72: %04X:

tool: D19: Wrote %d bytes, last value = 0x%04X


tool: D82: Cannot open %s for reading 


tool: D91: Cannot open %s for writing


assistant: ```c
main(int argc, char **argv) {
  FILE *fpin, *fpout;
  char inny[10];
  unsigned short outy[2048], *pouty;
  int i = 0, j, k;
  if (argc != 3) {
    printf("Invalid argument count\n");
    exit(-1);
  }
  if ((fpin = fopen(argv[1], "r")) == NULL) {
    printf("Cannot open %s for reading \n", argv[1]);
    exit(-1);
  }
  if ((fpout = fopen(argv[2], "wb")) == NULL) {
    printf("Cannot open %s for writing\n", argv[2]);
    exit(-1);
  }
  printf("Starting into the file\n");
  pouty = outy;
  pouty++;
  i++;
  fgets(inny, 10, fpin);
  sscanf(inny, "%04x\n", pouty);
  pouty++;
  i++;
  for (j = 0; j < 12; j++) {
    for (k = 0; k < 43; k++) {
      fgets(inny, 10, fpin);
      sscanf(inny, "%04x\n", pouty);
      pouty++;
      i++;
    }
  }
  outy[0] = i - 1;
  fwrite(outy, 2, i, fpout);
  fclose(fpin);
  fclose(fpout);
  printf("Wrote %d bytes, last value = 0x%04X\n", i * 2, pouty[i - 2]);
  for (j = 0; j < 1 + (12 * 43 + 2) / 8; j++) {
    printf("%04X:", j * 16);
    for (k = 0; k < 8; k++) {
      printf(" %04x", outy[j * 8 + k]);
    }
    printf("\n");
  }
  printf("\n");
}
```