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

```asm
<RGB555toRGB565>:
  endbr64
  push   %r15
  mov    %ecx,%r15d
  push   %r14
  push   %r13
  mov    %r8d,%r13d
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  lea    0x34(%rsp),%rax
  mov    0x90(%rsp),%r14
  movslq 0xa8(%rsp),%r12
  mov    0xb0(%rsp),%ebp
  mov    0xc0(%rsp),%ebx
  push   %rax
  lea    0x38(%rsp),%rax
  push   %rax
  mov    0xd8(%rsp),%eax
  push   %rax
  push   %rbx
  mov    0xd8(%rsp),%eax
  push   %rax
  push   %rbp
  push   %r12
  mov    0xd8(%rsp),%eax
  push   %rax
  mov    0xd8(%rsp),%eax
  push   %rax
  push   %r14
  mov    0xd8(%rsp),%eax
  push   %rax
  mov    0xd8(%rsp),%eax
  push   %rax
  mov    %r9d,0x78(%rsp)
  mov    %edx,0x70(%rsp)
  mov    %rdi,0x68(%rsp)
  call   <chk_args@plt>
  add    $0x60,%rsp
  test   %eax,%eax
  je     L40
  test   %r12d,%r12d
  mov    0x8(%rsp),%rdi
  mov    0x10(%rsp),%edx
  mov    0x18(%rsp),%r9d
  jns    L209
  mov    0xa0(%rsp),%eax
  sub    $0x1,%eax
  imul   %r12d,%eax
  cltq
  sub    %rax,%r14
L209:
  test   %r15d,%r15d
  jns    L217
  sub    $0x1,%edx
  imul   %r15d,%edx
  movslq %edx,%rax
  sub    %rax,%rdi
L217:
  mov    0x30(%rsp),%eax
  cmp    $0x1,%eax
  je     L160
  cmp    $0x2,%eax
  jne    L40
  cmpl   $0x2,0x34(%rsp)
  jne    L40
  imul   %r15d,%r9d
  lea    0x0(%rbp,%rbp,1),%eax
  mov    0xc8(%rsp),%ecx
  movslq %eax,%rdx
  mov    0xb8(%rsp),%eax
  imul   %r12d,%eax
  cltq
  add    %rdx,%rax
  movslq %r9d,%rdx
  add    %rax,%r14
  lea    0x0(%r13,%r13,1),%eax
  cltq
  add    %rdx,%rax
  lea    (%rdi,%rax,1),%rdx
  test   %ecx,%ecx
  jle    L261
  lea    0x0(,%rbx,4),%r13d
  movslq %r13d,%rax
  neg    %rax
  mov    %rax,0x8(%rsp)
  lea    (%rbx,%rbx,1),%eax
  cltq
  sub    %rax,%r12
  mov    %r12,0x18(%rsp)
  lea    (%r15,%r15,1),%r12d
  movslq %r12d,%rax
  mov    %rax,0x10(%rsp)
  movslq %r15d,%rax
  xor    %r15d,%r15d
  mov    %rax,0x20(%rsp)
  mov    %ebp,%eax
  and    $0x3,%eax
  mov    %eax,0x28(%rsp)
  lea    0x1(%rbx),%eax
  mov    %eax,0x2c(%rsp)
  nopl   (%rax)
L83:
  mov    0x28(%rsp),%eax
  test   %eax,%eax
  je     L133
  mov    0x2c(%rsp),%eax
  mov    %ebx,%esi
  lea    (%rax,%rbp,1),%edi
  test   %ebx,%ebx
  jne    L328
  jmp    L282
  cs nopw 0x0(%rax,%rax,1)
L311:
  test   %esi,%esi
  je     L282
L328:
  movzwl (%r14),%ecx
  add    $0x4,%rdx
  add    $0x2,%r14
  lea    (%rcx,%rcx,1),%eax
  and    $0x1f,%ecx
  and    $0xffffffc0,%eax
  or     %ecx,%eax
  mov    %ax,-0x4(%rdx)
  mov    %ax,-0x2(%rdx)
  mov    %edi,%eax
  sub    %esi,%eax
  sub    $0x1,%esi
  test   $0x3,%al
  jne    L311
L324:
  mov    %r14,%r8
  cmp    $0x3,%esi
  jle    L64
  sub    $0x4,%esi
  mov    %rdx,%rcx
  mov    %esi,%r10d
  shr    $0x2,%r10d
  lea    0x1(%r10),%r9d
  lea    (%r14,%r9,8),%r8
  nopl   0x0(%rax,%rax,1)
L136:
  mov    (%r14),%edi
  add    $0x8,%r14
  add    $0x10,%rcx
  lea    (%rdi,%rdi,1),%eax
  and    $0x1f001f,%edi
  and    $0xffc0ffc0,%eax
  or     %edi,%eax
  mov    %eax,%r11d
  movzwl %ax,%edi
  shl    $0x10,%r11d
  or     %r11d,%edi
  mov    %edi,-0x10(%rcx)
  mov    %eax,%edi
  shr    $0x10,%eax
  xor    %di,%di
  or     %edi,%eax
  mov    %eax,-0xc(%rcx)
  mov    -0x4(%r14),%edi
  lea    (%rdi,%rdi,1),%eax
  and    $0x1f001f,%edi
  and    $0xffc0ffc0,%eax
  or     %edi,%eax
  mov    %eax,%r11d
  movzwl %ax,%edi
  shl    $0x10,%r11d
  or     %r11d,%edi
  mov    %edi,-0x8(%rcx)
  mov    %eax,%edi
  shr    $0x10,%eax
  xor    %di,%di
  or     %edi,%eax
  mov    %eax,-0x4(%rcx)
  cmp    %r14,%r8
  jne    L136
  shl    $0x4,%r9
  neg    %r10d
  add    %r9,%rdx
  lea    (%rsi,%r10,4),%esi
L64:
  test   %esi,%esi
  je     L146
  xor    %ecx,%ecx
L157:
  movzwl (%r8,%rcx,2),%edi
  lea    (%rdi,%rdi,1),%eax
  and    $0x1f,%edi
  and    $0xffffffc0,%eax
  or     %edi,%eax
  mov    %ax,(%rdx,%rcx,4)
  mov    %ax,0x2(%rdx,%rcx,4)
  add    $0x1,%rcx
  cmp    %rcx,%rsi
  jne    L157
  lea    (%rdx,%rsi,4),%rdx
  lea    (%r8,%rsi,2),%r14
L282:
  mov    0x8(%rsp),%rax
  add    $0x1,%r15d
  lea    (%rdx,%rax,1),%r12
  mov    0x20(%rsp),%rax
  mov    %r13d,%edx
  mov    %r12,%rsi
  lea    (%r12,%rax,1),%rdi
  call   <memcpy@plt>
  mov    0x10(%rsp),%rax
  add    0x18(%rsp),%r14
  lea    (%r12,%rax,1),%rdx
  cmp    %r15d,0xc8(%rsp)
  jne    L83
L261:
  xor    %eax,%eax
L107:
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L219
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L133:
  mov    %ebx,%esi
  jmp    L324
L160:
  cmpl   $0x1,0x34(%rsp)
  mov    $0xffffffff,%eax
  jne    L107
  mov    0xb8(%rsp),%eax
  mov    %r9d,%edx
  lea    0x0(%rbp,%rbp,1),%r8d
  mov    0x88(%rsp),%esi
  imul   %r15d,%edx
  movslq %r8d,%r8
  imul   %r12d,%eax
  movslq %edx,%rdx
  cltq
  add    %rax,%r8
  lea    0x0(%r13,%r13,1),%eax
  cltq
  add    %r14,%r8
  add    %rdx,%rax
  add    %rdi,%rax
  test   %esi,%esi
  jle    L261
  mov    0x80(%rsp),%ebx
  mov    0x80(%rsp),%esi
  mov    %ebp,%r14d
  and    $0x3,%r14d
  lea    (%rbx,%rbx,1),%edx
  lea    0x1(%rsi,%rbp,1),%r11d
  xor    %ebx,%ebx
  sub    %edx,%r12d
  sub    %edx,%r15d
  movslq %r12d,%r13
  movslq %r15d,%r12
  mov    %esi,%r15d
L357:
  test   %r14d,%r14d
  je     L148
  mov    %r15d,%ecx
  test   %r15d,%r15d
  jne    L272
  jmp    L273
  xchg   %ax,%ax
L314:
  test   %ecx,%ecx
  je     L273
L272:
  movzwl (%r8),%esi
  add    $0x2,%rax
  add    $0x2,%r8
  lea    (%rsi,%rsi,1),%edx
  and    $0x1f,%esi
  and    $0xffffffc0,%edx
  or     %esi,%edx
  mov    %dx,-0x2(%rax)
  mov    %r11d,%edx
  sub    %ecx,%edx
  sub    $0x1,%ecx
  and    $0x3,%edx
  jne    L314
L294:
  mov    %rax,%r9
  cmp    $0x3,%ecx
  jle    L253
  lea    -0x4(%rcx),%esi
  mov    %r8,%rdi
  mov    %esi,%ebp
  mov    %esi,0x8(%rsp)
  shr    $0x2,%ebp
  lea    0x1(%rbp),%r10d
  shl    $0x3,%r10
  lea    (%rax,%r10,1),%r9
  nopl   0x0(%rax,%rax,1)
L155:
  mov    (%rdi),%esi
  mov    0x4(%rdi),%ecx
  add    $0x8,%rax
  add    $0x8,%rdi
  lea    (%rsi,%rsi,1),%edx
  and    $0x1f001f,%esi
  and    $0xffc0ffc0,%edx
  or     %esi,%edx
  mov    %edx,-0x8(%rax)
  lea    (%rcx,%rcx,1),%edx
  and    $0x1f001f,%ecx
  and    $0xffc0ffc0,%edx
  or     %ecx,%edx
  mov    %edx,-0x4(%rax)
  cmp    %rax,%r9
  jne    L155
  mov    0x8(%rsp),%eax
  neg    %ebp
  add    %r10,%r8
  lea    (%rax,%rbp,4),%ecx
L253:
  test   %ecx,%ecx
  je     L245
  xor    %edx,%edx
L138:
  movzwl (%r8,%rdx,2),%esi
  lea    (%rsi,%rsi,1),%eax
  and    $0x1f,%esi
  and    $0xffffffc0,%eax
  or     %esi,%eax
  mov    %ax,(%r9,%rdx,2)
  add    $0x1,%rdx
  cmp    %rdx,%rcx
  jne    L138
  add    %rcx,%rcx
  lea    (%r9,%rcx,1),%rax
  add    %rcx,%r8
L273:
  add    %r13,%r8
  add    %r12,%rax
  add    $0x1,%ebx
  cmp    %ebx,0x88(%rsp)
  jne    L357
  jmp    L261
L40:
  mov    $0xffffffff,%eax
  jmp    L107
L148:
  mov    %r15d,%ecx
  jmp    L294
L219:
  call   <__stack_chk_fail@plt>
L146:
  mov    %r8,%r14
  jmp    L282
L245:
  mov    %r9,%rax
  jmp    L273
```

assistant: ```c
int RGB555toRGB565(unsigned char *dest_ptr, int dest_width, int dest_height, int dest_pitch, int dest_x, int dest_y, int dest_dx, int dest_dy, unsigned char *src_ptr, int src_width, int src_height, int src_pitch, int src_x, int src_y, int src_dx, int src_dy) {
  int scale_x, scale_y;
  if (!chk_args(dest_ptr, dest_width, dest_height, dest_pitch, dest_x, dest_y, dest_dx, dest_dy, src_ptr, src_width, src_height, src_pitch, src_x, src_y, src_dx, src_dy, &scale_x, &scale_y))
    return -1;
  if (src_pitch < 0)
    src_ptr -= (src_height - 1) * src_pitch;
  if (dest_pitch < 0)
    dest_ptr -= (dest_height - 1) * dest_pitch;
  if (scale_x == 1 && scale_y == 1) {
    unsigned char *s, *d;
    register int i;
    s = src_ptr + src_x * 2 + src_y * src_pitch;
    d = dest_ptr + dest_x * 2 + dest_y * dest_pitch;
    for (i = 0; i < dest_dy; i++) {
      register int sx = src_x, ddx = dest_dx;
      while ((sx & 3) && ddx) {
        register unsigned short c = *(unsigned short *)s;
        *(unsigned short *)d = (c & 0x1F) | ((c & 0x7FE0) << 1);
        d += 2;
        s += 2;
        sx++;
        ddx--;
      }
      while (ddx >= 4) {
        register unsigned int a, b;
        a = *(unsigned int *)s;
        b = *(unsigned int *)(s + 4);
        *(unsigned int *)d = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
        *(unsigned int *)(d + 4) = (b & 0x1F001F) | ((b & 0x7FE07FE0) << 1);
        d += 2 * 4;
        s += 2 * 4;
        ddx -= 4;
      }
      while (ddx) {
        register unsigned short c = *(unsigned short *)s;
        *(unsigned short *)d = (c & 0x1F) | ((c & 0x7FE0) << 1);
        d += 2;
        s += 2;
        ddx--;
      }
      s += src_pitch - dest_dx * 2;
      d += dest_pitch - dest_dx * 2;
    }
    return 0;
  }
  if (scale_x == 2 && scale_y == 2) {
    unsigned char *s, *d;
    register int i;
    s = src_ptr + src_x * 2 + src_y * src_pitch;
    d = dest_ptr + dest_x * 2 + dest_y * dest_pitch;
    for (i = 0; i < src_dy; i++) {
      register int sx = src_x, sdx = src_dx;
      while ((sx & 3) && sdx) {
        register unsigned short a, b;
        a = *(unsigned short *)s;
        b = (a & 0x1F) | ((a & 0x7FE0) << 1);
        *(unsigned short *)d = b;
        *(unsigned short *)(d + 2) = b;
        d += 2 * 2;
        s += 2;
        sx++;
        sdx--;
      }
      while (sdx >= 4) {
        register unsigned int a, b;
        a = *(unsigned int *)s;
        b = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
        *(unsigned int *)d = (b & 0xFFFF) | (b << 16);
        *(unsigned int *)(d + 2 * 2) = (b & 0xFFFF0000) | (b >> 16);
        a = *(unsigned int *)(s + 2 * 2);
        b = (a & 0x1F001F) | ((a & 0x7FE07FE0) << 1);
        *(unsigned int *)(d + 2 * 2 * 2) = (b & 0xFFFF) | (b << 16);
        *(unsigned int *)(d + 3 * 2 * 2) = (b & 0xFFFF0000) | (b >> 16);
        d += 2 * 4 * 2;
        s += 4 * 2;
        sdx -= 4;
      }
      while (sdx) {
        register unsigned short a, b;
        a = *(unsigned short *)s;
        b = (a & 0x1F) | ((a & 0x7FE0) << 1);
        *(unsigned short *)d = b;
        *(unsigned short *)(d + 2) = b;
        d += 2 * 2;
        s += 2;
        sdx--;
      }
      s -= src_dx * 2;
      d -= src_dx * 2 * 2;
      memcpy(d + dest_pitch, d, src_dx * 2 * 2);
      s += src_pitch;
      d += dest_pitch * 2;
    }
    return 0;
  }
  return -1;
}
```