user: Please show me the C implementation that matches the assembly code listed below:

```asm
<qsort_r>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,0x48(%rsp)
  mov    %rdx,%rbp
  mov    %rcx,%r13
  mov    %r8,%r14
  mov    %rsi,%rax
  imul   %rdx,%rax
  add    %rdi,%rax
  mov    %rax,0x30(%rsp)
  cmp    $0x9,%rsi
  ja     L204
  mov    %rdi,%r15
  lea    (%rdi,%rdx,1),%r12
  cmp    %r12,%rax
  ja     L297
  jmp    L296
L94:
  mov    %rbx,%rsi
L207:
  cmp    %r15,%rsi
  jbe    L218
  mov    %rsi,%rbx
  sub    %rbp,%rbx
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %rbp,%rdx
  mov    %rbx,%rdi
  call   <sort_r_cmpswap@plt>
  test   %rax,%rax
  jne    L94
L218:
  add    %rbp,%r12
  cmp    %r12,0x30(%rsp)
  jbe    L296
L297:
  mov    %r12,%rsi
  jmp    L207
L204:
  mov    %rsi,%rbx
  lea    -0x1(%rsi),%rax
  imul   %rdx,%rax
  mov    0x48(%rsp),%rcx
  add    %rcx,%rax
  mov    %rax,0x18(%rsp)
  lea    (%rcx,%rdx,1),%r15
  shr    %rbx
  imul   %rdx,%rbx
  add    %rcx,%rbx
  mov    %rdx,%rcx
  neg    %rcx
  mov    %rcx,0x10(%rsp)
  sub    %rdx,%rax
  mov    %rax,%r12
  mov    %r8,%rdx
  mov    %rbx,%rsi
  mov    %r15,%rdi
  call   *%r13
  mov    %r15,0x8(%rsp)
  test   %eax,%eax
  jle    L121
  mov    %rbx,0x8(%rsp)
  mov    %r15,%rbx
L121:
  mov    %r14,%rdx
  mov    %r12,%rsi
  mov    %rbx,%rdi
  call   *%r13
  test   %eax,%eax
  jle    L36
  mov    %r14,%rdx
  mov    %r12,%rsi
  mov    0x8(%rsp),%rbx
  mov    %rbx,%rdi
  call   *%r13
  test   %eax,%eax
  cmovle %r12,%rbx
L36:
  mov    0x18(%rsp),%rax
  cmp    %rax,%rbx
  je     L159
  mov    %rbp,%rdx
  mov    %rax,%rsi
  mov    %rbx,%rdi
  call   <sort_r_swap@plt>
L159:
  mov    0x48(%rsp),%rax
  mov    0x18(%rsp),%rcx
  cmp    %rcx,%rax
  jae    L238
  mov    %rax,%r12
  mov    %rcx,0x28(%rsp)
  mov    %rcx,%rbx
  mov    %rax,0x20(%rsp)
  mov    %rbp,0x8(%rsp)
  jmp    L103
L24:
  mov    0x8(%rsp),%rcx
  add    %rcx,0x20(%rsp)
L30:
  cmp    %r15,%rbx
  jbe    L141
L224:
  mov    0x8(%rsp),%rax
  add    %rax,%r12
  add    %rax,%r15
L103:
  mov    %r12,%rbp
  mov    %r14,%rdx
  mov    0x18(%rsp),%rsi
  mov    %r12,%rdi
  call   *%r13
  test   %eax,%eax
  jg     L150
  jne    L30
  cmp    0x20(%rsp),%r12
  jbe    L24
  mov    0x8(%rsp),%rdx
  mov    %r12,%rsi
  mov    0x20(%rsp),%rdi
  call   <sort_r_swap@plt>
  jmp    L24
L141:
  mov    0x8(%rsp),%rbp
  jmp    L274
L150:
  cmp    %r12,%rbx
  jbe    L74
  mov    %r15,0x38(%rsp)
  mov    0x18(%rsp),%r15
  mov    %r12,0x40(%rsp)
  mov    0x28(%rsp),%r12
  jmp    L105
L147:
  js     L59
L115:
  cmp    %rbp,%rbx
  jbe    L292
L105:
  add    0x10(%rsp),%rbx
  mov    %r14,%rdx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   *%r13
  test   %eax,%eax
  jne    L147
  add    0x10(%rsp),%r12
  cmp    %r12,%rbx
  jae    L115
  mov    0x8(%rsp),%rdx
  mov    %r12,%rsi
  mov    %rbx,%rdi
  call   <sort_r_swap@plt>
  jmp    L115
L59:
  mov    0x38(%rsp),%r15
  mov    %r12,0x28(%rsp)
  mov    0x40(%rsp),%r12
  cmp    %rbp,%rbx
  ja     L304
L2:
  cmp    %r15,%rbx
  ja     L224
  mov    0x8(%rsp),%rbp
  jmp    L274
L304:
  mov    0x8(%rsp),%rdx
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  call   <sort_r_swap@plt>
  jmp    L2
L292:
  mov    %r12,0x28(%rsp)
  mov    0x8(%rsp),%rbp
L274:
  mov    %rbx,%r15
  mov    0x20(%rsp),%rax
  sub    %rax,%r15
  mov    %r15d,%edx
  mov    %eax,%esi
  mov    0x48(%rsp),%rax
  sub    %eax,%esi
  mov    %rax,%rdi
  call   <sort_r_swap_blocks@plt>
  mov    0x28(%rsp),%rax
  mov    %rax,%r12
  sub    %rbx,%r12
  mov    0x30(%rsp),%edx
  sub    %eax,%edx
  mov    %r12d,%esi
  mov    %rbx,%rdi
  call   <sort_r_swap_blocks@plt>
  mov    %r15,%rax
  mov    $0x0,%edx
  div    %rbp
  mov    %rax,%rsi
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %rbp,%rdx
  mov    0x48(%rsp),%rdi
  call   <qsort_r>
  mov    %r12,%rax
  mov    $0x0,%edx
  div    %rbp
  mov    %rax,%rsi
  mov    0x30(%rsp),%rdi
  sub    %r12,%rdi
  mov    %r14,%r8
  mov    %r13,%rcx
  mov    %rbp,%rdx
  call   <qsort_r>
L296:
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L238:
  mov    0x18(%rsp),%rbx
  mov    %rbx,0x28(%rsp)
  mov    0x48(%rsp),%rax
  mov    %rax,0x20(%rsp)
  jmp    L274
L74:
  mov    0x8(%rsp),%rbp
  jmp    L274
```

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);
  }
}
```