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

```asm
<convert_image_to_DXT5>:
  endbr64
  push   %r15
  push   %r14
  mov    %edx,%r14d
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xf8,%rsp
  mov    %rdi,0x18(%rsp)
  mov    %esi,0x30(%rsp)
  mov    %edx,0x7c(%rsp)
  mov    %ecx,0x60(%rsp)
  mov    %fs:0x28,%rdx
  mov    %rdx,0xe8(%rsp)
  xor    %edx,%edx
  movl   $0x0,(%r8)
  test   %esi,%esi
  jle    L64
  mov    %ecx,%ebx
  mov    %r14d,%ecx
  test   %r14d,%r14d
  jle    L64
  lea    -0x1(%rbx),%edx
  cmp    $0x3,%edx
  ja     L64
  test   %rdi,%rdi
  je     L64
  mov    %ebx,%edx
  cmp    $0x2,%ebx
  mov    %ebx,%edi
  mov    %esi,%r14d
  not    %edx
  setg   0x5b(%rsp)
  and    $0x1,%edi
  and    $0x1,%edx
  mov    %edi,0x50(%rsp)
  lea    0x3(%rsi),%edi
  lea    0xa0(%rsp),%r12
  mov    %edx,0x54(%rsp)
  lea    0x3(%rcx),%edx
  sar    $0x2,%edi
  sar    $0x2,%edx
  imul   %edx,%edi
  shl    $0x4,%edi
  mov    %edi,(%r8)
  call   <malloc@plt>
  lea    0x0(,%rbx,4),%edi
  xor    %edx,%edx
  movl   $0x0,0x78(%rsp)
  mov    %rax,%rcx
  mov    %rax,0x70(%rsp)
  imul   %r14d,%ebx
  lea    -0x4(,%r14,4),%eax
  and    $0xfffffff0,%eax
  mov    %edi,0x48(%rsp)
  imul   %r14d,%edi
  test   %r14d,%r14d
  cmovg  %eax,%edx
  lea    0x98(%rsp),%rax
  movl   $0x0,0x6c(%rsp)
  mov    %r12,%r14
  sub    %rax,%rcx
  mov    %ebx,0x5c(%rsp)
  mov    %edi,0x84(%rsp)
  mov    %edx,0x80(%rsp)
  movl   $0x0,0x68(%rsp)
  mov    %rax,0x28(%rsp)
  mov    %rcx,0x88(%rsp)
L83:
  mov    0x6c(%rsp),%ebx
  mov    0x7c(%rsp),%edi
  movl   $0x0,0x24(%rsp)
  mov    %ebx,%edx
  mov    %edi,%eax
  add    $0x4,%ebx
  sub    %edx,%eax
  mov    %ebx,0x6c(%rsp)
  cmp    %ebx,%edi
  mov    $0x4,%ebx
  cmovg  %ebx,%eax
  mov    0x88(%rsp),%rdi
  mov    %eax,%ebx
  mov    %eax,0x8(%rsp)
  movslq 0x68(%rsp),%rax
  lea    (%rdi,%rax,1),%r13
  mov    %ebx,%eax
  mov    0x78(%rsp),%ebx
  shl    $0x4,%eax
  mov    %ebx,0x34(%rsp)
  mov    0x28(%rsp),%rbx
  lea    0x8(%rbx),%r15
  mov    0x30(%rsp),%ebx
  add    $0x4,%ebx
  mov    %ebx,0x4c(%rsp)
  mov    $0x40,%ebx
  sub    %eax,%ebx
  mov    %ebx,0x64(%rsp)
  nopl   0x0(%rax)
L2:
  addl   $0x4,0x24(%rsp)
  mov    0x4c(%rsp),%r12d
  mov    0x24(%rsp),%eax
  sub    %eax,%r12d
  cmp    0x30(%rsp),%eax
  mov    $0x4,%eax
  cmovl  %eax,%r12d
  mov    0x8(%rsp),%eax
  test   %eax,%eax
  jle    L96
  lea    -0x1(%r12),%edx
  mov    %r13,0x38(%rsp)
  mov    0x34(%rsp),%ebp
  xor    %ebx,%ebx
  mov    %rdx,%rax
  movzbl 0x5b(%rsp),%esi
  mov    0x5c(%rsp),%r13d
  xor    %r9d,%r9d
  shl    $0x2,%eax
  movzbl 0x54(%rsp),%r11d
  movzbl 0x50(%rsp),%r10d
  mov    %r15,0x40(%rsp)
  mov    %eax,0xc(%rsp)
  mov    $0x3,%eax
  sub    %r12d,%eax
  mov    %eax,%ecx
  shl    $0x2,%eax
  mov    %eax,0x20(%rsp)
  lea    0xa4(%rsp),%rax
  lea    (%rax,%rcx,4),%rdi
  lea    (%rax,%rdx,4),%rax
  mov    %rdi,0x10(%rsp)
  movslq 0x60(%rsp),%rdi
  mov    %rax,%r15
L62:
  test   %r12d,%r12d
  jle    L130
  movslq %r9d,%r8
  movslq %ebp,%rcx
  add    0x18(%rsp),%rcx
  lea    (%r14,%r8,1),%rdx
  add    %r15,%r8
  nopw   0x0(%rax,%rax,1)
L32:
  movzbl (%rcx),%eax
  add    $0x4,%rdx
  mov    %al,-0x4(%rdx)
  movzbl (%rcx,%rsi,1),%eax
  mov    %al,-0x3(%rdx)
  movzbl (%rcx,%rsi,2),%eax
  mov    %al,-0x2(%rdx)
  movzbl -0x1(%rcx,%rdi,1),%eax
  add    %rdi,%rcx
  imul   %r11d,%eax
  sub    %r10d,%eax
  mov    %al,-0x1(%rdx)
  cmp    %r8,%rdx
  jne    L32
  mov    0xc(%rsp),%eax
  lea    0x4(%r9,%rax,1),%r9d
  cmp    $0x3,%r12d
  jg     L117
L130:
  movslq %r9d,%rdx
  lea    (%r14,%rdx,1),%rax
  add    0x10(%rsp),%rdx
  nopw   0x0(%rax,%rax,1)
L88:
  movzbl 0xa0(%rsp),%ecx
  add    $0x4,%rax
  mov    %cl,-0x4(%rax)
  movzbl 0xa1(%rsp),%ecx
  mov    %cl,-0x3(%rax)
  movzbl 0xa2(%rsp),%ecx
  mov    %cl,-0x2(%rax)
  movzbl 0xa3(%rsp),%ecx
  mov    %cl,-0x1(%rax)
  cmp    %rdx,%rax
  jne    L88
  mov    0x20(%rsp),%eax
  lea    0x4(%r9,%rax,1),%r9d
L117:
  add    $0x1,%ebx
  add    %r13d,%ebp
  cmp    %ebx,0x8(%rsp)
  jne    L62
  cmpl   $0x3,0x8(%rsp)
  mov    0x38(%rsp),%r13
  mov    0x40(%rsp),%r15
  jg     L5
L104:
  movslq %r9d,%rax
  lea    0xb0(%rsp,%rax,1),%rdx
  mov    0x64(%rsp),%eax
  lea    (%rax,%r9,1),%ecx
  nopw   0x0(%rax,%rax,1)
L47:
  lea    -0x10(%rdx),%rax
L97:
  movzbl 0xa0(%rsp),%esi
  add    $0x4,%rax
  mov    %sil,-0x4(%rax)
  movzbl 0xa1(%rsp),%esi
  mov    %sil,-0x3(%rax)
  movzbl 0xa2(%rsp),%esi
  mov    %sil,-0x2(%rax)
  movzbl 0xa3(%rsp),%esi
  mov    %sil,-0x1(%rax)
  cmp    %rdx,%rax
  jne    L97
  add    $0x10,%r9d
  add    $0x10,%rdx
  cmp    %ecx,%r9d
  jne    L47
L5:
  mov    0x28(%rsp),%rbx
  mov    %r14,%rdi
  mov    %rbx,%rsi
  call   <compress_DDS_alpha_block@plt>
  mov    %rbx,%rax
  nopl   (%rax)
L111:
  movzbl (%rax),%edx
  add    $0x1,%rax
  mov    %dl,-0x1(%rax,%r13,1)
  cmp    %r15,%rax
  jne    L111
  mov    0x28(%rsp),%rbx
  mov    %r14,%rsi
  mov    $0x4,%edi
  mov    %rbx,%rdx
  call   <compress_DDS_color_block@plt>
  mov    %rbx,%rax
  nopl   0x0(%rax)
L59:
  movzbl (%rax),%edx
  add    $0x1,%rax
  mov    %dl,0x7(%rax,%r13,1)
  cmp    %r15,%rax
  jne    L59
  mov    0x48(%rsp),%ebx
  add    $0x10,%r13
  add    %ebx,0x34(%rsp)
  mov    0x30(%rsp),%ebx
  cmp    %ebx,0x24(%rsp)
  jl     L2
  mov    0x68(%rsp),%ebx
  mov    0x80(%rsp),%eax
  lea    0x10(%rax,%rbx,1),%eax
  mov    0x84(%rsp),%ebx
  add    %ebx,0x78(%rsp)
  mov    %eax,0x68(%rsp)
  mov    0x6c(%rsp),%ebx
  cmp    %ebx,0x7c(%rsp)
  jg     L83
L169:
  mov    0xe8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L87
  mov    0x70(%rsp),%rax
  add    $0xf8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L96:
  xor    %r9d,%r9d
  jmp    L104
L64:
  movq   $0x0,0x70(%rsp)
  jmp    L169
L87:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
unsigned char *convert_image_to_DXT5(const unsigned char *const uncompressed, int width, int height, int channels, int *out_size) {
  unsigned char *compressed;
  int i, j, x, y;
  unsigned char ublock[16 * 4];
  unsigned char cblock[8];
  int index = 0, chan_step = 1;
  int block_count = 0, has_alpha;
  *out_size = 0;
  if ((width < 1) || (height < 1) || (NULL == uncompressed) || (channels < 1) || (channels > 4)) {
    return NULL;
  }
  if (channels < 3) {
    chan_step = 0;
  }
  has_alpha = 1 - (channels & 1);
  *out_size = ((width + 3) >> 2) * ((height + 3) >> 2) * 16;
  compressed = (unsigned char *)malloc(*out_size);
  for (j = 0; j < height; j += 4) {
    for (i = 0; i < width; i += 4) {
      int idx = 0;
      int mx = 4, my = 4;
      if (j + 4 >= height) {
        my = height - j;
      }
      if (i + 4 >= width) {
        mx = width - i;
      }
      for (y = 0; y < my; ++y) {
        for (x = 0; x < mx; ++x) {
          ublock[idx++] = uncompressed[(j + y) * width * channels + (i + x) * channels];
          ublock[idx++] = uncompressed[(j + y) * width * channels + (i + x) * channels + chan_step];
          ublock[idx++] = uncompressed[(j + y) * width * channels + (i + x) * channels + chan_step + chan_step];
          ublock[idx++] = has_alpha * uncompressed[(j + y) * width * channels + (i + x) * channels + channels - 1] + (1 - has_alpha) * 255;
        }
        for (x = mx; x < 4; ++x) {
          ublock[idx++] = ublock[0];
          ublock[idx++] = ublock[1];
          ublock[idx++] = ublock[2];
          ublock[idx++] = ublock[3];
        }
      }
      for (y = my; y < 4; ++y) {
        for (x = 0; x < 4; ++x) {
          ublock[idx++] = ublock[0];
          ublock[idx++] = ublock[1];
          ublock[idx++] = ublock[2];
          ublock[idx++] = ublock[3];
        }
      }
      compress_DDS_alpha_block(ublock, cblock);
      for (x = 0; x < 8; ++x) {
        compressed[index++] = cblock[x];
      }
      ++block_count;
      compress_DDS_color_block(4, ublock, cblock);
      for (x = 0; x < 8; ++x) {
        compressed[index++] = cblock[x];
      }
    }
  }
  return compressed;
}
```