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

```asm
<qsort_r>:
  endbr64
  push   %r15
  mov    %rsi,%rax
  push   %r14
  push   %r13
  push   %r12
  mov    %r8,%r12
  push   %rbp
  mov    %rcx,%rbp
  push   %rbx
  mov    %rdx,%rbx
  mov    %rsi,%rdx
  imul   %rbx,%rdx
  sub    $0x48,%rsp
  add    %rdi,%rdx
  mov    %rdi,0x30(%rsp)
  mov    %rbx,%rdi
  neg    %rdi
  mov    %rdx,0x28(%rsp)
  mov    %rdi,0x10(%rsp)
  cmp    $0x9,%rsi
  jbe    L29
L21:
  lea    -0x1(%rax),%r13
  shr    %rax
  mov    0x30(%rsp),%rdi
  mov    %r12,%rdx
  imul   %rbx,%rax
  imul   %rbx,%r13
  lea    (%rdi,%rbx,1),%r14
  lea    (%rdi,%rax,1),%r15
  mov    0x10(%rsp),%rax
  add    %rdi,%r13
  mov    %r15,%rsi
  mov    %r14,%rdi
  add    %r13,%rax
  mov    %rax,0x8(%rsp)
  call   *%rbp
  test   %eax,%eax
  jle    L155
  mov    %r14,%rax
  mov    %r15,%r14
  mov    %rax,%r15
L155:
  mov    0x8(%rsp),%rsi
  mov    %r12,%rdx
  mov    %r15,%rdi
  call   *%rbp
  test   %eax,%eax
  jle    L1
  mov    0x8(%rsp),%r15
  mov    %r12,%rdx
  mov    %r14,%rdi
  mov    %r15,%rsi
  call   *%rbp
  test   %eax,%eax
  cmovg  %r14,%r15
L1:
  cmp    %r13,%r15
  je     L123
  mov    %rbx,%rdx
  mov    %r13,%rsi
  mov    %r15,%rdi
  call   <sort_r_swap@plt>
L123:
  mov    0x30(%rsp),%r14
  cmp    %r14,%r13
  jbe    L20
  mov    %r13,0x8(%rsp)
  mov    %r13,%r15
  mov    %r14,0x18(%rsp)
  jmp    L143
  nopw   0x0(%rax,%rax,1)
L190:
  add    %rbx,0x18(%rsp)
L4:
  add    %rbx,%r14
  cmp    %r15,%r14
  jae    L164
L143:
  mov    %r12,%rdx
  mov    %r13,%rsi
  mov    %r14,%rdi
  call   *%rbp
  test   %eax,%eax
  jg     L122
  jne    L4
  cmp    0x18(%rsp),%r14
  jbe    L190
  mov    0x18(%rsp),%rdi
  mov    %rbx,%rdx
  mov    %r14,%rsi
  call   <sort_r_swap@plt>
  jmp    L190
  nop
L19:
  js     L259
L122:
  cmp    %r14,%r15
  jbe    L164
L248:
  add    0x10(%rsp),%r15
  mov    %r12,%rdx
  mov    %r13,%rsi
  mov    %r15,%rdi
  call   *%rbp
  test   %eax,%eax
  jne    L19
  mov    0x10(%rsp),%rax
  add    %rax,0x8(%rsp)
  mov    0x8(%rsp),%rcx
  cmp    %rcx,%r15
  jae    L122
  mov    %rbx,%rdx
  mov    %rcx,%rsi
  mov    %r15,%rdi
  call   <sort_r_swap@plt>
  cmp    %r14,%r15
  ja     L248
  cs nopw 0x0(%rax,%rax,1)
L164:
  mov    0x8(%rsp),%rax
  mov    0x18(%rsp),%esi
  sub    0x30(%rsp),%esi
  sub    %r15,%rax
  mov    %rax,%r13
  mov    %eax,%r9d
  mov    0x28(%rsp),%rax
  sub    %r13,%rax
  mov    %rax,0x20(%rsp)
L195:
  mov    0x30(%rsp),%r14
  mov    %r15,%rcx
  sub    0x18(%rsp),%rcx
  mov    %r9d,0x3c(%rsp)
  mov    %ecx,%edx
  mov    %rcx,0x18(%rsp)
  mov    %r14,%rdi
  call   <sort_r_swap_blocks@plt>
  mov    0x3c(%rsp),%esi
  mov    0x28(%rsp),%edx
  mov    %r15,%rdi
  sub    0x8(%rsp),%edx
  call   <sort_r_swap_blocks@plt>
  mov    0x18(%rsp),%rax
  xor    %edx,%edx
  mov    %r14,%rdi
  mov    %r12,%r8
  mov    %rbp,%rcx
  div    %rbx
  mov    %rbx,%rdx
  mov    %rax,%rsi
  call   <qsort_r>
  mov    %r13,%rax
  xor    %edx,%edx
  mov    0x20(%rsp),%rdi
  div    %rbx
  mov    %rax,%rdx
  imul   %rbx,%rdx
  add    %rdi,%rdx
  mov    %rdx,0x28(%rsp)
  cmp    $0x9,%rax
  jbe    L38
  mov    %rdi,0x30(%rsp)
  jmp    L21
  nopw   0x0(%rax,%rax,1)
L259:
  cmp    %r14,%r15
  ja     L171
L191:
  add    %rbx,%r14
  cmp    %r14,%r15
  ja     L143
  jmp    L164
  xchg   %ax,%ax
L171:
  mov    %rbx,%rdx
  mov    %r15,%rsi
  mov    %r14,%rdi
  call   <sort_r_swap@plt>
  jmp    L191
L29:
  mov    0x30(%rsp),%rax
  mov    %rax,0x20(%rsp)
L38:
  mov    0x20(%rsp),%rax
  lea    (%rax,%rbx,1),%r13
  cmp    0x28(%rsp),%r13
  jae    L117
  nopw   0x0(%rax,%rax,1)
L18:
  mov    %r13,%rsi
  jmp    L226
  nopl   (%rax)
L175:
  mov    %rsi,%r14
  mov    %r12,%r8
  mov    %rbp,%rcx
  mov    %rbx,%rdx
  sub    %rbx,%r14
  mov    %r14,%rdi
  call   <sort_r_cmpswap@plt>
  test   %rax,%rax
  je     L42
  mov    %r14,%rsi
L226:
  cmp    0x20(%rsp),%rsi
  ja     L175
L42:
  add    %rbx,%r13
  cmp    0x28(%rsp),%r13
  jb     L18
L117:
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L20:
  mov    0x28(%rsp),%rax
  mov    %r13,0x8(%rsp)
  mov    %r13,%r15
  xor    %r9d,%r9d
  xor    %r13d,%r13d
  xor    %esi,%esi
  mov    %rax,0x20(%rsp)
  mov    0x30(%rsp),%rax
  mov    %rax,0x18(%rsp)
  jmp    L195
```

assistant: ```c
void qsort_r(void *base, size_t nel, size_t w, int (*compar)(const void *_a, const void *_b, void *_arg), void *arg) {
  char *b = (char *)base, *end = b + nel * w;
  if (nel < 10) {
    char *pi, *pj;
    for (pi = b + w; pi < end; pi += w) {
      for (pj = pi; pj > b && sort_r_cmpswap(pj - w, pj, w, compar, arg); pj -= w) {
      }
    }
  } else {
    int cmp;
    char *pl, *ple, *pr, *pre, *pivot;
    char *last = b + w * (nel - 1), *tmp;
    char *l[3];
    l[0] = b + w;
    l[1] = b + w * (nel / 2);
    l[2] = last - w;
    if (compar(l[0], l[1], arg) > 0) {
      ((tmp) = (l[0]), (l[0]) = (l[1]), (l[1]) = (tmp));
    }
    if (compar(l[1], l[2], arg) > 0) {
      ((tmp) = (l[1]), (l[1]) = (l[2]), (l[2]) = (tmp));
      if (compar(l[0], l[1], arg) > 0) {
        ((tmp) = (l[0]), (l[0]) = (l[1]), (l[1]) = (tmp));
      }
    }
    if (l[1] != last) {
      sort_r_swap(l[1], last, w);
    }
    pivot = last;
    ple = pl = b;
    pre = pr = last;
    while (pl < pr) {
      for (; pl < pr; pl += w) {
        cmp = compar(pl, pivot, arg);
        if (cmp > 0) {
          break;
        } else if (cmp == 0) {
          if (ple < pl) {
            sort_r_swap(ple, pl, w);
          }
          ple += w;
        }
      }
      if (pl >= pr) {
        break;
      }
      for (; pl < pr;) {
        pr -= w;
        cmp = compar(pr, pivot, arg);
        if (cmp == 0) {
          pre -= w;
          if (pr < pre) {
            sort_r_swap(pr, pre, w);
          }
        } else if (cmp < 0) {
          if (pl < pr) {
            sort_r_swap(pl, pr, w);
          }
          pl += w;
          break;
        }
      }
    }
    pl = pr;
    sort_r_swap_blocks(b, ple - b, pl - ple);
    sort_r_swap_blocks(pr, pre - pr, end - pre);
    qsort_r(b, (pl - ple) / w, w, compar, arg);
    qsort_r(end - (pre - pr), (pre - pr) / w, w, compar, arg);
  }
}
```