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

```asm
<ReadPBM1>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %rsi,%r13
  lea    D4(%rip),%rsi
  push   %r12
  mov    %rcx,%r12
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  movq   $0x0,0x0(%r13)
  mov    %rax,%rbp
  xor    %eax,%eax
  mov    %ax,0x16(%rsp)
  mov    $0xffffffff,%eax
  test   %rbp,%rbp
  je     L69
  lea    0x16(%rsp),%rdi
  mov    %rbp,%rcx
  mov    $0x2,%edx
  mov    $0x1,%esi
  call   <fread@plt>
  cmpb   $0x50,0x16(%rsp)
  je     L94
L158:
  mov    0x0(%r13),%rdi
  test   %rdi,%rdi
  je     L44
  call   <free@plt>
  movq   $0x0,0x0(%r13)
L44:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    $0xffffffff,%eax
L69:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L14
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L94:
  cmpb   $0x31,0x17(%rsp)
  jne    L158
  movl   $0x0,(%r12)
  mov    %rbp,%rdi
  lea    0xf(%rsp),%r14
  movl   $0x0,(%rbx)
  call   <getc@plt>
  mov    %rbp,%rsi
  mov    %r14,%rdi
  mov    %al,0xf(%rsp)
  call   <PPM_scan_ws@plt>
  movzbl 0xf(%rsp),%eax
  jmp    L147
  nopl   0x0(%rax,%rax,1)
L57:
  mov    (%rbx),%eax
  mov    %rbp,%rdi
  lea    (%rax,%rax,4),%edx
  movzbl 0xf(%rsp),%eax
  lea    -0x30(%rax,%rdx,2),%eax
  mov    %eax,(%rbx)
  call   <getc@plt>
  mov    %al,0xf(%rsp)
L147:
  movzbl %al,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L57
  mov    %rbp,%rsi
  mov    %r14,%rdi
  call   <PPM_scan_ws@plt>
  movzbl 0xf(%rsp),%eax
  jmp    L108
  nopl   0x0(%rax,%rax,1)
L20:
  mov    (%r12),%eax
  mov    %rbp,%rdi
  lea    (%rax,%rax,4),%edx
  movzbl 0xf(%rsp),%eax
  lea    -0x30(%rax,%rdx,2),%eax
  mov    %eax,(%r12)
  call   <getc@plt>
  mov    %al,0xf(%rsp)
L108:
  movzbl %al,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L20
  movzbl 0xf(%rsp),%edi
  call   <isspace@plt>
  test   %eax,%eax
  je     L158
  mov    (%rbx),%edi
  test   %edi,%edi
  jle    L158
  mov    (%r12),%eax
  test   %eax,%eax
  jle    L158
  imul   %eax,%edi
  call   <malloc@plt>
  mov    %rax,0x0(%r13)
  test   %rax,%rax
  je     L89
  mov    (%r12),%eax
  imul   (%rbx),%eax
  xor    %r14d,%r14d
  lea    0x10(%rsp),%r15
  test   %eax,%eax
  jg     L184
  jmp    L88
  nopl   0x0(%rax,%rax,1)
L206:
  mov    0x10(%rsp),%eax
  cmp    $0x1,%eax
  ja     L111
  mov    0x0(%r13),%rdx
  xor    $0x1,%eax
  neg    %eax
  mov    %al,(%rdx,%r14,1)
  mov    (%rbx),%eax
  add    $0x1,%r14
  imul   (%r12),%eax
  cmp    %r14d,%eax
  jle    L88
L184:
  mov    %r15,%rdx
  lea    D9(%rip),%rsi
  mov    %rbp,%rdi
  call   <fscanf@plt>
  cmp    $0x1,%eax
  je     L206
L111:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    $0xfffffffe,%eax
  jmp    L69
  nop
L88:
  mov    %rbp,%rdi
  call   <fclose@plt>
  xor    %eax,%eax
  jmp    L69
L14:
  call   <__stack_chk_fail@plt>
L89:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    $0xfffffffd,%eax
  jmp    L69
```

tool_calls: name: read_data
arguments: data_label: D4
data_type: string
name: read_data
arguments: data_label: D9
data_type: string

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