user: 请从给定的汇编指令推导出C源代码：

```asm
<RGB24toRGB565>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    %esi,-0x6c(%rbp)
  mov    %edx,-0x70(%rbp)
  mov    %ecx,-0x74(%rbp)
  mov    %r8d,-0x78(%rbp)
  mov    %r9d,-0x7c(%rbp)
  mov    0x20(%rbp),%rax
  mov    %rax,-0x88(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    -0x7c(%rbp),%r9d
  mov    -0x78(%rbp),%r8d
  mov    -0x74(%rbp),%ecx
  mov    -0x70(%rbp),%edx
  mov    -0x6c(%rbp),%esi
  mov    -0x68(%rbp),%rax
  lea    -0x5c(%rbp),%rdi
  push   %rdi
  lea    -0x60(%rbp),%rdi
  push   %rdi
  mov    0x58(%rbp),%edi
  push   %rdi
  mov    0x50(%rbp),%edi
  push   %rdi
  mov    0x48(%rbp),%edi
  push   %rdi
  mov    0x40(%rbp),%edi
  push   %rdi
  mov    0x38(%rbp),%edi
  push   %rdi
  mov    0x30(%rbp),%edi
  push   %rdi
  mov    0x28(%rbp),%edi
  push   %rdi
  push   -0x88(%rbp)
  mov    0x18(%rbp),%edi
  push   %rdi
  mov    0x10(%rbp),%edi
  push   %rdi
  mov    %rax,%rdi
  call   <chk_args@plt>
  add    $0x60,%rsp
  test   %eax,%eax
  jne    L286
  mov    $0xffffffff,%eax
  jmp    L34
L286:
  cmpl   $0x0,0x38(%rbp)
  jns    L81
  mov    0x30(%rbp),%eax
  sub    $0x1,%eax
  imul   0x38(%rbp),%eax
  cltq
  neg    %rax
  add    %rax,-0x88(%rbp)
L81:
  cmpl   $0x0,-0x74(%rbp)
  jns    L53
  mov    -0x70(%rbp),%eax
  sub    $0x1,%eax
  imul   -0x74(%rbp),%eax
  cltq
  neg    %rax
  add    %rax,-0x68(%rbp)
L53:
  mov    -0x60(%rbp),%eax
  cmp    $0x1,%eax
  jne    L27
  mov    -0x5c(%rbp),%eax
  cmp    $0x1,%eax
  jne    L27
  mov    0x40(%rbp),%edx
  mov    %edx,%eax
  add    %eax,%eax
  add    %edx,%eax
  movslq %eax,%rdx
  mov    0x48(%rbp),%eax
  imul   0x38(%rbp),%eax
  cltq
  add    %rax,%rdx
  mov    -0x88(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x58(%rbp)
  mov    -0x78(%rbp),%eax
  add    %eax,%eax
  movslq %eax,%rdx
  mov    -0x7c(%rbp),%eax
  imul   -0x74(%rbp),%eax
  cltq
  add    %rax,%rdx
  mov    -0x68(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x50(%rbp)
  mov    $0x0,%r14d
  jmp    L167
L162:
  mov    0x40(%rbp),%r12d
  mov    0x10(%rbp),%ebx
  jmp    L57
L84:
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  shr    $0x3,%al
  movzbl %al,%edx
  mov    -0x58(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  or     %eax,%edx
  mov    -0x58(%rbp),%rax
  add    $0x2,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x8,%eax
  and    $0xf800,%ax
  or     %edx,%eax
  mov    %eax,%edx
  mov    -0x50(%rbp),%rax
  mov    %dx,(%rax)
  addq   $0x2,-0x50(%rbp)
  addq   $0x3,-0x58(%rbp)
  add    $0x1,%r12d
  sub    $0x1,%ebx
L57:
  mov    %r12d,%eax
  and    $0x3,%eax
  test   %eax,%eax
  je     L41
  test   %ebx,%ebx
  jne    L84
  jmp    L41
L252:
  mov    -0x58(%rbp),%rax
  mov    (%rax),%r12d
  mov    -0x58(%rbp),%rax
  mov    0x4(%rax),%r13d
  mov    %r12d,%eax
  shr    $0x3,%eax
  and    $0x1f,%eax
  mov    %eax,%edx
  mov    %r12d,%eax
  shr    $0x5,%eax
  and    $0x7e0,%eax
  or     %eax,%edx
  mov    %r12d,%eax
  shr    $0x8,%eax
  and    $0xf800,%eax
  or     %eax,%edx
  mov    %r12d,%eax
  shr    $0xb,%eax
  and    $0x1f0000,%eax
  or     %eax,%edx
  mov    %r13d,%eax
  shl    $0x13,%eax
  and    $0x7e00000,%eax
  or     %eax,%edx
  mov    %r13d,%eax
  shl    $0x10,%eax
  and    $0xf8000000,%eax
  or     %eax,%edx
  mov    -0x50(%rbp),%rax
  mov    %edx,(%rax)
  mov    -0x58(%rbp),%rax
  mov    0x8(%rax),%r12d
  mov    %r13d,%eax
  shr    $0x13,%eax
  and    $0x1f,%eax
  mov    %eax,%edx
  mov    %r13d,%eax
  shr    $0x15,%eax
  and    $0x7e0,%eax
  or     %eax,%edx
  mov    %r12d,%eax
  shl    $0x8,%eax
  and    $0xf800,%eax
  or     %eax,%edx
  mov    %r12d,%eax
  shl    $0x5,%eax
  and    $0x1f0000,%eax
  or     %eax,%edx
  lea    0x0(,%r12,8),%eax
  and    $0x7e00000,%eax
  mov    %edx,%ecx
  or     %eax,%ecx
  mov    %r12d,%edx
  and    $0xf8000000,%edx
  mov    -0x50(%rbp),%rax
  add    $0x4,%rax
  or     %ecx,%edx
  mov    %edx,(%rax)
  addq   $0x8,-0x50(%rbp)
  addq   $0xc,-0x58(%rbp)
  sub    $0x4,%ebx
L41:
  cmp    $0x3,%ebx
  jg     L252
  jmp    L228
L269:
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  shr    $0x3,%al
  movzbl %al,%edx
  mov    -0x58(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  or     %eax,%edx
  mov    -0x58(%rbp),%rax
  add    $0x2,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x8,%eax
  and    $0xf800,%ax
  or     %edx,%eax
  mov    %eax,%edx
  mov    -0x50(%rbp),%rax
  mov    %dx,(%rax)
  addq   $0x2,-0x50(%rbp)
  addq   $0x3,-0x58(%rbp)
  sub    $0x1,%ebx
L228:
  test   %ebx,%ebx
  jne    L269
  mov    0x10(%rbp),%eax
  mov    %eax,%edx
  shl    $0x2,%eax
  sub    %eax,%edx
  mov    0x38(%rbp),%eax
  add    %edx,%eax
  cltq
  add    %rax,-0x58(%rbp)
  mov    0x10(%rbp),%eax
  lea    (%rax,%rax,1),%edx
  mov    -0x74(%rbp),%eax
  sub    %edx,%eax
  cltq
  add    %rax,-0x50(%rbp)
  add    $0x1,%r14d
L167:
  cmp    0x18(%rbp),%r14d
  jl     L162
  mov    $0x0,%eax
  jmp    L34
L27:
  mov    -0x60(%rbp),%eax
  cmp    $0x2,%eax
  jne    L244
  mov    -0x5c(%rbp),%eax
  cmp    $0x2,%eax
  jne    L244
  mov    0x40(%rbp),%edx
  mov    %edx,%eax
  add    %eax,%eax
  add    %edx,%eax
  movslq %eax,%rdx
  mov    0x48(%rbp),%eax
  imul   0x38(%rbp),%eax
  cltq
  add    %rax,%rdx
  mov    -0x88(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x48(%rbp)
  mov    -0x78(%rbp),%eax
  add    %eax,%eax
  movslq %eax,%rdx
  mov    -0x7c(%rbp),%eax
  imul   -0x74(%rbp),%eax
  cltq
  add    %rax,%rdx
  mov    -0x68(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x40(%rbp)
  mov    $0x0,%r15d
  jmp    L225
L166:
  mov    0x40(%rbp),%r12d
  mov    0x50(%rbp),%ebx
  jmp    L158
L136:
  mov    -0x48(%rbp),%rax
  movzbl (%rax),%eax
  shr    $0x3,%al
  movzbl %al,%edx
  mov    -0x48(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  or     %eax,%edx
  mov    -0x48(%rbp),%rax
  add    $0x2,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x8,%eax
  and    $0xf800,%ax
  or     %edx,%eax
  mov    %eax,%r13d
  mov    -0x40(%rbp),%rax
  mov    %r13w,(%rax)
  mov    -0x40(%rbp),%rax
  add    $0x2,%rax
  mov    %r13w,(%rax)
  addq   $0x4,-0x40(%rbp)
  addq   $0x3,-0x48(%rbp)
  add    $0x1,%r12d
  sub    $0x1,%ebx
L158:
  mov    %r12d,%eax
  and    $0x3,%eax
  test   %eax,%eax
  je     L78
  test   %ebx,%ebx
  jne    L136
  jmp    L78
L223:
  mov    -0x48(%rbp),%rax
  mov    (%rax),%r12d
  mov    -0x48(%rbp),%rax
  mov    0x4(%rax),%r14d
  mov    %r12d,%eax
  shr    $0x3,%eax
  and    $0x1f,%eax
  mov    %eax,%edx
  mov    %r12d,%eax
  shr    $0x5,%eax
  and    $0x7e0,%eax
  or     %eax,%edx
  mov    %r12d,%eax
  shr    $0x8,%eax
  and    $0xf800,%eax
  or     %eax,%edx
  mov    %edx,%r13d
  mov    %r13d,%eax
  shl    $0x10,%eax
  mov    %r13d,%edx
  or     %eax,%edx
  mov    -0x40(%rbp),%rax
  mov    %edx,(%rax)
  mov    %r12d,%eax
  shr    $0xb,%eax
  and    $0x1f0000,%eax
  mov    %eax,%edx
  mov    %r14d,%eax
  shl    $0x13,%eax
  and    $0x7e00000,%eax
  or     %eax,%edx
  mov    %r14d,%eax
  shl    $0x10,%eax
  and    $0xf8000000,%eax
  or     %eax,%edx
  mov    %edx,%r13d
  mov    %r13d,%edx
  shr    $0x10,%edx
  mov    -0x40(%rbp),%rax
  add    $0x4,%rax
  or     %r13d,%edx
  mov    %edx,(%rax)
  mov    -0x48(%rbp),%rax
  mov    0x8(%rax),%r12d
  mov    %r14d,%eax
  shr    $0x13,%eax
  and    $0x1f,%eax
  mov    %eax,%edx
  mov    %r14d,%eax
  shr    $0x15,%eax
  and    $0x7e0,%eax
  or     %eax,%edx
  mov    %r12d,%eax
  shl    $0x8,%eax
  and    $0xf800,%eax
  or     %eax,%edx
  mov    %edx,%r13d
  mov    %r13d,%edx
  shl    $0x10,%edx
  mov    -0x40(%rbp),%rax
  add    $0x8,%rax
  or     %r13d,%edx
  mov    %edx,(%rax)
  mov    %r12d,%eax
  shl    $0x5,%eax
  and    $0x1f0000,%eax
  mov    %eax,%edx
  lea    0x0(,%r12,8),%eax
  and    $0x7e00000,%eax
  or     %eax,%edx
  mov    %r12d,%eax
  and    $0xf8000000,%eax
  or     %eax,%edx
  mov    %edx,%r13d
  mov    %r13d,%edx
  shr    $0x10,%edx
  mov    -0x40(%rbp),%rax
  add    $0xc,%rax
  or     %r13d,%edx
  mov    %edx,(%rax)
  addq   $0x10,-0x40(%rbp)
  addq   $0xc,-0x48(%rbp)
  sub    $0x4,%ebx
L78:
  cmp    $0x3,%ebx
  jg     L223
  jmp    L107
L0:
  mov    -0x48(%rbp),%rax
  movzbl (%rax),%eax
  shr    $0x3,%al
  movzbl %al,%edx
  mov    -0x48(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x3,%eax
  and    $0x7e0,%ax
  or     %eax,%edx
  mov    -0x48(%rbp),%rax
  add    $0x2,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x8,%eax
  and    $0xf800,%ax
  or     %edx,%eax
  mov    %eax,%r12d
  mov    -0x40(%rbp),%rax
  mov    %r12w,(%rax)
  mov    -0x40(%rbp),%rax
  add    $0x2,%rax
  mov    %r12w,(%rax)
  addq   $0x4,-0x40(%rbp)
  addq   $0x3,-0x48(%rbp)
  sub    $0x1,%ebx
L107:
  test   %ebx,%ebx
  jne    L0
  mov    0x50(%rbp),%edx
  mov    %edx,%eax
  add    %eax,%eax
  add    %edx,%eax
  cltq
  neg    %rax
  add    %rax,-0x48(%rbp)
  mov    0x50(%rbp),%eax
  shl    $0x2,%eax
  cltq
  neg    %rax
  add    %rax,-0x40(%rbp)
  mov    0x50(%rbp),%eax
  lea    0x0(,%rax,4),%edx
  mov    -0x74(%rbp),%eax
  movslq %eax,%rcx
  mov    -0x40(%rbp),%rax
  add    %rax,%rcx
  mov    -0x40(%rbp),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  call   <memcpy@plt>
  mov    0x38(%rbp),%eax
  cltq
  add    %rax,-0x48(%rbp)
  mov    -0x74(%rbp),%eax
  add    %eax,%eax
  cltq
  add    %rax,-0x40(%rbp)
  add    $0x1,%r15d
L225:
  cmp    0x58(%rbp),%r15d
  jl     L166
  mov    $0x0,%eax
  jmp    L34
L244:
  mov    $0xffffffff,%eax
L34:
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L113
  call   <__stack_chk_fail@plt>
L113:
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
```

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;
}
```