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

```asm
<sort_r_simple>:
  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     L90
  mov    %rdi,%r15
  lea    (%rdi,%rdx,1),%r12
  cmp    %r12,%rax
  ja     L291
  jmp    L245
L202:
  mov    %rbx,%rsi
L38:
  cmp    %r15,%rsi
  jbe    L300
  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    L202
L300:
  add    %rbp,%r12
  cmp    %r12,0x30(%rsp)
  jbe    L245
L291:
  mov    %r12,%rsi
  jmp    L38
L90:
  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    L146
  mov    %rbx,0x8(%rsp)
  mov    %r15,%rbx
L146:
  mov    %r14,%rdx
  mov    %r12,%rsi
  mov    %rbx,%rdi
  call   *%r13
  test   %eax,%eax
  jle    L164
  mov    %r14,%rdx
  mov    %r12,%rsi
  mov    0x8(%rsp),%rbx
  mov    %rbx,%rdi
  call   *%r13
  test   %eax,%eax
  cmovle %r12,%rbx
L164:
  mov    0x18(%rsp),%rax
  cmp    %rax,%rbx
  je     L274
  mov    %rbp,%rdx
  mov    %rax,%rsi
  mov    %rbx,%rdi
  call   <sort_r_swap@plt>
L274:
  mov    0x48(%rsp),%rax
  mov    0x18(%rsp),%rcx
  cmp    %rcx,%rax
  jae    L253
  mov    %rax,%r12
  mov    %rcx,0x28(%rsp)
  mov    %rcx,%rbx
  mov    %rax,0x20(%rsp)
  mov    %rbp,0x8(%rsp)
  jmp    L5
L262:
  mov    0x8(%rsp),%rcx
  add    %rcx,0x20(%rsp)
L123:
  cmp    %r15,%rbx
  jbe    L142
L293:
  mov    0x8(%rsp),%rax
  add    %rax,%r12
  add    %rax,%r15
L5:
  mov    %r12,%rbp
  mov    %r14,%rdx
  mov    0x18(%rsp),%rsi
  mov    %r12,%rdi
  call   *%r13
  test   %eax,%eax
  jg     L30
  jne    L123
  cmp    0x20(%rsp),%r12
  jbe    L262
  mov    0x8(%rsp),%rdx
  mov    %r12,%rsi
  mov    0x20(%rsp),%rdi
  call   <sort_r_swap@plt>
  jmp    L262
L142:
  mov    0x8(%rsp),%rbp
  jmp    L70
L30:
  cmp    %r12,%rbx
  jbe    L263
  mov    %r15,0x38(%rsp)
  mov    0x18(%rsp),%r15
  mov    %r12,0x40(%rsp)
  mov    0x28(%rsp),%r12
  jmp    L284
L190:
  js     L275
L208:
  cmp    %rbp,%rbx
  jbe    L224
L284:
  add    0x10(%rsp),%rbx
  mov    %r14,%rdx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   *%r13
  test   %eax,%eax
  jne    L190
  add    0x10(%rsp),%r12
  cmp    %r12,%rbx
  jae    L208
  mov    0x8(%rsp),%rdx
  mov    %r12,%rsi
  mov    %rbx,%rdi
  call   <sort_r_swap@plt>
  jmp    L208
L275:
  mov    0x38(%rsp),%r15
  mov    %r12,0x28(%rsp)
  mov    0x40(%rsp),%r12
  cmp    %rbp,%rbx
  ja     L14
L155:
  cmp    %r15,%rbx
  ja     L293
  mov    0x8(%rsp),%rbp
  jmp    L70
L14:
  mov    0x8(%rsp),%rdx
  mov    %rbx,%rsi
  mov    %rbp,%rdi
  call   <sort_r_swap@plt>
  jmp    L155
L224:
  mov    %r12,0x28(%rsp)
  mov    0x8(%rsp),%rbp
L70:
  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   <sort_r_simple>
  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   <sort_r_simple>
L245:
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L253:
  mov    0x18(%rsp),%rbx
  mov    %rbx,0x28(%rsp)
  mov    0x48(%rsp),%rax
  mov    %rax,0x20(%rsp)
  jmp    L70
L263:
  mov    0x8(%rsp),%rbp
  jmp    L70
```

assistant: ```c
void sort_r_simple(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);
    sort_r_simple(b, (pl - ple) / w, w, compar, arg);
    sort_r_simple(end - (pre - pr), (pre - pr) / w, w, compar, arg);
  }
}
```