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

```asm
<readppm>:
  endbr64
  push   %r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  mov    %rsi,%r12
  lea    D3(%rip),%rsi
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x120,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x118(%rsp)
  xor    %eax,%eax
  call   <fopen@plt>
  mov    $0x1,%r8d
  test   %eax,%eax
  jne    L18
L69:
  mov    0x118(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L6
  add    $0x120,%rsp
  mov    %r8d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  nop
L18:
  movslq %eax,%rbp
  lea    0x10(%rsp),%rdx
  lea    D10(%rip),%rsi
  xor    %eax,%eax
  mov    %rbp,%rdi
  call   <fscanf@plt>
  cmpb   $0x50,0x10(%rsp)
  je     L20
L42:
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fclose@plt>
  mov    $0x2,%r8d
  jmp    L69
  nopw   0x0(%rax,%rax,1)
L20:
  cmpb   $0x36,0x11(%rsp)
  jne    L42
  cmpb   $0x0,0x12(%rsp)
  jne    L42
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <getint@plt>
  mov    %rbp,%rdi
  mov    %eax,(%r12)
  xor    %eax,%eax
  call   <getint@plt>
  mov    %rbp,%rdi
  mov    %eax,(%rbx)
  xor    %eax,%eax
  call   <getint@plt>
  mov    %rbp,%rcx
  mov    $0x1,%edx
  mov    $0x1,%esi
  mov    %eax,0xc(%rsp)
  lea    0xc(%rsp),%rdi
  xor    %eax,%eax
  call   <fread@plt>
  mov    (%r12),%eax
  imul   (%rbx),%eax
  lea    (%rax,%rax,2),%r12d
  movslq %r12d,%r14
  mov    %r14,%rdi
  call   <malloc@plt>
  mov    %rbp,%rcx
  mov    %r14,%rdx
  mov    $0x1,%esi
  mov    %rax,0x0(%r13)
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <fread@plt>
  mov    %rbp,%rdi
  mov    %eax,%ebx
  xor    %eax,%eax
  call   <fclose@plt>
  xor    %r8d,%r8d
  cmp    %r12d,%ebx
  setne  %r8b
  shl    $0x2,%r8d
  jmp    L69
L6:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D3
type: string
name: read_data
arguments: label: D10
type: string

tool: D3: r

tool: D10: %s

assistant: ```c
signed int readppm(char *name, signed int *xres, signed int *yres, unsigned char **imgdata) {
  char data[256l];
  struct _IO_FILE$link40 *ifp;
  signed int i;
  signed int bytesread;
  signed int datasize;
  ifp = fopen(name, "r");
  if (ifp == ((struct _IO_FILE$link40 *)((void *)0)))
    return 1;
  fscanf(ifp, "%s", (const void *)data);
  signed int tmp_statement_expression$1;
  unsigned long int __s1_len;
  unsigned long int __s2_len;
  _Bool tmp_if_expr$3;
  unsigned int return_value___builtin_strlen$2;
  if ((_Bool)1) {
    if (!((unsigned long int)("P6" + 1l) + -((unsigned long int)"P6") == 1ul))
      goto __CPROVER_DUMP_L2;
    return_value___builtin_strlen$2 = __builtin_strlen("P6");
    __s2_len = (unsigned long int)return_value___builtin_strlen$2;
    tmp_if_expr$3 = __s2_len < (unsigned long int)4 ? (_Bool)1 : (_Bool)0;
  } else {
  __CPROVER_DUMP_L2:;
    tmp_if_expr$3 = (_Bool)0;
  }
  signed int tmp_if_expr$6;
  signed int tmp_statement_expression$4;
  signed int return_value___builtin_strcmp$5;
  if (tmp_if_expr$3) {
    const unsigned char *__s1 = (const unsigned char *)(const char *)data;
    signed int __result = (signed int)__s1[(signed long int)0] - (signed int)((const unsigned char *)(const char *)"P6")[(signed long int)0];
    if (__s2_len > 0ul) {
      if (__result == 0) {
        __result = (signed int)__s1[(signed long int)1] - (signed int)((const unsigned char *)(const char *)"P6")[(signed long int)1];
        if (__s2_len > 1ul) {
          if (__result == 0) {
            __result = (signed int)__s1[(signed long int)2] - (signed int)((const unsigned char *)(const char *)"P6")[(signed long int)2];
            if (__s2_len > 2ul) {
              if (__result == 0)
                __result = (signed int)__s1[(signed long int)3] - (signed int)((const unsigned char *)(const char *)"P6")[(signed long int)3];
            }
          }
        }
      }
    }
    tmp_statement_expression$4 = __result;
    tmp_if_expr$6 = tmp_statement_expression$4;
  } else {
    return_value___builtin_strcmp$5 = __builtin_strcmp(data, "P6");
    tmp_if_expr$6 = return_value___builtin_strcmp$5;
  }
  tmp_statement_expression$1 = tmp_if_expr$6;
  if (!(tmp_statement_expression$1 == 0)) {
    fclose(ifp);
    return 2;
  }
  *xres = getint(ifp);
  *yres = getint(ifp);
  i = getint(ifp);
  fread((void *)&i, (unsigned long int)1, (unsigned long int)1, ifp);
  datasize = 3 * *xres * *yres;
  void *return_value_malloc$7;
  return_value_malloc$7 = malloc((unsigned long int)datasize);
  *imgdata = (unsigned char *)return_value_malloc$7;
  unsigned long int return_value_fread$8;
  return_value_fread$8 = fread((void *)*imgdata, (unsigned long int)1, (unsigned long int)datasize, ifp);
  bytesread = (signed int)return_value_fread$8;
  fclose(ifp);
  if (!(bytesread == datasize))
    return 4;
  return 0;
}
```