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

```asm
<ReadPBM1>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    -0x38(%rbp),%rax
  lea    D9(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x18(%rbp)
  movw   $0x0,-0xa(%rbp)
  mov    -0x40(%rbp),%rax
  movq   $0x0,(%rax)
  cmpq   $0x0,-0x18(%rbp)
  je     L98
  mov    -0x18(%rbp),%rdx
  lea    -0xa(%rbp),%rax
  mov    %rdx,%rcx
  mov    $0x2,%edx
  mov    $0x1,%esi
  mov    %rax,%rdi
  call   <fread@plt>
  movzbl -0xa(%rbp),%eax
  cmp    $0x50,%al
  jne    L24
  movzbl -0x9(%rbp),%eax
  cmp    $0x31,%al
  jne    L24
  mov    -0x50(%rbp),%rax
  movl   $0x0,(%rax)
  mov    -0x50(%rbp),%rax
  mov    (%rax),%edx
  mov    -0x48(%rbp),%rax
  mov    %edx,(%rax)
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <getc@plt>
  mov    %al,-0x21(%rbp)
  mov    -0x18(%rbp),%rdx
  lea    -0x21(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <PPM_scan_ws@plt>
  jmp    L142
L53:
  mov    -0x48(%rbp),%rax
  mov    (%rax),%edx
  mov    %edx,%eax
  shl    $0x2,%eax
  add    %edx,%eax
  add    %eax,%eax
  mov    %eax,%edx
  movzbl -0x21(%rbp),%eax
  movzbl %al,%eax
  add    %edx,%eax
  lea    -0x30(%rax),%edx
  mov    -0x48(%rbp),%rax
  mov    %edx,(%rax)
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <getc@plt>
  mov    %al,-0x21(%rbp)
L142:
  movzbl -0x21(%rbp),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L53
  mov    -0x18(%rbp),%rdx
  lea    -0x21(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <PPM_scan_ws@plt>
  jmp    L206
L154:
  mov    -0x50(%rbp),%rax
  mov    (%rax),%edx
  mov    %edx,%eax
  shl    $0x2,%eax
  add    %edx,%eax
  add    %eax,%eax
  mov    %eax,%edx
  movzbl -0x21(%rbp),%eax
  movzbl %al,%eax
  add    %edx,%eax
  lea    -0x30(%rax),%edx
  mov    -0x50(%rbp),%rax
  mov    %edx,(%rax)
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <getc@plt>
  mov    %al,-0x21(%rbp)
L206:
  movzbl -0x21(%rbp),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L154
  movzbl -0x21(%rbp),%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <isspace@plt>
  test   %eax,%eax
  je     L9
  mov    -0x48(%rbp),%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jle    L263
  mov    -0x50(%rbp),%rax
  mov    (%rax),%eax
  test   %eax,%eax
  jle    L263
  mov    -0x48(%rbp),%rax
  mov    (%rax),%edx
  mov    -0x50(%rbp),%rax
  mov    (%rax),%eax
  imul   %edx,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    -0x40(%rbp),%rdx
  mov    %rax,(%rdx)
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  je     L107
  movl   $0x0,-0x1c(%rbp)
  jmp    L97
L138:
  lea    -0x20(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  lea    D0(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <fscanf@plt>
  cmp    $0x1,%eax
  jne    L0
  mov    -0x20(%rbp),%eax
  test   %eax,%eax
  js     L20
  mov    -0x20(%rbp),%eax
  cmp    $0x1,%eax
  jg     L20
  mov    -0x20(%rbp),%eax
  test   %eax,%eax
  je     L104
  mov    $0x0,%edx
  jmp    L273
L104:
  mov    $0xffffffff,%edx
L273:
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rcx
  mov    -0x1c(%rbp),%eax
  cltq
  add    %rcx,%rax
  mov    %dl,(%rax)
  addl   $0x1,-0x1c(%rbp)
L97:
  mov    -0x48(%rbp),%rax
  mov    (%rax),%edx
  mov    -0x50(%rbp),%rax
  mov    (%rax),%eax
  imul   %edx,%eax
  cmp    %eax,-0x1c(%rbp)
  jl     L138
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    $0x0,%eax
  jmp    L269
L98:
  nop
  jmp    L175
L24:
  nop
  jmp    L175
L9:
  nop
  jmp    L175
L263:
  nop
L175:
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  test   %rax,%rax
  je     L246
  mov    -0x40(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <free@plt>
L246:
  mov    -0x40(%rbp),%rax
  movq   $0x0,(%rax)
  cmpq   $0x0,-0x18(%rbp)
  je     L87
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
L87:
  mov    $0xffffffff,%eax
  jmp    L269
L0:
  nop
  jmp    L115
L20:
  nop
L115:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    $0xfffffffe,%eax
  jmp    L269
L107:
  nop
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    $0xfffffffd,%eax
L269:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L256
  call   <__stack_chk_fail@plt>
L256:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: tag: D9
type_infered: string
name: disassemble_data
arguments: tag: D0
type_infered: string

tool: D9: r

tool: D0: %d

assistant: ```c
int ReadPBM1(const char *fname, unsigned char **data, int *w, int *h) {
  FILE *fp = fopen(fname, "r");
  unsigned char buf[2] = {0};
  unsigned char c;
  int i, g;
  *data = NULL;
  if (!fp)
    goto close_fail;
  fread(buf, 1, 2, fp);
  if (buf[0] != 'P' || buf[1] != '1')
    goto close_fail;
  *w = *h = 0;
  c = getc(fp);
  PPM_scan_ws(&c, fp);
  while (isdigit(c)) {
    *w = 10 * (*w) + c - '0';
    c = getc(fp);
  }
  PPM_scan_ws(&c, fp);
  while (isdigit(c)) {
    *h = 10 * (*h) + c - '0';
    c = getc(fp);
  }
  if (!isspace(c))
    goto close_fail;
  if (*w <= 0 || *h <= 0)
    goto close_fail;
  *data = malloc((*w) * (*h) * sizeof **data);
  if (*data == NULL)
    goto nospace_fail;
  for (i = 0; i < (*w) * (*h); ++i) {
    if (fscanf(fp, "%d", &g) != 1)
      goto corrupt_fail;
    if (g < 0 || g > 1)
      goto corrupt_fail;
    (*data)[i] = (g ? 0 : 255);
  }
  fclose(fp);
  return 0;
close_fail:
  if (*data)
    free(*data);
  *data = NULL;
  if (fp)
    fclose(fp);
  return -1;
corrupt_fail:
  fclose(fp);
  return -2;
nospace_fail:
  fclose(fp);
  return -3;
}
```