user: 请将以下的汇编代码转换成C语言代码：

```asm
<ReadPBM1>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rsi,%rbp
  mov    %rdx,%r12
  mov    %rcx,%r13
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    D8(%rip),%rsi
  call   <fopen@plt>
  movw   $0x0,0x16(%rsp)
  movq   $0x0,0x0(%rbp)
  test   %rax,%rax
  je     L77
  mov    %rax,%rbx
  lea    0x16(%rsp),%rdi
  mov    %rax,%rcx
  mov    $0x2,%edx
  mov    $0x1,%esi
  call   <fread@plt>
  cmpb   $0x50,0x16(%rsp)
  jne    L83
  cmpb   $0x31,0x17(%rsp)
  je     L138
L83:
  mov    0x0(%rbp),%rdi
  test   %rdi,%rdi
  je     L150
  call   <free@plt>
  movq   $0x0,0x0(%rbp)
L150:
  mov    %rbx,%rdi
  call   <fclose@plt>
  mov    $0xffffffff,%eax
L145:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L205
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L138:
  movl   $0x0,0x0(%r13)
  movl   $0x0,(%r12)
  mov    %rbx,%rdi
  call   <getc@plt>
  mov    %al,0xf(%rsp)
  lea    0xf(%rsp),%rdi
  mov    %rbx,%rsi
  call   <PPM_scan_ws@plt>
  jmp    L48
L35:
  mov    (%r12),%eax
  lea    (%rax,%rax,4),%edx
  movzbl 0xf(%rsp),%eax
  lea    -0x30(%rax,%rdx,2),%eax
  mov    %eax,(%r12)
  mov    %rbx,%rdi
  call   <getc@plt>
  mov    %al,0xf(%rsp)
L48:
  movzbl 0xf(%rsp),%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L35
  lea    0xf(%rsp),%rdi
  mov    %rbx,%rsi
  call   <PPM_scan_ws@plt>
  jmp    L172
L94:
  mov    0x0(%r13),%eax
  lea    (%rax,%rax,4),%edx
  movzbl 0xf(%rsp),%eax
  lea    -0x30(%rax,%rdx,2),%eax
  mov    %eax,0x0(%r13)
  mov    %rbx,%rdi
  call   <getc@plt>
  mov    %al,0xf(%rsp)
L172:
  movzbl 0xf(%rsp),%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L94
  movzbl 0xf(%rsp),%edi
  call   <isspace@plt>
  test   %eax,%eax
  je     L83
  mov    (%r12),%edi
  test   %edi,%edi
  jle    L83
  mov    0x0(%r13),%eax
  test   %eax,%eax
  jle    L83
  imul   %eax,%edi
  call   <malloc@plt>
  mov    %rax,0x0(%rbp)
  test   %rax,%rax
  je     L194
  mov    (%r12),%eax
  imul   0x0(%r13),%eax
  mov    $0x0,%r14d
  lea    D9(%rip),%r15
  test   %eax,%eax
  jle    L124
L100:
  lea    0x10(%rsp),%rdx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <fscanf@plt>
  cmp    $0x1,%eax
  jne    L37
  mov    0x10(%rsp),%eax
  cmp    $0x1,%eax
  ja     L37
  mov    0x0(%rbp),%rdx
  sbb    %al,%al
  mov    %al,(%rdx,%r14,1)
  add    $0x1,%r14
  mov    (%r12),%eax
  imul   0x0(%r13),%eax
  cmp    %r14d,%eax
  jg     L100
L124:
  mov    %rbx,%rdi
  call   <fclose@plt>
  mov    $0x0,%eax
  jmp    L145
L194:
  mov    %rbx,%rdi
  call   <fclose@plt>
  mov    $0xfffffffd,%eax
  jmp    L145
L37:
  mov    %rbx,%rdi
  call   <fclose@plt>
  mov    $0xfffffffe,%eax
  jmp    L145
L77:
  movq   $0x0,0x0(%rbp)
  mov    $0xffffffff,%eax
  jmp    L145
L205:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D8
type_guessed: string
name: unpack_data
arguments: tag: D9
type_guessed: string

tool: D8: r

tool: D9: %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;
}
```