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

```asm
<bgr565_to_abgr8888>:
  endbr64
  push   %r15
  lea    0x3(%rsi,%rsi,1),%r11d
  push   %r14
  and    $0xfffffffc,%r11d
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  test   %rdi,%rdi
  je     L224
  test   %rcx,%rcx
  je     L224
  test   %esi,%esi
  jle    L224
  mov    %edx,%ebp
  test   %edx,%edx
  jle    L224
  movslq %esi,%rax
  test   %esi,%esi
  mov    $0x4,%edx
  mov    $0x1,%r12d
  lea    0x0(,%rax,4),%r13
  lea    0x0(,%rsi,4),%r14d
  pcmpeqd %xmm3,%xmm3
  movslq %r11d,%r11
  cmovle %rdx,%r13
  add    %rax,%rax
  test   %esi,%esi
  mov    $0x2,%edx
  cmovg  %esi,%r12d
  cmovg  %rax,%rdx
  movdqa D0(%rip),%xmm2
  movslq %r14d,%r14
  xor    %r8d,%r8d
  mov    %r12d,%eax
  mov    %r12d,%r9d
  mov    %rdx,%r10
  and    $0xfffffff0,%r9d
  shr    $0x4,%eax
  lea    -0x1(%rax),%ebx
  mov    %r9d,%eax
  lea    (%rax,%rax,1),%rdx
  shl    $0x2,%rax
  add    $0x1,%rbx
  mov    %rax,0x10(%rsp)
  lea    0x1(%r9),%eax
  shl    $0x5,%rbx
  mov    %eax,0x18(%rsp)
  lea    0x2(%r9),%eax
  mov    %eax,0x1c(%rsp)
  lea    0x3(%r9),%eax
  mov    %eax,0x20(%rsp)
  lea    0x4(%r9),%eax
  mov    %eax,0x24(%rsp)
  lea    0x5(%r9),%eax
  mov    %eax,0x28(%rsp)
  lea    0x6(%r9),%eax
  mov    %eax,0x2c(%rsp)
  lea    0x7(%r9),%eax
  mov    %eax,0x30(%rsp)
  lea    0x8(%r9),%eax
  mov    %eax,0x34(%rsp)
  lea    0x9(%r9),%eax
  mov    %eax,0x38(%rsp)
  lea    0xa(%r9),%eax
  mov    %eax,0x3c(%rsp)
  lea    0xb(%r9),%eax
  mov    %eax,0x40(%rsp)
  lea    0xc(%r9),%eax
  mov    %eax,0x44(%rsp)
  lea    0xd(%r9),%eax
  mov    %eax,0x48(%rsp)
  lea    0xe(%r9),%eax
  mov    %rdx,0x8(%rsp)
  mov    %eax,0x4c(%rsp)
  nopw   0x0(%rax,%rax,1)
L58:
  lea    (%rdi,%r10,1),%rax
  cmp    %rax,%rcx
  lea    (%rcx,%r13,1),%rax
  setae  %dl
  cmp    %rax,%rdi
  setae  %al
  or     %dl,%al
  je     L211
  mov    %rdi,%rdx
  mov    %rcx,%rax
  lea    (%rbx,%rdi,1),%r15
  cmp    $0xf,%esi
  jle    L211
  nop
L93:
  movdqu (%rdx),%xmm0
  movdqu 0x10(%rdx),%xmm5
  add    $0x20,%rdx
  add    $0x40,%rax
  movdqa %xmm0,%xmm1
  movdqa %xmm5,%xmm4
  movdqa %xmm5,%xmm6
  psrlw  $0xb,%xmm1
  psrlw  $0xb,%xmm4
  pand   %xmm2,%xmm5
  pand   %xmm2,%xmm4
  psrlw  $0x5,%xmm6
  pand   %xmm2,%xmm1
  packuswb %xmm4,%xmm1
  pand   %xmm2,%xmm6
  paddb  %xmm1,%xmm1
  paddb  %xmm1,%xmm1
  movdqa %xmm1,%xmm4
  paddb  %xmm1,%xmm4
  movdqa %xmm0,%xmm1
  pand   %xmm2,%xmm0
  psrlw  $0x5,%xmm1
  packuswb %xmm5,%xmm0
  movdqa %xmm4,%xmm7
  pand   %xmm2,%xmm1
  paddb  %xmm0,%xmm0
  movdqa %xmm3,%xmm5
  packuswb %xmm6,%xmm1
  paddb  %xmm0,%xmm0
  movdqa %xmm3,%xmm6
  paddb  %xmm1,%xmm1
  paddb  %xmm0,%xmm0
  paddb  %xmm1,%xmm1
  punpcklbw %xmm0,%xmm7
  punpckhbw %xmm0,%xmm4
  punpcklbw %xmm1,%xmm6
  punpckhbw %xmm1,%xmm5
  movdqa %xmm6,%xmm0
  punpckhbw %xmm7,%xmm6
  punpcklbw %xmm7,%xmm0
  movups %xmm6,-0x30(%rax)
  movups %xmm0,-0x40(%rax)
  movdqa %xmm5,%xmm0
  punpckhbw %xmm4,%xmm5
  punpcklbw %xmm4,%xmm0
  movups %xmm5,-0x10(%rax)
  movups %xmm0,-0x20(%rax)
  cmp    %rdx,%r15
  jne    L93
  mov    0x8(%rsp),%rax
  lea    (%rdi,%rax,1),%rdx
  mov    0x10(%rsp),%rax
  add    %rcx,%rax
  cmp    %r9d,%r12d
  je     L187
  movb   $0xff,(%rax)
  movzwl (%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x1(%rax)
  movzwl (%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x2(%rax)
  movzbl (%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x3(%rax)
  cmp    0x18(%rsp),%esi
  jle    L187
  movb   $0xff,0x4(%rax)
  movzwl 0x2(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x5(%rax)
  movzwl 0x2(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x6(%rax)
  movzbl 0x2(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x7(%rax)
  cmp    0x1c(%rsp),%esi
  jle    L187
  movb   $0xff,0x8(%rax)
  movzwl 0x4(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x9(%rax)
  movzwl 0x4(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0xa(%rax)
  movzbl 0x4(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0xb(%rax)
  cmp    0x20(%rsp),%esi
  jle    L187
  movb   $0xff,0xc(%rax)
  movzwl 0x6(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0xd(%rax)
  movzwl 0x6(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0xe(%rax)
  movzbl 0x6(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0xf(%rax)
  cmp    0x24(%rsp),%esi
  jle    L187
  movb   $0xff,0x10(%rax)
  movzwl 0x8(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x11(%rax)
  movzwl 0x8(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x12(%rax)
  movzbl 0x8(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x13(%rax)
  cmp    0x28(%rsp),%esi
  jle    L187
  movb   $0xff,0x14(%rax)
  movzwl 0xa(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x15(%rax)
  movzwl 0xa(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x16(%rax)
  movzbl 0xa(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x17(%rax)
  cmp    0x2c(%rsp),%esi
  jle    L187
  movb   $0xff,0x18(%rax)
  movzwl 0xc(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x19(%rax)
  movzwl 0xc(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x1a(%rax)
  movzbl 0xc(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x1b(%rax)
  cmp    0x30(%rsp),%esi
  jle    L187
  movb   $0xff,0x1c(%rax)
  movzwl 0xe(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x1d(%rax)
  movzwl 0xe(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x1e(%rax)
  movzbl 0xe(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x1f(%rax)
  cmp    0x34(%rsp),%esi
  jle    L187
  movb   $0xff,0x20(%rax)
  movzwl 0x10(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x21(%rax)
  movzwl 0x10(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x22(%rax)
  movzbl 0x10(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x23(%rax)
  cmp    0x38(%rsp),%esi
  jle    L187
  movb   $0xff,0x24(%rax)
  movzwl 0x12(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x25(%rax)
  movzwl 0x12(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x26(%rax)
  movzbl 0x12(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x27(%rax)
  cmp    0x3c(%rsp),%esi
  jle    L187
  movb   $0xff,0x28(%rax)
  movzwl 0x14(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x29(%rax)
  movzwl 0x14(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x2a(%rax)
  movzbl 0x14(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x2b(%rax)
  cmp    0x40(%rsp),%esi
  jle    L187
  movb   $0xff,0x2c(%rax)
  movzwl 0x16(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x2d(%rax)
  movzwl 0x16(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x2e(%rax)
  movzbl 0x16(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x2f(%rax)
  cmp    0x44(%rsp),%esi
  jle    L187
  movb   $0xff,0x30(%rax)
  movzwl 0x18(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x31(%rax)
  movzwl 0x18(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x32(%rax)
  movzbl 0x18(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x33(%rax)
  cmp    0x48(%rsp),%esi
  jle    L187
  movb   $0xff,0x34(%rax)
  movzwl 0x1a(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x35(%rax)
  movzwl 0x1a(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x36(%rax)
  movzbl 0x1a(%rdx),%r15d
  shl    $0x3,%r15d
  mov    %r15b,0x37(%rax)
  cmp    0x4c(%rsp),%esi
  jle    L187
  movb   $0xff,0x38(%rax)
  movzwl 0x1c(%rdx),%r15d
  shr    $0xb,%r15w
  shl    $0x3,%r15d
  mov    %r15b,0x39(%rax)
  movzwl 0x1c(%rdx),%r15d
  shr    $0x5,%r15w
  shl    $0x2,%r15d
  mov    %r15b,0x3a(%rax)
  movzwl 0x1c(%rdx),%edx
  shl    $0x3,%edx
  mov    %dl,0x3b(%rax)
  nopl   0x0(%rax)
L187:
  add    $0x1,%r8d
  add    %r11,%rdi
  add    %r14,%rcx
  cmp    %r8d,%ebp
  jg     L58
  xor    %eax,%eax
L179:
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L211:
  xor    %eax,%eax
  nopw   0x0(%rax,%rax,1)
L247:
  movb   $0xff,(%rcx,%rax,4)
  movzwl (%rdi,%rax,2),%edx
  shr    $0xb,%dx
  shl    $0x3,%edx
  mov    %dl,0x1(%rcx,%rax,4)
  movzwl (%rdi,%rax,2),%edx
  shr    $0x5,%dx
  shl    $0x2,%edx
  mov    %dl,0x2(%rcx,%rax,4)
  movzbl (%rdi,%rax,2),%edx
  shl    $0x3,%edx
  mov    %dl,0x3(%rcx,%rax,4)
  add    $0x1,%rax
  cmp    %eax,%esi
  jg     L247
  jmp    L187
L224:
  lea    D12(%rip),%rdi
  call   <printf@plt>
  mov    $0xffffffff,%eax
  jmp    L179
```

tool_calls: name: parse_data
arguments: tag: D0
data_type: byte[16]
name: parse_data
arguments: tag: D12
data_type: string

tool: {"D0": [0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00]}

tool: D12: bgr565_to_abgr8888 : parameter error


assistant: ```c
int bgr565_to_abgr8888(const void *psrc, int w, int h, void *pdst) {
  int srclinesize = (((w * 2) + 3) & ~3);
  int dstlinesize = (((w * 4) + 3) & ~3);
  const unsigned char *psrcline;
  const unsigned short *psrcdot;
  unsigned char *pdstline;
  unsigned char *pdstdot;
  int i, j;
  if (!psrc || !pdst || w <= 0 || h <= 0) {
    printf("bgr565_to_abgr8888 : parameter error\n");
    return -1;
  }
  psrcline = (const unsigned char *)psrc;
  pdstline = (unsigned char *)pdst;
  for (i = 0; i < h; i++) {
    psrcdot = (const unsigned short *)psrcline;
    pdstdot = pdstline;
    for (j = 0; j < w; j++) {
      *pdstdot++ = 0xFF;
      *pdstdot++ = (unsigned char)(((*psrcdot) >> 11) << 3);
      *pdstdot++ = (unsigned char)(((*psrcdot) >> 5) << 2);
      *pdstdot++ = (unsigned char)(((*psrcdot) >> 0) << 3);
      psrcdot++;
    }
    psrcline += srclinesize;
    pdstline += dstlinesize;
  }
  return 0;
}
```