user: What is the c source code of the assembly code below?

```asm
<pgm_load>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%r13
  mov    %rdx,%r12
  mov    %rcx,%r14
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  lea    D15(%rip),%rsi
  call   <fopen@plt>
  test   %rax,%rax
  je     L50
  mov    %rax,%rbx
  mov    %rsp,%r15
  mov    $0x20,%edx
  mov    %r15,%rsi
  mov    %rax,%rdi
  call   <nextToken@plt>
  lea    D4(%rip),%rsi
  mov    %r15,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L29
  mov    $0x20,%edx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <nextToken@plt>
  mov    %r15,%rdi
  call   <atoi@plt>
  mov    %eax,0x0(%r13)
  mov    $0x20,%edx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <nextToken@plt>
  mov    %r15,%rdi
  call   <atoi@plt>
  mov    %eax,(%r12)
  mov    $0x20,%edx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <nextToken@plt>
  mov    %r15,%rdi
  call   <atoi@plt>
  mov    %eax,%r15d
  mov    0x0(%r13),%ebp
  imul   (%r12),%ebp
  cmp    $0xff,%eax
  jg     L79
  mov    $0x4,%esi
  mov    %ebp,%edi
  call   <calloc@plt>
  mov    %rax,%rdi
  mov    %rax,(%r14)
  mov    %rbx,%rcx
  mov    %ebp,%edx
  mov    $0x4,%esi
  call   <fread@plt>
  cmp    %ebp,%eax
  jne    L28
L37:
  mov    %rbx,%rdi
  call   <fclose@plt>
L21:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L55
  mov    %r15d,%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L29:
  mov    %rsp,%rcx
  mov    %rbp,%rdx
  lea    D20(%rip),%rsi
  mov    $0x0,%edi
  call   <errx@plt>
L85:
  mov    $0xffffffff,%r15d
  jmp    L21
L28:
  mov    (%r14),%rdi
  call   <free@plt>
  jmp    L85
L79:
  mov    $0x4,%esi
  mov    %ebp,%edi
  call   <calloc@plt>
  mov    %rax,%rdi
  mov    %rax,(%r14)
  mov    %rbx,%rcx
  mov    %ebp,%edx
  mov    $0x4,%esi
  call   <fread@plt>
  cmp    %ebp,%eax
  je     L37
  mov    (%r14),%rdi
  call   <free@plt>
  jmp    L85
L50:
  mov    $0xffffffff,%r15d
  jmp    L21
L55:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: data_tag: D15
type_guessed: string
name: parse_data
arguments: data_tag: D4
type_guessed: string
name: parse_data
arguments: data_tag: D20
type_guessed: string

tool: D15: r

tool: D4: P5

tool: D20: File %s has signature "%s"; expected "P5"

assistant: ```c
int pgm_load(const char *name, int *w, int *h, uint8_t **img) {
  int n, maxval = -1;
  FILE *fp = fopen(name, "r");
  if (fp) {
    char buf[32];
    n = nextToken(fp, buf, 32);
    if (strcmp(buf, "P5")) {
      errx(0, "File %s has signature \"%s\"; expected \"P5\"", name, buf);
      return -1;
    }
    nextToken(fp, buf, 32);
    *w = atoi(buf);
    nextToken(fp, buf, 32);
    *h = atoi(buf);
    nextToken(fp, buf, 32);
    maxval = atoi(buf);
    n = (*w) * (*h);
    if (maxval < 256) {
      *img = calloc(n, sizeof(uint8_t));
      if (fread(*img, sizeof(uint8_t), n, fp) != n) {
        free(*img);
        return -1;
      }
    } else {
      *img = calloc(n, sizeof(uint16_t));
      if (fread(*img, sizeof(uint16_t), n, fp) != n) {
        free(*img);
        return -1;
      }
    }
    fclose(fp);
  }
  return maxval;
}
```