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

```asm
<SplitChannels>:
  endbr64
  mov    %rdi,%r10
  mov    %r9d,%edi
  push   %r15
  mov    %rsi,%r11
  push   %r14
  mov    %edi,%eax
  push   %r13
  push   %r12
  push   %rbp
  mov    %rcx,%rbp
  movslq %r8d,%rcx
  push   %rbx
  cmp    %edi,0x38(%rsp)
  mov    %rdx,%rbx
  cmovle 0x38(%rsp),%eax
  cmp    0x40(%rsp),%eax
  mov    0x50(%rsp),%r12
  mov    0x58(%rsp),%r13
  mov    %eax,%edx
  cmovg  0x40(%rsp),%edx
  mov    %edi,%eax
  mov    %r9d,-0x2c(%rsp)
  mov    0x48(%rsp),%r9
  add    %r10,%rcx
  mov    %edx,%edi
  mov    %edx,-0x28(%rsp)
  cltd
  idiv   %edi
  movl   $0x0,(%r9)
  movl   $0x0,(%r12)
  movl   $0x0,0x0(%r13)
  mov    %edi,%edx
  mov    %edx,%esi
  imul   %eax,%edi
  mov    %eax,-0x18(%rsp)
  mov    %eax,%r14d
  mov    0x38(%rsp),%eax
  add    %edi,%esi
  mov    %edi,-0x24(%rsp)
  mov    %edx,%edi
  cltd
  idiv   %edi
  mov    %esi,-0x38(%rsp)
  mov    %edi,%edx
  mov    %edx,%esi
  imul   %eax,%edi
  mov    %eax,-0x14(%rsp)
  mov    %eax,%r8d
  mov    0x40(%rsp),%eax
  add    %edi,%esi
  mov    %edi,-0x20(%rsp)
  mov    %edx,%edi
  cltd
  idiv   %edi
  mov    %esi,-0x34(%rsp)
  mov    %edi,%edx
  mov    %edx,%esi
  imul   %eax,%edi
  mov    %eax,-0x10(%rsp)
  add    %edi,%esi
  mov    %edi,-0x1c(%rsp)
  mov    %esi,-0x30(%rsp)
  test   %edx,%edx
  jle    L153
  lea    0x1(%r14),%edx
  add    $0x1,%eax
  xor    %edi,%edi
  mov    %r10,%rsi
  mov    %edx,-0xc(%rsp)
  lea    0x1(%r8),%edx
  xor    %r15d,%r15d
  mov    %edi,%r10d
  movl   $0x0,-0x3c(%rsp)
  movl   $0x0,-0x40(%rsp)
  mov    %edx,-0x8(%rsp)
  mov    %eax,-0x4(%rsp)
L61:
  mov    -0x38(%rsp),%edx
  mov    -0x40(%rsp),%eax
  add    -0x2c(%rsp),%eax
  cmp    %eax,%edx
  jg     L202
  sub    %edx,%eax
  mov    -0x34(%rsp),%edi
  mov    -0xc(%rsp),%r8d
  mov    %eax,-0x40(%rsp)
  mov    -0x3c(%rsp),%eax
  add    0x38(%rsp),%eax
  cmp    %eax,%edi
  jg     L64
L177:
  sub    %edi,%eax
  mov    -0x8(%rsp),%edx
  mov    %eax,-0x3c(%rsp)
L130:
  mov    -0x30(%rsp),%eax
  add    0x40(%rsp),%r10d
  cmp    %r10d,%eax
  jg     L5
  mov    -0x4(%rsp),%r14d
  sub    %eax,%r10d
L156:
  cmp    %rsi,%rcx
  seta   %al
  mov    %eax,%edi
  test   %r8d,%r8d
  jle    L63
  test   %al,%al
  je     L63
  xor    %eax,%eax
  mov    %r11,%rdi
  nopl   (%rax)
L42:
  movsb  %ds:(%rsi),%es:(%rdi)
  add    $0x1,%eax
  addl   $0x1,(%r9)
  cmp    %rsi,%rcx
  seta   %r11b
  cmp    %eax,%r8d
  jle    L197
  test   %r11b,%r11b
  jne    L42
L197:
  mov    %rdi,%rax
  mov    %r11d,%edi
  mov    %rax,%r11
L63:
  test   %edx,%edx
  jle    L193
  test   %dil,%dil
  je     L193
  xor    %eax,%eax
  mov    %rbx,%rdi
L185:
  movsb  %ds:(%rsi),%es:(%rdi)
  add    $0x1,%eax
  addl   $0x1,(%r12)
  cmp    %rsi,%rcx
  seta   %r8b
  cmp    %eax,%edx
  jle    L70
  test   %r8b,%r8b
  jne    L185
L70:
  mov    %rdi,%rbx
  mov    %r8d,%edi
L193:
  test   %r14d,%r14d
  jle    L128
  test   %dil,%dil
  je     L128
  xor    %eax,%eax
  mov    %rbp,%rdi
  xchg   %ax,%ax
L88:
  movsb  %ds:(%rsi),%es:(%rdi)
  add    $0x1,%eax
  addl   $0x1,0x0(%r13)
  cmp    %rsi,%rcx
  jbe    L153
  cmp    %eax,%r14d
  jg     L88
  mov    %rdi,%rbp
L128:
  cmp    %rsi,%rcx
  jbe    L153
  add    $0x1,%r15d
  cmp    %r15d,-0x28(%rsp)
  jne    L61
L153:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L5:
  mov    -0x10(%rsp),%r14d
  sub    -0x1c(%rsp),%r10d
  jmp    L156
  nopw   0x0(%rax,%rax,1)
L202:
  sub    -0x24(%rsp),%eax
  mov    -0x34(%rsp),%edi
  mov    %eax,-0x40(%rsp)
  mov    -0x3c(%rsp),%eax
  add    0x38(%rsp),%eax
  mov    -0x18(%rsp),%r8d
  cmp    %eax,%edi
  jle    L177
L64:
  sub    -0x20(%rsp),%eax
  mov    -0x14(%rsp),%edx
  mov    %eax,-0x3c(%rsp)
  jmp    L130
```

assistant: ```c
void SplitChannels(unsigned char *buf, unsigned char *lum, unsigned char *cb, unsigned char *cr, int n_buf, int n_lum, int n_cb, int n_cr, int *count_lum, int *count_cb, int *count_cr) {
  int lum_pkg, cb_pkg, cr_pkg;
  int lum_div, cb_div, cr_div;
  int lum_cur, cb_cur, cr_cur;
  int lum_rem, cb_rem, cr_rem;
  int lum_tr0, cb_tr0, cr_tr0;
  int lum_tr1, cb_tr1, cr_tr1;
  unsigned char *pn;
  int i, pkg, min;
  min = (n_lum < (n_cb < n_cr ? n_cb : n_cr) ? n_lum : (n_cb < n_cr ? n_cb : n_cr));
  pn = buf + n_buf;
  *count_lum = 0;
  *count_cb = 0;
  *count_cr = 0;
  lum_div = n_lum / min;
  lum_cur = n_lum;
  lum_rem = 0;
  lum_tr0 = lum_div * min;
  lum_tr1 = lum_tr0 + min;
  cb_div = n_cb / min;
  cb_cur = n_cb;
  cb_rem = 0;
  cb_tr0 = cb_div * min;
  cb_tr1 = cb_tr0 + min;
  cr_div = n_cr / min;
  cr_cur = n_cr;
  cr_rem = 0;
  cr_tr0 = cr_div * min;
  cr_tr1 = cr_tr0 + min;
  for (pkg = 0; pkg < min; pkg++) {
    lum_cur = n_lum + lum_rem;
    if (lum_cur >= lum_tr1) {
      lum_pkg = lum_div + 1;
      lum_rem = lum_cur - lum_tr1;
    } else {
      lum_pkg = lum_div;
      lum_rem = lum_cur - lum_tr0;
    }
    cb_cur = n_cb + cb_rem;
    if (cb_cur >= cb_tr1) {
      cb_pkg = cb_div + 1;
      cb_rem = cb_cur - cb_tr1;
    } else {
      cb_pkg = cb_div;
      cb_rem = cb_cur - cb_tr0;
    }
    cr_cur = n_cr + cr_rem;
    if (cr_cur >= cr_tr1) {
      cr_pkg = cr_div + 1;
      cr_rem = cr_cur - cr_tr1;
    } else {
      cr_pkg = cr_div;
      cr_rem = cr_cur - cr_tr0;
    }
    for (i = 0; (buf < pn) && (i < lum_pkg); i++, (*count_lum)++)
      *lum++ = *buf++;
    for (i = 0; (buf < pn) && (i < cb_pkg); i++, (*count_cb)++)
      *cb++ = *buf++;
    for (i = 0; (buf < pn) && (i < cr_pkg); i++, (*count_cr)++)
      *cr++ = *buf++;
    if (buf >= pn)
      return;
  }
}
```