user: Converte this assembly snippet into its equivalent C code:

```asm
<readtga>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rsi,(%rsp)
  mov    %rdx,0x8(%rsp)
  mov    %rcx,%rbp
  lea    D4(%rip),%rsi
  mov    $0x0,%eax
  call   <fopen@plt>
  mov    $0x1,%edx
  test   %eax,%eax
  jne    L21
L91:
  mov    %edx,%eax
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L21:
  movslq %eax,%rbx
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %eax,%r15d
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %eax,0x10(%rsp)
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %eax,%r13d
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %eax,0x18(%rsp)
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %eax,%r12d
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %eax,%r14d
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <_IO_getc@plt>
  mov    %eax,0x24(%rsp)
  cmp    $0x18,%r14d
  jne    L95
  cmp    $0x2,%r15d
  jne    L95
  shl    $0x8,%r13d
  mov    %r13d,%eax
  or     0x10(%rsp),%eax
  mov    %eax,0x28(%rsp)
  shl    $0x8,%r12d
  mov    %r12d,%esi
  or     0x18(%rsp),%esi
  mov    %esi,0x2c(%rsp)
  imul   %esi,%eax
  lea    (%rax,%rax,2),%r12d
  movslq %r12d,%r13
  mov    %r13,%rdi
  call   <malloc@plt>
  mov    %rax,%rdi
  mov    %rax,0x0(%rbp)
  mov    %rbx,%rcx
  mov    %r13,%rdx
  mov    $0x1,%esi
  mov    $0x0,%eax
  call   <fread@plt>
  mov    %eax,0x38(%rsp)
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <fclose@plt>
  cmpl   $0x20,0x24(%rsp)
  je     L13
L52:
  mov    $0x0,%eax
  test   %r12d,%r12d
  jle    L37
L17:
  mov    0x0(%rbp),%rcx
  lea    (%rcx,%rax,1),%rdx
  movzbl (%rdx),%esi
  movzbl 0x2(%rcx,%rax,1),%ecx
  mov    %cl,(%rdx)
  mov    0x0(%rbp),%rdx
  mov    %sil,0x2(%rdx,%rax,1)
  add    $0x3,%rax
  cmp    %eax,%r12d
  jg     L17
L37:
  mov    (%rsp),%rax
  mov    0x28(%rsp),%ebx
  mov    %ebx,(%rax)
  mov    0x8(%rsp),%rax
  mov    0x2c(%rsp),%ebx
  mov    %ebx,(%rax)
  cmp    %r12d,0x38(%rsp)
  setne  %dl
  movzbl %dl,%edx
  shl    $0x2,%edx
  jmp    L91
L95:
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <fclose@plt>
  mov    $0x2,%edx
  jmp    L91
L13:
  mov    0x28(%rsp),%eax
  lea    (%rax,%rax,2),%ebx
  movslq %ebx,%r15
  mov    %r15,%rdi
  call   <malloc@plt>
  mov    %rax,0x10(%rsp)
  mov    0x2c(%rsp),%ecx
  mov    %ecx,%eax
  shr    $0x1f,%eax
  add    %ecx,%eax
  sar    %eax
  mov    %eax,0x24(%rsp)
  cmp    $0x1,%ecx
  jle    L106
  mov    %ebx,%eax
  neg    %eax
  cltq
  mov    %rax,0x30(%rsp)
  lea    -0x1(%rcx),%r13d
  imul   %ebx,%r13d
  movslq %r13d,%r13
  movq   $0x0,0x18(%rsp)
  mov    $0x0,%r14d
  mov    %r12d,0x3c(%rsp)
L46:
  mov    0x0(%rbp),%rbx
  mov    0x18(%rsp),%rax
  lea    (%rbx,%rax,1),%r12
  mov    %r15,%rdx
  mov    %r12,%rsi
  mov    0x10(%rsp),%rdi
  call   <memcpy@plt>
  lea    (%rbx,%r13,1),%rsi
  mov    %r15,%rdx
  mov    %r12,%rdi
  call   <memcpy@plt>
  mov    %r13,%rbx
  add    0x0(%rbp),%rbx
  mov    %rbx,%rdi
  mov    %r15,%rdx
  mov    0x10(%rsp),%rsi
  call   <memcpy@plt>
  add    $0x1,%r14d
  add    %r15,0x18(%rsp)
  add    0x30(%rsp),%r13
  cmp    0x24(%rsp),%r14d
  jl     L46
  mov    0x3c(%rsp),%r12d
L106:
  mov    0x10(%rsp),%rdi
  call   <free@plt>
  jmp    L52
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D4
data_type: string

tool: D4: r

assistant: ```c
signed int readtga(char *name, signed int *xres, signed int *yres, unsigned char **imgdata) {
  signed int format;
  signed int width;
  signed int height;
  signed int w1;
  signed int w2;
  signed int h1;
  signed int h2;
  signed int depth;
  signed int flags;
  signed int imgsize;
  signed int bytesread;
  signed int i;
  signed int tmp;
  struct _IO_FILE$link43 *ifp;
  ifp = fopen(name, "r");
  if (ifp == ((struct _IO_FILE$link43 *)((void *)0)))
    return 1;
  _IO_getc(ifp);
  _IO_getc(ifp);
  format = _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  _IO_getc(ifp);
  w1 = _IO_getc(ifp);
  w2 = _IO_getc(ifp);
  h1 = _IO_getc(ifp);
  h2 = _IO_getc(ifp);
  depth = _IO_getc(ifp);
  flags = _IO_getc(ifp);
  if (format == 2) {
    if (depth != 24)
      goto __CPROVER_DUMP_L2;
  } else {
  __CPROVER_DUMP_L2:;
    fclose(ifp);
    return 2;
  }
  width = w2 << 8 | w1;
  height = h2 << 8 | h1;
  imgsize = 3 * width * height;
  void *return_value_malloc$1;
  return_value_malloc$1 = malloc((unsigned long int)imgsize);
  *imgdata = (unsigned char *)return_value_malloc$1;
  unsigned long int return_value_fread$2;
  return_value_fread$2 = fread((void *)*imgdata, (unsigned long int)1, (unsigned long int)imgsize, ifp);
  bytesread = (signed int)return_value_fread$2;
  fclose(ifp);
  if (flags == 32) {
    signed int rowsize = 3 * width;
    unsigned char *copytmp;
    void *return_value_malloc$3;
    return_value_malloc$3 = malloc((unsigned long int)rowsize);
    copytmp = (unsigned char *)return_value_malloc$3;
    i = 0;
    while (!(i >= height / 2)) {
      memcpy((void *)copytmp, (const void *)&(*imgdata)[(signed long int)(rowsize * i)], (unsigned long int)rowsize);
      memcpy((void *)&(*imgdata)[(signed long int)(rowsize * i)], (const void *)&(*imgdata)[(signed long int)(rowsize * ((height - 1) - i))], (unsigned long int)rowsize);
      memcpy((void *)&(*imgdata)[(signed long int)(rowsize * ((height - 1) - i))], (const void *)copytmp, (unsigned long int)rowsize);
      i = i + 1;
    }
    free((void *)copytmp);
  }
  i = 0;
  while (!(i >= imgsize)) {
    tmp = (signed int)(*imgdata)[(signed long int)i];
    (*imgdata)[(signed long int)i] = (*imgdata)[(signed long int)(i + 2)];
    (*imgdata)[(signed long int)(i + 2)] = (unsigned char)tmp;
    i = i + 3;
  }
  *xres = width;
  *yres = height;
  if (!(bytesread == imgsize))
    return 4;
  return 0;
}
```