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

```asm
<RGB24toRGB565>:
  endbr64
  push   %r15
  push   %r14
  mov    %edx,%r14d
  push   %r13
  mov    %ecx,%r13d
  push   %r12
  mov    %r9d,%r12d
  push   %rbp
  push   %rbx
  mov    %r8d,%ebx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  lea    0x24(%rsp),%rax
  mov    0x80(%rsp),%r11
  mov    0x98(%rsp),%r10d
  mov    0xa8(%rsp),%r15d
  mov    0xb0(%rsp),%ebp
  push   %rax
  lea    0x28(%rsp),%rax
  push   %rax
  mov    0xc8(%rsp),%eax
  push   %rax
  push   %rbp
  push   %r15
  mov    0xc8(%rsp),%eax
  push   %rax
  push   %r10
  mov    0xc8(%rsp),%eax
  mov    %r10d,0xd0(%rsp)
  push   %rax
  mov    0xc8(%rsp),%eax
  push   %rax
  push   %r11
  mov    0xc8(%rsp),%eax
  mov    %r11,0x58(%rsp)
  push   %rax
  mov    0xc8(%rsp),%eax
  push   %rax
  mov    %rdi,0x60(%rsp)
  call   <chk_args@plt>
  add    $0x60,%rsp
  test   %eax,%eax
  je     L47
  movslq 0x98(%rsp),%r10
  mov    (%rsp),%rdi
  mov    0x8(%rsp),%r11
  test   %r10d,%r10d
  jns    L128
  mov    0x90(%rsp),%eax
  sub    $0x1,%eax
  imul   %r10d,%eax
  cltq
  sub    %rax,%r11
L128:
  test   %r13d,%r13d
  jns    L49
  sub    $0x1,%r14d
  imul   %r13d,%r14d
  movslq %r14d,%rax
  sub    %rax,%rdi
L49:
  mov    0x20(%rsp),%eax
  cmp    $0x1,%eax
  je     L105
  cmp    $0x2,%eax
  jne    L47
  cmpl   $0x2,0x24(%rsp)
  jne    L47
  mov    0xa0(%rsp),%eax
  imul   %r10d,%r15d
  mov    0xb8(%rsp),%ecx
  imul   %r13d,%r12d
  lea    (%rax,%rax,2),%r14d
  movslq %r14d,%r14
  movslq %r15d,%rax
  add    %rax,%r14
  lea    (%rbx,%rbx,1),%eax
  movslq %r12d,%rdx
  cltq
  add    %r11,%r14
  add    %rdx,%rax
  add    %rdi,%rax
  test   %ecx,%ecx
  jle    L280
  mov    0xa0(%rsp),%ebx
  movslq %r13d,%rdi
  xor    %r12d,%r12d
  mov    %rdi,0x10(%rsp)
  lea    0x1(%rbp),%edi
  and    $0x3,%ebx
  mov    %edi,0x1c(%rsp)
  mov    %ebx,0x18(%rsp)
  lea    0x0(,%rbp,4),%ebx
  movslq %ebx,%rdx
  neg    %rdx
  mov    %rdx,(%rsp)
  lea    0x0(%rbp,%rbp,2),%edx
  movslq %edx,%rdx
  sub    %rdx,%r10
  lea    0x0(%r13,%r13,1),%edx
  mov    %r10,0x8(%rsp)
  movslq %edx,%r15
  nopl   0x0(%rax)
L363:
  mov    0x18(%rsp),%edx
  mov    %ebp,%r8d
  test   %edx,%edx
  je     L1
  mov    0x1c(%rsp),%ecx
  add    0xa0(%rsp),%ecx
  test   %ebp,%ebp
  jne    L302
  jmp    L270
  nopw   0x0(%rax,%rax,1)
L329:
  test   %r8d,%r8d
  je     L270
L302:
  movzbl 0x1(%r14),%edx
  movzbl 0x2(%r14),%esi
  add    $0x4,%rax
  add    $0x3,%r14
  shl    $0x3,%edx
  shl    $0x8,%esi
  and    $0xf800,%si
  and    $0x7e0,%dx
  or     %esi,%edx
  movzbl -0x3(%r14),%esi
  shr    $0x3,%sil
  movzbl %sil,%esi
  or     %esi,%edx
  mov    %dx,-0x4(%rax)
  mov    %dx,-0x2(%rax)
  mov    %ecx,%edx
  sub    %r8d,%edx
  sub    $0x1,%r8d
  and    $0x3,%edx
  jne    L329
L1:
  mov    %rax,%r9
  cmp    $0x3,%r8d
  jle    L143
  sub    $0x4,%r8d
  mov    %r14,%rdi
  mov    %r8d,%r11d
  shr    $0x2,%r11d
  lea    0x1(%r11),%r10d
  mov    %r10,%r9
  shl    $0x4,%r9
  add    %rax,%r9
  nopl   0x0(%rax,%rax,1)
L90:
  mov    (%rdi),%edx
  mov    0x4(%rdi),%ecx
  mov    %edx,%esi
  mov    %edx,%r13d
  shr    $0x3,%esi
  shr    $0x5,%r13d
  and    $0x7e0,%r13d
  and    $0x1f,%esi
  or     %r13d,%esi
  mov    %edx,%r13d
  shr    $0xb,%edx
  shr    $0x8,%r13d
  and    $0x1f0000,%edx
  and    $0xf800,%r13d
  or     %r13d,%esi
  mov    %esi,%r13d
  shl    $0x10,%r13d
  or     %r13d,%esi
  mov    %esi,(%rax)
  mov    %ecx,%esi
  shl    $0x13,%esi
  and    $0x7e00000,%esi
  or     %esi,%edx
  mov    %ecx,%esi
  shl    $0x10,%esi
  and    $0xf8000000,%esi
  or     %esi,%edx
  mov    %edx,%esi
  shr    $0x10,%esi
  or     %esi,%edx
  mov    %edx,0x4(%rax)
  mov    %ecx,%edx
  mov    0x8(%rdi),%esi
  shr    $0x15,%ecx
  shr    $0x13,%edx
  and    $0x7e0,%ecx
  and    $0x1f,%edx
  or     %ecx,%edx
  mov    %esi,%ecx
  shl    $0x8,%ecx
  and    $0xf800,%ecx
  or     %ecx,%edx
  mov    %edx,%ecx
  shl    $0x10,%ecx
  or     %ecx,%edx
  lea    0x0(,%rsi,8),%ecx
  mov    %edx,0x8(%rax)
  mov    %esi,%edx
  shl    $0x5,%edx
  and    $0x1f0000,%edx
  and    $0x7e00000,%ecx
  add    $0x10,%rax
  and    $0xf8000000,%esi
  or     %ecx,%edx
  add    $0xc,%rdi
  or     %esi,%edx
  mov    %edx,%ecx
  shr    $0x10,%ecx
  or     %ecx,%edx
  mov    %edx,-0x4(%rax)
  cmp    %r9,%rax
  jne    L90
  lea    (%r10,%r10,2),%rax
  neg    %r11d
  lea    (%r14,%rax,4),%r14
  lea    (%r8,%r11,4),%r8d
L143:
  test   %r8d,%r8d
  je     L312
  movzbl 0x2(%r14),%eax
  movzbl 0x1(%r14),%edx
  shl    $0x8,%eax
  shl    $0x3,%edx
  and    $0x7e0,%dx
  and    $0xf800,%ax
  or     %edx,%eax
  movzbl (%r14),%edx
  shr    $0x3,%dl
  movzbl %dl,%edx
  or     %edx,%eax
  mov    %r8d,%edx
  mov    %ax,(%r9)
  mov    %ax,0x2(%r9)
  sub    $0x1,%edx
  je     L63
  movzbl 0x5(%r14),%eax
  movzbl 0x4(%r14),%ecx
  shl    $0x8,%eax
  shl    $0x3,%ecx
  and    $0x7e0,%cx
  and    $0xf800,%ax
  or     %ecx,%eax
  movzbl 0x3(%r14),%ecx
  shr    $0x3,%cl
  movzbl %cl,%ecx
  or     %ecx,%eax
  mov    %ax,0x4(%r9)
  mov    %ax,0x6(%r9)
  cmp    $0x2,%r8d
  je     L63
  movzbl 0x8(%r14),%eax
  movzbl 0x7(%r14),%ecx
  shl    $0x8,%eax
  shl    $0x3,%ecx
  and    $0x7e0,%cx
  and    $0xf800,%ax
  or     %ecx,%eax
  movzbl 0x6(%r14),%ecx
  shr    $0x3,%cl
  movzbl %cl,%ecx
  or     %ecx,%eax
  mov    %ax,0x8(%r9)
  mov    %ax,0xa(%r9)
  cmp    $0x3,%r8d
  je     L63
  movzbl 0xa(%r14),%eax
  movzbl 0xb(%r14),%ecx
  shl    $0x3,%eax
  shl    $0x8,%ecx
  and    $0xf800,%cx
  and    $0x7e0,%ax
  or     %ecx,%eax
  movzbl 0x9(%r14),%ecx
  shr    $0x3,%cl
  movzbl %cl,%ecx
  or     %ecx,%eax
  mov    %ax,0xc(%r9)
  mov    %ax,0xe(%r9)
L63:
  mov    %edx,%edx
  add    $0x1,%rdx
  lea    (%r9,%rdx,4),%rax
  lea    (%rdx,%rdx,2),%rdx
  add    %rdx,%r14
L270:
  mov    (%rsp),%rdi
  mov    %ebx,%edx
  add    $0x1,%r12d
  lea    (%rax,%rdi,1),%r13
  mov    0x10(%rsp),%rax
  mov    %r13,%rsi
  lea    0x0(%r13,%rax,1),%rdi
  call   <memcpy@plt>
  add    0x8(%rsp),%r14
  lea    0x0(%r13,%r15,1),%rax
  cmp    %r12d,0xb8(%rsp)
  jne    L363
L280:
  xor    %eax,%eax
L158:
  mov    0x28(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L307
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L105:
  cmpl   $0x1,0x24(%rsp)
  mov    $0xffffffff,%eax
  jne    L158
  mov    0xa0(%rsp),%eax
  mov    %r12d,%edx
  mov    0x78(%rsp),%r8d
  imul   %r13d,%edx
  lea    (%rax,%rax,2),%esi
  mov    %r15d,%eax
  imul   %r10d,%eax
  movslq %esi,%rsi
  movslq %edx,%rdx
  cltq
  add    %rax,%rsi
  lea    (%rbx,%rbx,1),%eax
  cltq
  add    %r11,%rsi
  add    %rdx,%rax
  lea    (%rdi,%rax,1),%rcx
  test   %r8d,%r8d
  jle    L280
  mov    0xa0(%rsp),%eax
  mov    0x70(%rsp),%r12d
  xor    %ebp,%ebp
  mov    0xa0(%rsp),%ebx
  and    $0x3,%eax
  mov    %eax,(%rsp)
  mov    0x70(%rsp),%eax
  shl    $0x2,%eax
  sub    %eax,%r12d
  mov    0x70(%rsp),%eax
  add    %r10d,%r12d
  add    %eax,%eax
  movslq %r12d,%r12
  sub    %eax,%r13d
  mov    0x70(%rsp),%eax
  movslq %r13d,%r15
  lea    0x1(%rax,%rbx,1),%ebx
  mov    %eax,%r14d
L313:
  mov    (%rsp),%edi
  mov    %r14d,%edx
  test   %edi,%edi
  je     L36
  test   %r14d,%r14d
  jne    L343
  jmp    L93
  nopl   0x0(%rax)
L26:
  test   %edx,%edx
  je     L93
L343:
  movzbl 0x1(%rsi),%eax
  movzbl 0x2(%rsi),%edi
  add    $0x2,%rcx
  add    $0x3,%rsi
  shl    $0x3,%eax
  shl    $0x8,%edi
  and    $0xf800,%di
  and    $0x7e0,%ax
  or     %edi,%eax
  movzbl -0x3(%rsi),%edi
  shr    $0x3,%dil
  movzbl %dil,%edi
  or     %edi,%eax
  mov    %ax,-0x2(%rcx)
  mov    %ebx,%eax
  sub    %edx,%eax
  sub    $0x1,%edx
  test   $0x3,%al
  jne    L26
L36:
  mov    %rcx,%r10
  cmp    $0x3,%edx
  jle    L12
  lea    -0x4(%rdx),%eax
  mov    %rsi,%r9
  mov    %eax,%r13d
  mov    %eax,0x8(%rsp)
  shr    $0x2,%r13d
  lea    0x1(%r13),%r11d
  lea    (%rcx,%r11,8),%r10
  nopl   0x0(%rax,%rax,1)
L229:
  mov    (%r9),%edx
  mov    0x4(%r9),%edi
  mov    %edx,%eax
  mov    %edx,%r8d
  shr    $0x3,%eax
  shr    $0x5,%r8d
  and    $0x7e0,%r8d
  and    $0x1f,%eax
  or     %r8d,%eax
  mov    %edx,%r8d
  shr    $0xb,%edx
  shr    $0x8,%r8d
  and    $0x1f0000,%edx
  and    $0xf800,%r8d
  or     %r8d,%eax
  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    %edi,%eax
  mov    0x8(%r9),%edx
  shr    $0x15,%edi
  shr    $0x13,%eax
  and    $0x7e0,%edi
  and    $0x1f,%eax
  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    $0x3,%edx
  shl    $0x5,%edi
  and    $0x7e00000,%edx
  and    $0x1f0000,%edi
  or     %edi,%eax
  or     %edx,%eax
  add    $0x8,%rcx
  add    $0xc,%r9
  mov    %eax,-0x4(%rcx)
  cmp    %r10,%rcx
  jne    L229
  lea    (%r11,%r11,2),%rax
  neg    %r13d
  lea    (%rsi,%rax,4),%rsi
  mov    0x8(%rsp),%eax
  lea    (%rax,%r13,4),%edx
L12:
  test   %edx,%edx
  je     L196
  movzbl 0x1(%rsi),%eax
  movzbl 0x2(%rsi),%ecx
  shl    $0x3,%eax
  shl    $0x8,%ecx
  and    $0xf800,%cx
  and    $0x7e0,%ax
  or     %ecx,%eax
  movzbl (%rsi),%ecx
  shr    $0x3,%cl
  movzbl %cl,%ecx
  or     %ecx,%eax
  mov    %edx,%ecx
  mov    %ax,(%r10)
  sub    $0x1,%ecx
  je     L235
  movzbl 0x5(%rsi),%eax
  movzbl 0x4(%rsi),%edi
  shl    $0x8,%eax
  shl    $0x3,%edi
  and    $0x7e0,%di
  and    $0xf800,%ax
  or     %edi,%eax
  movzbl 0x3(%rsi),%edi
  shr    $0x3,%dil
  movzbl %dil,%edi
  or     %edi,%eax
  mov    %ax,0x2(%r10)
  cmp    $0x2,%edx
  je     L235
  movzbl 0x8(%rsi),%eax
  movzbl 0x7(%rsi),%edi
  shl    $0x8,%eax
  shl    $0x3,%edi
  and    $0x7e0,%di
  and    $0xf800,%ax
  or     %edi,%eax
  movzbl 0x6(%rsi),%edi
  shr    $0x3,%dil
  movzbl %dil,%edi
  or     %edi,%eax
  mov    %ax,0x4(%r10)
  cmp    $0x3,%edx
  je     L235
  movzbl 0xa(%rsi),%eax
  movzbl 0xb(%rsi),%edx
  shl    $0x3,%eax
  shl    $0x8,%edx
  and    $0xf800,%dx
  and    $0x7e0,%ax
  or     %edx,%eax
  movzbl 0x9(%rsi),%edx
  shr    $0x3,%dl
  movzbl %dl,%edx
  or     %edx,%eax
  mov    %ax,0x6(%r10)
L235:
  mov    %ecx,%eax
  add    $0x1,%rax
  lea    (%rax,%rax,1),%rdx
  lea    (%r10,%rdx,1),%rcx
  add    %rax,%rdx
  add    %rdx,%rsi
L93:
  add    %r12,%rsi
  add    %r15,%rcx
  add    $0x1,%ebp
  cmp    %ebp,0x78(%rsp)
  jne    L313
  jmp    L280
L47:
  mov    $0xffffffff,%eax
  jmp    L158
L196:
  mov    %r10,%rcx
  jmp    L93
L307:
  call   <__stack_chk_fail@plt>
L312:
  mov    %r9,%rax
  jmp    L270
```

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