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

```asm
<RGB24toRGB565>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,0x8(%rsp)
  mov    %edx,0x18(%rsp)
  mov    %ecx,%r12d
  mov    %r8d,0x10(%rsp)
  mov    %r9d,%ebp
  mov    0x90(%rsp),%r15
  mov    0xa8(%rsp),%r13d
  mov    0xb0(%rsp),%r14d
  mov    0xc0(%rsp),%ebx
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  lea    0x34(%rsp),%rax
  push   %rax
  lea    0x38(%rsp),%rax
  push   %rax
  mov    0xd8(%rsp),%eax
  push   %rax
  push   %rbx
  mov    0xd8(%rsp),%eax
  push   %rax
  push   %r14
  push   %r13
  mov    0xd8(%rsp),%eax
  push   %rax
  mov    0xd8(%rsp),%eax
  push   %rax
  push   %r15
  mov    0xd8(%rsp),%eax
  push   %rax
  mov    0xd8(%rsp),%eax
  push   %rax
  call   <chk_args@plt>
  add    $0x60,%rsp
  test   %eax,%eax
  je     L96
  test   %r13d,%r13d
  js     L288
L47:
  test   %r12d,%r12d
  js     L280
L113:
  mov    0x30(%rsp),%eax
  cmp    $0x1,%eax
  je     L155
  cmp    $0x2,%eax
  jne    L254
  cmpl   $0x2,0x34(%rsp)
  jne    L4
  lea    (%r14,%r14,2),%ecx
  movslq %ecx,%rcx
  mov    %r13d,%eax
  imul   0xb8(%rsp),%eax
  cltq
  add    %rax,%rcx
  add    %r15,%rcx
  mov    0x10(%rsp),%r15d
  add    %r15d,%r15d
  movslq %r15d,%r15
  imul   %r12d,%ebp
  movslq %ebp,%rax
  add    %rax,%r15
  add    0x8(%rsp),%r15
  cmpl   $0x0,0xc8(%rsp)
  jle    L328
  lea    0x0(,%rbx,4),%eax
  mov    %eax,0x8(%rsp)
  cltq
  neg    %rax
  mov    %rax,0x10(%rsp)
  movslq %r13d,%r13
  lea    (%rbx,%rbx,2),%eax
  cltq
  sub    %rax,%r13
  mov    %r13,0x20(%rsp)
  lea    (%r12,%r12,1),%eax
  cltq
  mov    %rax,0x18(%rsp)
  mov    $0x0,%ebp
  mov    %r14d,%r13d
  and    $0x3,%r13d
  lea    0x1(%r14,%rbx,1),%r14d
  movslq %r12d,%rax
  mov    %rax,0x28(%rsp)
  jmp    L91
L288:
  mov    0xa0(%rsp),%eax
  sub    $0x1,%eax
  imul   %r13d,%eax
  cltq
  sub    %rax,%r15
  jmp    L47
L280:
  mov    0x18(%rsp),%eax
  sub    $0x1,%eax
  imul   %r12d,%eax
  cltq
  sub    %rax,0x8(%rsp)
  jmp    L113
L155:
  mov    $0xffffffff,%eax
  cmpl   $0x1,0x34(%rsp)
  jne    L183
  lea    (%r14,%r14,2),%esi
  movslq %esi,%rsi
  mov    %r13d,%eax
  imul   0xb8(%rsp),%eax
  cltq
  add    %rax,%rsi
  add    %r15,%rsi
  mov    0x10(%rsp),%ecx
  add    %ecx,%ecx
  movslq %ecx,%rcx
  mov    %ebp,%eax
  imul   %r12d,%eax
  cltq
  add    %rax,%rcx
  add    0x8(%rsp),%rcx
  cmpl   $0x0,0x88(%rsp)
  jle    L180
  mov    0x80(%rsp),%eax
  lea    0x0(,%rax,4),%edx
  sub    %edx,%eax
  add    %r13d,%eax
  movslq %eax,%r15
  mov    0x80(%rsp),%eax
  add    %eax,%eax
  sub    %eax,%r12d
  movslq %r12d,%rax
  mov    %rax,0x8(%rsp)
  mov    $0x0,%r12d
  mov    %r14d,%r13d
  and    $0x3,%r13d
  mov    0x80(%rsp),%eax
  lea    0x1(%rax,%r14,1),%ebx
  mov    %r15,0x10(%rsp)
  mov    %eax,%r15d
  jmp    L122
L358:
  mov    %rcx,%r11
  jmp    L348
L306:
  mov    %r15d,%r10d
L394:
  cmp    $0x3,%r10d
  jle    L358
  lea    -0x4(%r10),%ebp
  shr    $0x2,%ebp
  lea    0x1(%rbp),%r14d
  mov    %r14d,%r14d
  lea    (%rcx,%r14,8),%r11
  mov    %rsi,%r9
L315:
  mov    (%r9),%edx
  mov    0x4(%r9),%edi
  mov    %edx,%eax
  shr    $0x3,%eax
  and    $0x1f,%eax
  mov    %edx,%r8d
  shr    $0x5,%r8d
  and    $0x7e0,%r8d
  or     %r8d,%eax
  mov    %edx,%r8d
  shr    $0x8,%r8d
  and    $0xf800,%r8d
  or     %r8d,%eax
  shr    $0xb,%edx
  and    $0x1f0000,%edx
  or     %edx,%eax
  mov    %edi,%edx
  shl    $0x13,%edx
  and    $0x7e00000,%edx
  or     %edx,%eax
  mov    %edi,%edx
  shl    $0x10,%edx
  and    $0xf8000000,%edx
  or     %edx,%eax
  mov    %eax,(%rcx)
  mov    0x8(%r9),%edx
  mov    %edi,%eax
  shr    $0x13,%eax
  and    $0x1f,%eax
  shr    $0x15,%edi
  and    $0x7e0,%edi
  or     %edi,%eax
  mov    %edx,%edi
  and    $0xf8000000,%edi
  or     %edi,%eax
  mov    %edx,%edi
  shl    $0x8,%edi
  and    $0xf800,%edi
  or     %edi,%eax
  mov    %edx,%edi
  shl    $0x5,%edi
  and    $0x1f0000,%edi
  or     %edi,%eax
  shl    $0x3,%edx
  and    $0x7e00000,%edx
  or     %edx,%eax
  mov    %eax,0x4(%rcx)
  add    $0x8,%rcx
  add    $0xc,%r9
  cmp    %r11,%rcx
  jne    L315
  lea    (%r14,%r14,2),%rax
  lea    (%rsi,%rax,4),%rsi
  neg    %ebp
  lea    -0x4(%r10,%rbp,4),%r10d
L348:
  test   %r10d,%r10d
  je     L239
  mov    %r10d,%eax
  lea    (%r11,%rax,2),%rdi
  mov    %r11,%rcx
  mov    %rsi,%rdx
L10:
  movzbl 0x1(%rdx),%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  movzbl 0x2(%rdx),%r8d
  shl    $0x8,%r8d
  and    $0xf800,%r8w
  or     %r8d,%eax
  movzbl (%rdx),%r8d
  shr    $0x3,%r8b
  movzbl %r8b,%r8d
  or     %r8d,%eax
  mov    %ax,(%rcx)
  add    $0x2,%rcx
  add    $0x3,%rdx
  cmp    %rdi,%rcx
  jne    L10
  lea    -0x1(%r10),%edx
  add    $0x1,%rdx
  lea    (%rdx,%rdx,1),%rax
  add    %rax,%r11
  add    %rdx,%rax
  add    %rax,%rsi
L239:
  add    0x10(%rsp),%rsi
  mov    0x8(%rsp),%rax
  lea    (%r11,%rax,1),%rcx
  add    $0x1,%r12d
  cmp    %r12d,0x88(%rsp)
  je     L384
L122:
  test   %r13d,%r13d
  je     L306
  mov    %r15d,%r10d
  test   %r15d,%r15d
  je     L306
L393:
  movzbl 0x1(%rsi),%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  movzbl 0x2(%rsi),%edx
  shl    $0x8,%edx
  and    $0xf800,%dx
  or     %edx,%eax
  movzbl (%rsi),%edx
  shr    $0x3,%dl
  movzbl %dl,%edx
  or     %edx,%eax
  mov    %ax,(%rcx)
  add    $0x2,%rcx
  add    $0x3,%rsi
  mov    %ebx,%eax
  sub    %r10d,%eax
  sub    $0x1,%r10d
  test   $0x3,%al
  je     L394
  test   %r10d,%r10d
  jne    L393
  jmp    L394
L60:
  mov    %rcx,%r12
  jmp    L66
L257:
  mov    %ebx,%r8d
L302:
  cmp    $0x3,%r8d
  jle    L60
  lea    -0x4(%r8),%r10d
  shr    $0x2,%r10d
  lea    0x1(%r10),%r9d
  mov    %r9d,%r9d
  lea    (%r9,%r9,2),%rax
  lea    (%rcx,%rax,4),%r12
  mov    %r15,%rdi
L158:
  mov    (%rcx),%eax
  mov    0x4(%rcx),%edx
  mov    %eax,%esi
  shr    $0x3,%esi
  and    $0x1f,%esi
  mov    %eax,%r11d
  shr    $0x5,%r11d
  and    $0x7e0,%r11d
  or     %r11d,%esi
  mov    %eax,%r11d
  shr    $0x8,%r11d
  and    $0xf800,%r11d
  or     %r11d,%esi
  mov    %esi,%r11d
  shl    $0x10,%r11d
  or     %r11d,%esi
  mov    %esi,(%rdi)
  shr    $0xb,%eax
  and    $0x1f0000,%eax
  mov    %edx,%esi
  shl    $0x13,%esi
  and    $0x7e00000,%esi
  or     %esi,%eax
  mov    %edx,%esi
  shl    $0x10,%esi
  and    $0xf8000000,%esi
  or     %esi,%eax
  mov    %eax,%esi
  shr    $0x10,%esi
  or     %esi,%eax
  mov    %eax,0x4(%rdi)
  mov    0x8(%rcx),%esi
  mov    %edx,%eax
  shr    $0x13,%eax
  and    $0x1f,%eax
  shr    $0x15,%edx
  and    $0x7e0,%edx
  or     %edx,%eax
  mov    %esi,%edx
  shl    $0x8,%edx
  and    $0xf800,%edx
  or     %edx,%eax
  mov    %eax,%edx
  shl    $0x10,%edx
  or     %edx,%eax
  mov    %eax,0x8(%rdi)
  mov    %esi,%eax
  shl    $0x5,%eax
  and    $0x1f0000,%eax
  lea    0x0(,%rsi,8),%edx
  and    $0x7e00000,%edx
  or     %edx,%eax
  and    $0xf8000000,%esi
  or     %esi,%eax
  mov    %eax,%edx
  shr    $0x10,%edx
  or     %edx,%eax
  mov    %eax,0xc(%rdi)
  add    $0x10,%rdi
  add    $0xc,%rcx
  cmp    %r12,%rcx
  jne    L158
  shl    $0x4,%r9
  add    %r9,%r15
  neg    %r10d
  lea    -0x4(%r8,%r10,4),%r8d
L66:
  test   %r8d,%r8d
  je     L237
  mov    %r8d,%eax
  lea    (%r15,%rax,4),%rsi
  mov    %r15,%rcx
  mov    %r12,%rdx
L392:
  movzbl 0x1(%rdx),%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  movzbl 0x2(%rdx),%edi
  shl    $0x8,%edi
  and    $0xf800,%di
  or     %edi,%eax
  movzbl (%rdx),%edi
  shr    $0x3,%dil
  movzbl %dil,%edi
  or     %edi,%eax
  mov    %ax,(%rcx)
  mov    %ax,0x2(%rcx)
  add    $0x4,%rcx
  add    $0x3,%rdx
  cmp    %rsi,%rcx
  jne    L392
  lea    -0x1(%r8),%eax
  add    $0x1,%rax
  lea    (%r15,%rax,4),%r15
  lea    (%rax,%rax,2),%rax
  add    %rax,%r12
L237:
  add    0x10(%rsp),%r15
  mov    0x28(%rsp),%rax
  lea    (%r15,%rax,1),%rdi
  mov    0x8(%rsp),%edx
  mov    %r15,%rsi
  call   <memcpy@plt>
  mov    0x20(%rsp),%rax
  lea    (%r12,%rax,1),%rcx
  add    0x18(%rsp),%r15
  add    $0x1,%ebp
  cmp    %ebp,0xc8(%rsp)
  je     L80
L91:
  test   %r13d,%r13d
  je     L257
  mov    %ebx,%r8d
  test   %ebx,%ebx
  je     L257
L332:
  movzbl 0x1(%rcx),%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  movzbl 0x2(%rcx),%edx
  shl    $0x8,%edx
  and    $0xf800,%dx
  or     %edx,%eax
  movzbl (%rcx),%edx
  shr    $0x3,%dl
  movzbl %dl,%edx
  or     %edx,%eax
  mov    %ax,(%r15)
  mov    %ax,0x2(%r15)
  add    $0x4,%r15
  add    $0x3,%rcx
  mov    %r14d,%eax
  sub    %r8d,%eax
  sub    $0x1,%r8d
  test   $0x3,%al
  je     L302
  test   %r8d,%r8d
  jne    L332
  jmp    L302
L96:
  mov    $0xffffffff,%eax
  jmp    L183
L180:
  mov    $0x0,%eax
  jmp    L183
L384:
  mov    $0x0,%eax
  jmp    L183
L254:
  mov    $0xffffffff,%eax
  jmp    L183
L4:
  mov    $0xffffffff,%eax
  jmp    L183
L328:
  mov    $0x0,%eax
  jmp    L183
L80:
  mov    $0x0,%eax
L183:
  mov    0x38(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L9
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L9:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int RGB24toRGB565(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 * 3 + 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) {
        *(unsigned short *)d = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
        d += 2;
        s += 3;
        sx++;
        ddx--;
      }
      while (ddx >= 4) {
        register unsigned int a, b;
        a = *(unsigned int *)s;
        b = *(unsigned int *)(s + 4);
        *(unsigned int *)d = ((a & 0xF8) >> 3) | ((a & 0xFC00) >> 5) | ((a & 0xF80000) >> 8) | ((a & 0xF8000000) >> 11) | ((b & 0xFC) << 19) | ((b & 0xF800) << 16);
        a = *(unsigned int *)(s + 8);
        *(unsigned int *)(d + 4) = ((b & 0xF80000) >> 19) | ((b & 0xFC000000) >> 21) | ((a & 0xF8) << 8) | ((a & 0xF800) << 5) | ((a & 0xFC0000) << 3) | (a & 0xF8000000);
        d += 2 * 4;
        s += 3 * 4;
        ddx -= 4;
      }
      while (ddx) {
        *(unsigned short *)d = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
        d += 2;
        s += 3;
        ddx--;
      }
      s += src_pitch - dest_dx * 3;
      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 * 3 + 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;
        a = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
        *(unsigned short *)d = a;
        *(unsigned short *)(d + 2) = a;
        d += 2 * 2;
        s += 3;
        sx++;
        sdx--;
      }
      while (sdx >= 4) {
        register unsigned int a, b, c;
        a = *(unsigned int *)s;
        b = *(unsigned int *)(s + 4);
        c = ((a & 0xF8) >> 3) | ((a & 0xFC00) >> 5) | ((a & 0xF80000) >> 8);
        *(unsigned int *)d = c | (c << 16);
        c = ((a & 0xF8000000) >> 11) | ((b & 0xFC) << 19) | ((b & 0xF800) << 16);
        *(unsigned int *)(d + 2 * 2) = c | (c >> 16);
        a = *(unsigned int *)(s + 8);
        c = ((b & 0xF80000) >> 19) | ((b & 0xFC000000) >> 21) | ((a & 0xF8) << 8);
        *(unsigned int *)(d + 2 * 2 * 2) = c | (c << 16);
        c = ((a & 0xF800) << 5) | ((a & 0xFC0000) << 3) | (a & 0xF8000000);
        *(unsigned int *)(d + 3 * 2 * 2) = c | (c >> 16);
        d += 2 * 4 * 2;
        s += 4 * 3;
        sdx -= 4;
      }
      while (sdx) {
        register unsigned short a;
        a = (s[0] >> 3) | ((s[1] & 0xFC) << 3) | ((s[2] & 0xF8) << 8);
        *(unsigned short *)d = a;
        *(unsigned short *)(d + 2) = a;
        d += 2 * 2;
        s += 3;
        sdx--;
      }
      s -= src_dx * 3;
      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;
}
```