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    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  cmp    $0x2,%edi
  jne    L7
  mov    0x8(%rsi),%rdi
  lea    D4(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L15
  cmpl   $0x1,0x4(%rsp)
  lea    D6(%rip),%r14
  lea    0x3(%rsp),%r12
  lea    D76(%rip),%rbx
  lea    D25(%rip),%r13
  je     L52
  nopl   0x0(%rax)
L78:
  mov    %r14,%rdi
  call   <printf@plt>
  mov    %rbx,%rdi
  mov    %r12,%rsi
  xor    %eax,%eax
  call   <scanf@plt>
  movsbl 0x3(%rsp),%edi
  cmp    $0x51,%dil
  je     L32
  mov    %rbp,%rsi
  lea    0x4(%rsp),%r15
  call   <putc@plt>
  lea    D69(%rip),%rdi
  call   <printf@plt>
  mov    %r15,%rsi
  mov    %r13,%rdi
  xor    %eax,%eax
  call   <scanf@plt>
  mov    0x4(%rsp),%edi
  mov    %rbp,%rsi
  mov    %dil,0x3(%rsp)
  movsbl %dil,%edi
  call   <putc@plt>
  mov    0x4(%rsp),%edi
  mov    %rbp,%rsi
  and    $0xff00,%edi
  mov    %edi,0x4(%rsp)
  sar    $0x8,%edi
  mov    %dil,0x3(%rsp)
  movsbl %dil,%edi
  call   <putc@plt>
  lea    D64(%rip),%rdi
  call   <printf@plt>
  mov    %r15,%rsi
  mov    %r13,%rdi
  xor    %eax,%eax
  call   <scanf@plt>
  mov    0x4(%rsp),%edi
  mov    %rbp,%rsi
  mov    %dil,0x3(%rsp)
  movsbl %dil,%edi
  call   <putc@plt>
  mov    0x4(%rsp),%edi
  mov    %rbp,%rsi
  and    $0xff00,%edi
  mov    %edi,0x4(%rsp)
  sar    $0x8,%edi
  mov    %dil,0x3(%rsp)
  movsbl %dil,%edi
  call   <putc@plt>
  lea    D33(%rip),%rdi
  call   <printf@plt>
  mov    %r15,%rsi
  mov    %r13,%rdi
  xor    %eax,%eax
  call   <scanf@plt>
  mov    0x4(%rsp),%edi
  mov    %rbp,%rsi
  mov    %dil,0x3(%rsp)
  movsbl %dil,%edi
  call   <putc@plt>
  mov    %r12,%rsi
  mov    %rbx,%rdi
  xor    %eax,%eax
  call   <scanf@plt>
  movl   $0x0,0x4(%rsp)
  jmp    L78
  nopl   0x0(%rax)
L32:
  movl   $0x1,0x4(%rsp)
L52:
  mov    %rbp,%rdi
  call   <fclose@plt>
  xor    %eax,%eax
L8:
  mov    0x8(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L55
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L7:
  or     $0xffffffff,%eax
  jmp    L8
L15:
  lea    D73(%rip),%rdi
  call   <printf@plt>
  or     $0xffffffff,%eax
  jmp    L8
L55:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_label: D4
data_type: string
name: read_data
arguments: data_label: D6
data_type: string
name: read_data
arguments: data_label: D76
data_type: string
name: read_data
arguments: data_label: D25
data_type: string
name: read_data
arguments: data_label: D69
data_type: string
name: read_data
arguments: data_label: D64
data_type: string
name: read_data
arguments: data_label: D33
data_type: string
name: read_data
arguments: data_label: D73
data_type: string

tool: D4: w+

tool: D6: Enter type to add: 

tool: D76: %c

tool: D25: %i

tool: D69: X: 

tool: D64: Y: 

tool: D33: Attrib: 

tool: D73: File could not be opened for write+trunc!


assistant: ```c
int main(int argc, char **argv) {
  int i;
  char c;
  if (argc != 2) {
    return -1;
  }
  FILE *filep;
  if ((filep = fopen(argv[1], "w+")) == NULL) {
    printf("File could not be opened for write+trunc!\n");
    return -1;
  }
  while (i != 1) {
    printf("Enter type to add: ");
    scanf("%c", &c);
    if (c != 'Q') {
      putc(c, filep);
      printf("X: ");
      scanf("%i", &i);
      c = i & 0xFF;
      putc(c, filep);
      i = i & 0xFF00;
      c = i / 0x100;
      putc(c, filep);
      printf("Y: ");
      scanf("%i", &i);
      c = i & 0xFF;
      putc(c, filep);
      i = i & 0xFF00;
      c = i / 0x100;
      putc(c, filep);
      printf("Attrib: ");
      scanf("%i", &i);
      c = i & 0xFF;
      putc(c, filep);
      scanf("%c", &c);
      i = 0;
    } else {
      i = 1;
    }
  }
  fclose(filep);
  return 0;
}
```