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
  mov    %rsi,%rbx
  sub    $0x838,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x828(%rsp)
  xor    %eax,%eax
  cmp    $0x1,%edi
  jle    L111
L22:
  mov    0x8(%rbx),%rdi
  lea    D86(%rip),%rsi
  call   <fopen@plt>
  lea    D44(%rip),%rsi
  lea    D87(%rip),%rdi
  mov    %rax,%r15
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %r15,%r15
  je     L83
  test   %rax,%rax
  je     L83
L29:
  mov    %rbp,%rcx
  mov    $0x5b,%edx
  mov    $0x1,%esi
  lea    D42(%rip),%rdi
  lea    0x18(%rsp),%r12
  call   <fwrite@plt>
  lea    0x20(%rsp),%rax
  movl   $0x0,0xc(%rsp)
  lea    D4(%rip),%r14
  mov    %rax,(%rsp)
  nopl   (%rax)
L103:
  mov    (%rsp),%rdi
  mov    %r15,%rdx
  mov    $0x800,%esi
  call   <fgets@plt>
  test   %rax,%rax
  je     L17
  movzbl 0x20(%rsp),%eax
  addl   $0x1,0xc(%rsp)
  cmp    $0x3b,%al
  jbe    L76
L78:
  mov    (%rsp),%rdi
  mov    $0xa,%edx
  mov    %r12,%rsi
  call   <strtol@plt>
  mov    %eax,%ebx
  mov    0x18(%rsp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,0x18(%rsp)
  movzbl 0x1(%rax),%eax
  cmp    $0x54,%al
  je     L163
  cmp    $0x46,%al
  je     L163
  mov    0xc(%rsp),%esi
  lea    D13(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  mov    0x18(%rsp),%rdx
  movzbl (%rdx),%eax
L163:
  xor    %r13d,%r13d
  cmp    $0x54,%al
  lea    0x2(%rdx),%rax
  mov    %rax,0x18(%rsp)
  movzbl 0x2(%rdx),%edx
  sete   %r13b
  cmp    $0x2c,%dl
  jne    L35
  jmp    L103
  nopl   (%rax)
L77:
  mov    0x18(%rsp),%rdi
L143:
  mov    $0xa,%edx
  mov    %r12,%rsi
  call   <strtol@plt>
  mov    %ebx,%edx
  mov    %r13d,%ecx
  mov    %r14,%rsi
  mov    %eax,%r8d
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fprintf@plt>
  mov    0x18(%rsp),%rax
  movzbl (%rax),%edx
  cmp    $0x2c,%dl
  je     L103
L35:
  cmp    $0x3b,%dl
  jne    L77
  lea    0x1(%rax),%rdi
  mov    %rdi,0x18(%rsp)
  jmp    L143
L76:
  movabs $0xf7fffffeffffdbff,%rcx
  bt     %rax,%rcx
  jae    L103
  jmp    L78
  nopl   0x0(%rax)
L17:
  mov    %rbp,%rcx
  mov    $0xd,%edx
  mov    $0x1,%esi
  lea    D8(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r15,%rdi
  call   <fclose@plt>
  mov    0x828(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L167
  add    $0x838,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L83:
  lea    D64(%rip),%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L29
L111:
  mov    (%rsi),%rsi
  lea    D37(%rip),%rdi
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L22
L167:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D86
datatype: string
name: unpack_data
arguments: tag: D44
datatype: string
name: unpack_data
arguments: tag: D87
datatype: string
name: unpack_data
arguments: tag: D42
datatype: string
name: unpack_data
arguments: tag: D4
datatype: string
name: unpack_data
arguments: tag: D13
datatype: string
name: unpack_data
arguments: tag: D8
datatype: string
name: unpack_data
arguments: tag: D64
datatype: string
name: unpack_data
arguments: tag: D37
datatype: string

tool: D86: r

tool: D44: w

tool: D87: mnc_list.h

tool: D42: typedef struct {
    int mcc;
    int bT;
    int mnc;
} MNC_LIST;
MNC_LIST mnc_list[] = {


tool: D4: {%d,%d,%d},


tool: D13: Error in file - field 2 line %d


tool: D8: {0, 0, 0}
};


tool: D64: can't open files

tool: D37: Usage %s <ConnectionProfile.csv>
Generates mnc_list.h

assistant: ```c
int main(int argc, char *argv[]) {
  FILE *in, *out;
  char line[2048], *pStr;
  int mcc;
  int bThreeDigit, mnc;
  int current_line = 0;
  if (argc < 2) {
    printf("Usage %s <ConnectionProfile.csv>\nGenerates mnc_list.h", argv[0]);
    exit(1);
  }
  in = fopen(argv[1], "r");
  out = fopen("mnc_list.h", "w");
  if (in == NULL || out == NULL) {
    printf("can't open files\n");
    exit(1);
  }
  fprintf(out, "typedef struct {\n    int mcc;\n    int bT;\n    int mnc;\n} MNC_LIST;\nMNC_LIST mnc_list[] = {\n");
  while (fgets(line, 2048, in) != NULL) {
    current_line++;
    if (*line == ';' || *line == ' ' || *line == '\r' || *line == '\n')
      continue;
    mcc = strtol(line, &pStr, 10);
    pStr++;
    if (*pStr != 'T' && *pStr != 'F') {
      printf("Error in file - field 2 line %d\n", current_line);
      exit(1);
    }
    if (*pStr == 'T')
      bThreeDigit = 1;
    else
      bThreeDigit = 0;
    pStr += 2;
    while (*pStr != ',') {
      if (*pStr == ';')
        pStr++;
      mnc = strtol(pStr, &pStr, 10);
      fprintf(out, "{%d,%d,%d},\n", mcc, bThreeDigit, mnc);
    }
  }
  fprintf(out, "{0, 0, 0}\n};\n");
  fclose(out);
  fclose(in);
}
```