user: Translate the below assembly code into C programming language:

```asm
<OptimizeHuffmanForRle>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  test   %edi,%edi
  js     L248
  je     L219
  mov    %rsi,%r14
  movslq %edi,%rax
  jmp    L45
  nopl   0x0(%rax,%rax,1)
L383:
  sub    $0x1,%rax
  test   %eax,%eax
  je     L219
L45:
  cmpq   $0x0,-0x8(%r14,%rax,8)
  mov    %eax,%ebx
  je     L383
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  mov    %rax,%r10
  test   %ebx,%ebx
  jle    L46
  lea    -0x1(%rbx),%eax
  xor    %esi,%esi
  mov    %r10,%rdi
  lea    0x4(,%rax,4),%rdx
  call   <memset@plt>
  mov    (%r14),%rsi
  mov    %rax,%r10
L302:
  movdqa D3(%rip),%xmm0
  mov    %r10,%r15
  mov    %r10,%rdi
  xor    %eax,%eax
  mov    %rsi,%r9
  xor    %ecx,%ecx
  jmp    L443
  nopl   0x0(%rax)
L318:
  cmp    $0x4,%ecx
  jg     L303
  test   %r9,%r9
  jne    L409
L292:
  cmp    %ebp,%ebx
  je     L398
  mov    (%r14,%rax,8),%r9
L398:
  add    $0x1,%rax
  mov    $0x1,%ecx
  add    $0x4,%rdi
  cmp    %eax,%ebx
  jl     L198
L443:
  mov    %eax,%r11d
  mov    %eax,%ebp
  cmp    %eax,%ebx
  je     L59
  cmp    %r9,(%r14,%rax,8)
  je     L377
L59:
  test   %r9,%r9
  je     L318
L409:
  cmp    $0x6,%ecx
  jle    L292
L303:
  lea    -0x1(%rcx),%edx
  cmp    $0x2,%edx
  jbe    L52
  mov    %ecx,%r12d
  lea    -0x20(%rdi),%r8
  lea    -0x10(%rdi),%rdx
  shr    $0x2,%r12d
  sub    $0x1,%r12d
  shl    $0x4,%r12
  sub    %r12,%r8
  nopw   0x0(%rax,%rax,1)
L315:
  movups %xmm0,(%rdx)
  sub    $0x10,%rdx
  cmp    %r8,%rdx
  jne    L315
  mov    %ecx,%edx
  and    $0xfffffffc,%edx
  test   $0x3,%cl
  je     L292
L339:
  mov    %r11d,%r8d
  lea    0x1(%rdx),%r12d
  sub    %edx,%r8d
  movslq %r8d,%r8
  movl   $0x1,-0x4(%r10,%r8,4)
  cmp    %ecx,%r12d
  jge    L292
  mov    %r11d,%r8d
  add    $0x2,%edx
  sub    %r12d,%r8d
  movslq %r8d,%r8
  movl   $0x1,-0x4(%r10,%r8,4)
  cmp    %ecx,%edx
  jge    L292
  sub    %edx,%r11d
  movslq %r11d,%r11
  movl   $0x1,-0x4(%r10,%r11,4)
  jmp    L292
  xchg   %ax,%ax
L377:
  add    $0x1,%rax
  add    $0x1,%ecx
  add    $0x4,%rdi
  cmp    %eax,%ebx
  jge    L443
L198:
  lea    -0x10(%r14),%rcx
  xor    %r12d,%r12d
  xor    %r13d,%r13d
  xor    %ebp,%ebp
  jmp    L332
  nopl   0x0(%rax)
L397:
  mov    0x20(%rcx),%rdx
  mov    0x18(%rcx),%rax
  add    0x10(%rcx),%rax
  lea    0x2(%rax,%rdx,1),%rsi
  add    0x28(%rcx),%rsi
  shr    $0x2,%rsi
L106:
  cmp    %ebp,%ebx
  je     L313
  mov    0x10(%rcx),%r12
  mov    $0x1,%r13d
L340:
  add    $0x1,%ebp
  add    $0x4,%r15
  add    $0x8,%rcx
  cmp    %ebp,%ebx
  jl     L311
L332:
  cmp    %ebp,%ebx
  je     L321
  mov    (%r15),%eax
  test   %eax,%eax
  je     L372
L321:
  cmp    $0x3,%r13d
  jg     L149
  jne    L163
  test   %r12,%r12
  je     L12
  nopw   0x0(%rax,%rax,1)
L163:
  lea    -0x3(%rbx),%eax
  cmp    %ebp,%eax
  jg     L397
  cmp    %ebp,%ebx
  jle    L128
  mov    0x10(%rcx),%rsi
  add    $0x1,%ebp
  add    $0x4,%r15
  add    $0x8,%rcx
  mov    $0x1,%r13d
  mov    %rsi,%r12
  cmp    %ebp,%ebx
  jge    L332
L311:
  mov    0x18(%rsp),%rdi
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1080 <free@plt>
  nopl   0x0(%rax,%rax,1)
L372:
  mov    0x10(%rcx),%rdi
  mov    %rcx,0x8(%rsp)
  mov    %rsi,0x10(%rsp)
  call   <AbsDiff@plt>
  mov    0x8(%rsp),%rcx
  cmp    $0x3,%eax
  jg     L321
  mov    0x10(%rsp),%rsi
  add    $0x1,%r13d
  add    0x10(%rcx),%r12
  jmp    L340
  nop
L149:
  mov    %r13d,%eax
  xor    %edx,%edx
  movslq %r13d,%rsi
  sar    %eax
  cltq
  add    %r12,%rax
  div    %rsi
  mov    $0x1,%edx
  test   %eax,%eax
  cmovle %edx,%eax
  test   %r12,%r12
  cltq
  cmovne %rax,%r12
L296:
  test   %r13d,%r13d
  movq   %r12,%xmm0
  mov    $0x1,%r9d
  cmovg  %r13d,%r9d
  lea    -0x10(%rcx),%rdx
  punpcklqdq %xmm0,%xmm0
  mov    %r9d,%eax
  shr    %eax
  sub    $0x1,%eax
  shl    $0x4,%rax
  sub    %rax,%rdx
  mov    %rcx,%rax
  nopl   0x0(%rax)
L156:
  movups %xmm0,(%rax)
  sub    $0x10,%rax
  cmp    %rdx,%rax
  jne    L156
  mov    %r9d,%edx
  and    $0xfffffffe,%edx
  and    $0x1,%r9d
  je     L163
  mov    %ebp,%eax
  sub    %edx,%eax
  cltq
  mov    %r12,-0x8(%r14,%rax,8)
  jmp    L163
  nopl   0x0(%rax)
L313:
  mov    $0x1,%r13d
  xor    %r12d,%r12d
  jmp    L340
  cs nopw 0x0(%rax,%rax,1)
L12:
  xor    %r12d,%r12d
  jmp    L296
  nopl   (%rax)
L128:
  xor    %esi,%esi
  jmp    L106
  nop
L219:
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L52:
  xor    %edx,%edx
  jmp    L339
L46:
  jne    L311
  mov    (%r14),%rsi
  jmp    L302
  nopl   0x0(%rax)
L248:
  shl    $0x2,%edi
  call   <malloc@plt>
  mov    %rax,0x18(%rsp)
  jmp    L311
```

tool_calls: name: read_data
arguments: data_label: D3
type: byte[16]

tool: {"D3": [0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00]}

assistant: ```c
void OptimizeHuffmanForRle(int length, size_t *counts) {
  int i, k, stride;
  size_t symbol, sum, limit;
  int *good_for_rle;
  for (; length >= 0; --length) {
    if (length == 0) {
      return;
    }
    if (counts[length - 1] != 0) {
      break;
    }
  }
  good_for_rle = (int *)malloc(length * sizeof(int));
  for (i = 0; i < length; ++i)
    good_for_rle[i] = 0;
  symbol = counts[0];
  stride = 0;
  for (i = 0; i < length + 1; ++i) {
    if (i == length || counts[i] != symbol) {
      if ((symbol == 0 && stride >= 5) || (symbol != 0 && stride >= 7)) {
        for (k = 0; k < stride; ++k) {
          good_for_rle[i - k - 1] = 1;
        }
      }
      stride = 1;
      if (i != length) {
        symbol = counts[i];
      }
    } else {
      ++stride;
    }
  }
  stride = 0;
  limit = counts[0];
  sum = 0;
  for (i = 0; i < length + 1; ++i) {
    if (i == length || good_for_rle[i] || AbsDiff(counts[i], limit) >= 4) {
      if (stride >= 4 || (stride >= 3 && sum == 0)) {
        int count = (sum + stride / 2) / stride;
        if (count < 1)
          count = 1;
        if (sum == 0) {
          count = 0;
        }
        for (k = 0; k < stride; ++k) {
          counts[i - k - 1] = count;
        }
      }
      stride = 0;
      sum = 0;
      if (i < length - 3) {
        limit = (counts[i] + counts[i + 1] + counts[i + 2] + counts[i + 3] + 2) / 4;
      } else if (i < length) {
        limit = counts[i];
      } else {
        limit = 0;
      }
    }
    ++stride;
    if (i != length) {
      sum += counts[i];
    }
  }
  free(good_for_rle);
}
```