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

```asm
<main>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x70,%rsp
  mov    %edi,-0x64(%rbp)
  mov    %rsi,-0x70(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  cmpl   $0x4,-0x64(%rbp)
  je     L131
  cmpl   $0x6,-0x64(%rbp)
  je     L131
  mov    -0x70(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <usage@plt>
L131:
  mov    -0x70(%rbp),%rax
  add    $0x8,%rax
  mov    (%rax),%rax
  lea    D63(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  jne    L122
  lea    D48(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L122:
  cmpl   $0x6,-0x64(%rbp)
  jne    L116
  mov    -0x70(%rbp),%rax
  add    $0x10,%rax
  mov    (%rax),%rax
  lea    D27(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x50(%rbp)
  mov    -0x70(%rbp),%rax
  add    $0x18,%rax
  mov    (%rax),%rax
  lea    D27(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x48(%rbp)
  mov    -0x70(%rbp),%rax
  add    $0x20,%rax
  mov    (%rax),%rax
  mov    $0x0,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <strtoul@plt>
  mov    %rax,-0x40(%rbp)
  mov    -0x70(%rbp),%rax
  add    $0x28,%rax
  mov    (%rax),%rax
  mov    $0x0,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <strtoul@plt>
  mov    %rax,-0x38(%rbp)
  cmpq   $0x0,-0x50(%rbp)
  je     L153
  cmpq   $0x0,-0x48(%rbp)
  jne    L164
L153:
  lea    D17(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L164
L116:
  movq   $0x0,-0x50(%rbp)
  movq   $0x0,-0x48(%rbp)
  mov    -0x70(%rbp),%rax
  add    $0x10,%rax
  mov    (%rax),%rax
  mov    $0x0,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <strtoul@plt>
  mov    %rax,-0x40(%rbp)
  mov    -0x70(%rbp),%rax
  add    $0x18,%rax
  mov    (%rax),%rax
  mov    $0x0,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <strtoul@plt>
  mov    %rax,-0x38(%rbp)
L164:
  mov    -0x40(%rbp),%rax
  movzbl %al,%eax
  test   %rax,%rax
  jne    L72
  mov    -0x38(%rbp),%rax
  movzbl %al,%eax
  test   %rax,%rax
  je     L19
L72:
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L19:
  mov    -0x28(%rbp),%rax
  mov    $0xffffffffffffffff,%rsi
  mov    %rax,%rdi
  call   <FseekEnd@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <ftell@plt>
  movsbl %al,%eax
  add    $0x1,%eax
  cltq
  mov    %rax,-0x20(%rbp)
  mov    -0x70(%rbp),%rax
  add    $0x8,%rax
  mov    (%rax),%rax
  mov    -0x20(%rbp),%rdx
  mov    %rax,%rsi
  lea    D108(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x20(%rbp),%rax
  movzbl %al,%eax
  test   %rax,%rax
  je     L12
  lea    D106(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L12:
  mov    -0x20(%rbp),%rdx
  mov    -0x40(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <negoffset@plt>
  mov    %rax,-0x40(%rbp)
  mov    -0x20(%rbp),%rdx
  mov    -0x38(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <negoffset@plt>
  mov    %rax,-0x38(%rbp)
  mov    -0x40(%rbp),%rax
  add    $0x1000000,%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  sar    $0x10,%rax
  mov    %al,-0x10(%rbp)
  mov    -0x18(%rbp),%rax
  sar    $0x8,%rax
  mov    %al,-0xf(%rbp)
  movzbl -0x10(%rbp),%eax
  not    %eax
  mov    %al,-0xe(%rbp)
  movzbl -0xf(%rbp),%eax
  not    %eax
  mov    %al,-0xd(%rbp)
  mov    -0x38(%rbp),%rax
  add    $0x1000000,%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  sar    $0x10,%rax
  mov    %al,-0xc(%rbp)
  mov    -0x18(%rbp),%rax
  sar    $0x8,%rax
  mov    %al,-0xb(%rbp)
  movzbl -0xc(%rbp),%eax
  not    %eax
  mov    %al,-0xa(%rbp)
  movzbl -0xb(%rbp),%eax
  not    %eax
  mov    %al,-0x9(%rbp)
  movq   $0x0,-0x30(%rbp)
  jmp    L37
L120:
  lea    -0x10(%rbp),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%esi
  lea    D94(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  addq   $0x1,-0x30(%rbp)
L37:
  cmpq   $0x7,-0x30(%rbp)
  jbe    L120
  lea    D119(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  mov    -0x28(%rbp),%rax
  mov    $0xffffffffffffff00,%rsi
  mov    %rax,%rdi
  call   <FseekEnd@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <ftell@plt>
  movsbl %al,%eax
  mov    %eax,%esi
  lea    D15(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x28(%rbp),%rdx
  lea    -0x10(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x8,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
  cmpl   $0x6,-0x64(%rbp)
  jne    L33
  mov    -0x40(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <FseekEnd@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <ftell@plt>
  movsbl %al,%eax
  mov    %eax,%esi
  lea    D15(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L58
L62:
  mov    -0x28(%rbp),%rdx
  lea    -0x51(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
L58:
  mov    -0x50(%rbp),%rdx
  lea    -0x51(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fread@plt>
  cmp    $0x1,%eax
  je     L62
  mov    -0x38(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <FseekEnd@plt>
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <ftell@plt>
  movsbl %al,%eax
  mov    %eax,%esi
  lea    D15(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L112
L14:
  mov    -0x28(%rbp),%rdx
  lea    -0x51(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fwrite@plt>
L112:
  mov    -0x48(%rbp),%rdx
  lea    -0x51(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fread@plt>
  cmp    $0x1,%eax
  je     L14
  mov    -0x50(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
L33:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    $0x0,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L118
  call   <__stack_chk_fail@plt>
L118:
  leave
  ret
```

tool_calls: name: parse_data
arguments: data_tag: D63
type: string
name: parse_data
arguments: data_tag: D48
type: string
name: parse_data
arguments: data_tag: D27
type: string
name: parse_data
arguments: data_tag: D17
type: string
name: parse_data
arguments: data_tag: D16
type: string
name: parse_data
arguments: data_tag: D108
type: string
name: parse_data
arguments: data_tag: D106
type: string
name: parse_data
arguments: data_tag: D94
type: string
name: parse_data
arguments: data_tag: D119
type: string
name: parse_data
arguments: data_tag: D15
type: string

tool: D63: rb+

tool: D48: Error opening firmware image!

tool: D27: rb

tool: D17: Error opening file!

tool: D16: The offsets must be aligned to 0x100

tool: D108: size of %s: 0x%lx


tool: D106: The ROM size must be multiple of 0x100

tool: D94: %02hhx 

tool: 

tool: D15: writing to 0x%lx


assistant: ```c
int main(int argc, char *argv[]) {
  FILE *fp, *fw1, *fw2;
  long offset1, offset2;
  if (argc != 4 && argc != 6)
    usage(argv[0]);
  fp = fopen(argv[1], "rb+");
  if (fp == NULL) {
    puts("Error opening firmware image!");
    exit(1);
  }
  if (argc == 6) {
    fw1 = fopen(argv[2], "rb");
    fw2 = fopen(argv[3], "rb");
    offset1 = strtoul(argv[4], NULL, 0);
    offset2 = strtoul(argv[5], NULL, 0);
    if (fw1 == NULL || fw2 == NULL) {
      puts("Error opening file!");
      exit(1);
    }
  } else {
    fw1 = NULL;
    fw2 = NULL;
    offset1 = strtoul(argv[2], NULL, 0);
    offset2 = strtoul(argv[3], NULL, 0);
  }
  if ((offset1 & 0xff) || (offset2 & 0xff)) {
    puts("The offsets must be aligned to 0x100");
    exit(1);
  }
  long romsz;
  FseekEnd(fp, -1);
  romsz = ftell(fp) + 1;
  printf("size of %s: 0x%lx\n", argv[1], romsz);
  if (romsz & 0xff) {
    puts("The ROM size must be multiple of 0x100");
    exit(1);
  }
  offset1 = negoffset(offset1, romsz);
  offset2 = negoffset(offset2, romsz);
  char offs[8];
  long os;
  os = 0x1000000 + offset1;
  offs[0] = os >> 16;
  offs[1] = os >> 8;
  offs[2] = 0xff - offs[0];
  offs[3] = 0xff - offs[1];
  os = 0x1000000 + offset2;
  offs[4] = os >> 16;
  offs[5] = os >> 8;
  offs[6] = 0xff - offs[4];
  offs[7] = 0xff - offs[5];
  for (size_t i = 0; i < 8; i++)
    printf("%02hhx ", offs[i]);
  puts("");
  FseekEnd(fp, -0x100);
  printf("writing to 0x%lx\n", ftell(fp));
  fwrite(offs, 1, 8, fp);
  if (argc == 6) {
    char c;
    FseekEnd(fp, offset1);
    printf("writing to 0x%lx\n", ftell(fp));
    while (fread(&c, 1, 1, fw1) == 1)
      fwrite(&c, 1, 1, fp);
    FseekEnd(fp, offset2);
    printf("writing to 0x%lx\n", ftell(fp));
    while (fread(&c, 1, 1, fw2) == 1)
      fwrite(&c, 1, 1, fp);
    fclose(fw1);
    fclose(fw2);
  }
  fclose(fp);
  return 0;
}
```