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

```asm
<main>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x10(%rbp)
  cmpl   $0x1,-0x44(%rbp)
  jle    L76
  mov    -0x50(%rbp),%rax
  add    $0x8,%rax
  mov    (%rax),%rax
  lea    D7(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x18(%rbp)
L76:
  cmpq   $0x0,-0x18(%rbp)
  jne    L108
  mov    $0x0,%eax
  call   <usage@plt>
  mov    $0x2,%eax
  jmp    L129
L108:
  lea    D24(%rip),%rax
  mov    %rax,%rsi
  lea    D15(%rip),%rax
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L3
  mov    $0x0,%eax
  call   <usage@plt>
  mov    $0x2,%eax
  jmp    L129
L3:
  lea    -0x2c(%rbp),%rdx
  lea    -0x30(%rbp),%rcx
  mov    -0x18(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <spng_dec_read_size@plt>
  mov    -0x2c(%rbp),%edx
  mov    -0x30(%rbp),%ecx
  mov    -0x10(%rbp),%rax
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <write_ppm_header@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <spng_dec_read_palet@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <spng_dec_go_to_image_data@plt>
  mov    -0x18(%rbp),%rax
  mov    $0x3,%esi
  mov    %rax,%rdi
  call   <spng_dec_read_bits@plt>
  movl   $0x0,-0x20(%rbp)
  jmp    L75
L101:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <spng_dec_read_literal@plt>
  movl   $0x0,-0x24(%rbp)
  jmp    L124
L10:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <spng_dec_read_literal@plt>
  mov    %eax,-0x1c(%rbp)
  cmpl   $0xff,-0x1c(%rbp)
  ja     L81
  lea    -0x31(%rbp),%rdi
  lea    -0x32(%rbp),%rcx
  lea    -0x33(%rbp),%rdx
  mov    -0x1c(%rbp),%esi
  mov    -0x18(%rbp),%rax
  mov    %rdi,%r8
  mov    %rax,%rdi
  call   <spng_dec_literal_to_rgb@plt>
  addl   $0x1,-0x24(%rbp)
  movzbl -0x31(%rbp),%eax
  movzbl %al,%ecx
  movzbl -0x32(%rbp),%eax
  movzbl %al,%edx
  movzbl -0x33(%rbp),%eax
  movzbl %al,%esi
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <write_ppm_pixel@plt>
  jmp    L124
L81:
  mov    -0x1c(%rbp),%edx
  mov    -0x18(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <spng_dec_read_length@plt>
  mov    %eax,-0x1c(%rbp)
  mov    -0x1c(%rbp),%eax
  add    %eax,-0x24(%rbp)
  mov    -0x18(%rbp),%rax
  mov    $0x5,%esi
  mov    %rax,%rdi
  call   <spng_dec_read_bits@plt>
  movl   $0x0,-0x28(%rbp)
  jmp    L1
L21:
  movzbl -0x31(%rbp),%eax
  movzbl %al,%ecx
  movzbl -0x32(%rbp),%eax
  movzbl %al,%edx
  movzbl -0x33(%rbp),%eax
  movzbl %al,%esi
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <write_ppm_pixel@plt>
  addl   $0x1,-0x28(%rbp)
L1:
  mov    -0x28(%rbp),%eax
  cmp    -0x1c(%rbp),%eax
  jb     L21
L124:
  mov    -0x30(%rbp),%eax
  cmp    %eax,-0x24(%rbp)
  jb     L10
  addl   $0x1,-0x20(%rbp)
L75:
  mov    -0x2c(%rbp),%eax
  cmp    %eax,-0x20(%rbp)
  jb     L101
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    $0x1,%eax
L129:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L4
  call   <__stack_chk_fail@plt>
L4:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: label: D7
datatype: string
name: retrieve_data
arguments: label: D24
datatype: string
name: retrieve_data
arguments: label: D15
datatype: string

tool: D7: r

tool: D24: w

tool: D15: out.ppm

assistant: ```c
int main(int argc, char *argv[]) {
  unsigned char r, g, b;
  unsigned int i, x, y;
  unsigned int w, h;
  unsigned int lit;
  FILE *fp = NULL;
  FILE *fpppm = NULL;
  if (argc > 1) {
    fp = fopen(argv[1], "r");
  }
  if (!fp) {
    usage();
    return 2;
  }
  fpppm = fopen("out.ppm", "w");
  if (!fpppm) {
    usage();
    return 2;
  }
  spng_dec_read_size(fp, &w, &h);
  write_ppm_header(fpppm, w, h);
  spng_dec_read_palet(fp);
  spng_dec_go_to_image_data(fp);
  spng_dec_read_bits(fp, 3);
  y = 0;
  while (y < h) {
    spng_dec_read_literal(fp);
    x = 0;
    while (x < w) {
      lit = spng_dec_read_literal(fp);
      if (lit < 256) {
        spng_dec_literal_to_rgb(fp, lit, &r, &g, &b);
        x++;
        write_ppm_pixel(fpppm, r, g, b);
      } else {
        lit = spng_dec_read_length(fp, lit);
        x += lit;
        spng_dec_read_bits(fp, 5);
        for (i = 0; i < lit; i++) {
          write_ppm_pixel(fpppm, r, g, b);
        }
      }
    }
    y++;
  }
  fclose(fpppm);
  fclose(fp);
  return 1;
}
```