user: Converte this assembly snippet into its equivalent C code:

```asm
<rle_compress_hdmv>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  movq   $0x0,(%rdi)
  mov    %rdi,0x8(%rsp)
  mov    %edx,0x14(%rsp)
  mov    %ecx,0x18(%rsp)
  movl   $0x0,(%r8)
  test   %ecx,%ecx
  jle    L45
  movslq %edx,%r15
  mov    %ecx,%eax
  mov    %r8,%rbx
  mov    %rsi,%r12
  imul   %r15d,%eax
  lea    0x0(,%r15,4),%edx
  mov    %edx,0x1c(%rsp)
  mov    %eax,%edx
  lea    0xf(%rax),%eax
  test   %edx,%edx
  cmovns %edx,%eax
  xor    %r8d,%r8d
  xor    %edi,%edi
  xor    %r14d,%r14d
  xor    %r13d,%r13d
  sar    $0x4,%eax
  cltq
  mov    %rax,0x28(%rsp)
  lea    0x0(,%r15,4),%rax
  mov    %rax,0x20(%rsp)
  lea    -0x2(%r15),%eax
  lea    0x8(%rsi,%rax,4),%rbp
  nopl   (%rax)
L62:
  mov    %rdi,%r15
  mov    %r14d,%eax
  sub    %r8,%r15
  mov    %r15,%rcx
  sar    $0x2,%rcx
  sub    %ecx,%eax
  cmp    0x1c(%rsp),%eax
  jge    L77
  test   %r14,%r14
  lea    (%r14,%r14,1),%rax
  cmove  0x28(%rsp),%rax
  mov    %r8,%rdi
  mov    %rax,%rsi
  mov    %rax,%r14
  call   <realloc@plt>
  mov    0x8(%rsp),%rcx
  lea    (%rax,%r15,1),%rdi
  mov    %rax,(%rcx)
L77:
  cmpl   $0x1,0x14(%rsp)
  mov    (%r12),%esi
  jle    L39
  lea    0x4(%r12),%r15
L57:
  mov    $0x1,%edx
L12:
  cmp    %esi,(%r15)
  jne    L48
  add    $0x4,%r15
  add    $0x1,%edx
  cmp    %rbp,%r15
  jne    L12
L23:
  call   <write_rle_hdmv@plt>
  addl   $0x1,(%rbx)
  xor    %edx,%edx
  xor    %esi,%esi
  mov    %rax,%rdi
  add    $0x1,%r13d
  call   <write_rle_hdmv@plt>
  addl   $0x1,(%rbx)
  mov    %rax,%rdi
  mov    0x20(%rsp),%rax
  add    %rax,%r12
  add    %rax,%rbp
  cmp    %r13d,0x18(%rsp)
  je     L51
  mov    0x8(%rsp),%rax
  mov    (%rax),%r8
  jmp    L62
  nopw   0x0(%rax,%rax,1)
L48:
  call   <write_rle_hdmv@plt>
  add    $0x4,%r15
  addl   $0x1,(%rbx)
  mov    -0x4(%r15),%esi
  mov    %rax,%rdi
  cmp    %r15,%rbp
  jne    L57
L39:
  mov    $0x1,%edx
  jmp    L23
  nop
L51:
  mov    0x8(%rsp),%rbx
  mov    %rdi,%rax
  sub    (%rbx),%rax
  add    $0x38,%rsp
  pop    %rbx
  sar    $0x2,%rax
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L45:
  add    $0x38,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
size_t rle_compress_hdmv(uint8_t **rle_data, const uint8_t *data, uint w, uint h, int *num_rle) {
  uint y;
  size_t rle_size = 0;
  uint8_t *rle = NULL;
  *rle_data = NULL;
  *num_rle = 0;
  for (y = 0; y < h; y++) {
    if ((ssize_t)(rle_size - (rle - *rle_data)) < w * 4) {
      size_t used = rle - *rle_data;
      rle_size = rle_size < 1 ? w * h / 16 : rle_size * 2;
      *rle_data = realloc(*rle_data, rle_size);
      rle = *rle_data + used;
    }
    uint color = *data;
    uint len = 1;
    uint x = 1;
    for (x = 1; x < w; x++) {
      if (data[x] == color) {
        len++;
      } else {
        rle = write_rle_hdmv(rle, color, len);
        (*num_rle)++;
        color = data[x];
        len = 1;
      }
    }
    if (len) {
      rle = write_rle_hdmv(rle, color, len);
      (*num_rle)++;
    }
    rle = write_rle_hdmv(rle, 0, 0);
    (*num_rle)++;
    data += w;
  }
  return rle - *rle_data;
}
```