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

```asm
<_pqsort>:
  endbr64
  push   %r15
  xor    %eax,%eax
  push   %r14
  mov    %rcx,%r14
  push   %r13
  mov    %rdi,%r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x48,%rsp
  test   %rdx,%rdx
  cmovle %rdx,%rax
  mov    %rdx,0x8(%rsp)
  mov    %r8,0x28(%rsp)
  mov    %r9,0x30(%rsp)
  mov    %rax,0x38(%rsp)
L41:
  mov    0x8(%rsp),%rax
  movl   $0x2,(%rsp)
  or     %r13,%rax
  test   $0x7,%al
  je     L54
  cmp    $0x6,%rbx
  jbe    L246
L422:
  mov    0x8(%rsp),%rax
  mov    %rbx,%rbp
  lea    -0x1(%rbx),%r8
  shr    %rbp
  imul   %rax,%rbp
  imul   %rax,%r8
  add    %r13,%rbp
  lea    0x0(%r13,%r8,1),%r15
  cmp    $0x7,%rbx
  je     L427
  mov    %r15,%rdx
  mov    %r13,%r12
  cmp    $0x28,%rbx
  ja     L143
L428:
  mov    %rbp,%rsi
  mov    %r14,%rcx
  mov    %r12,%rdi
  call   <med3@plt>
  mov    %rax,%rbp
L427:
  mov    (%rsp),%esi
  test   %esi,%esi
  jne    L20
  mov    0x0(%r13),%rax
  mov    0x0(%rbp),%rdx
  mov    %rdx,0x0(%r13)
  mov    %rax,0x0(%rbp)
L448:
  mov    0x8(%rsp),%rcx
  imul   %rcx,%rbx
  lea    0x0(%r13,%rcx,1),%rax
  mov    %rax,0x18(%rsp)
  lea    0x0(%r13,%rbx,1),%rcx
  mov    %rcx,0x20(%rsp)
  cmp    %r15,%rax
  ja     L102
  mov    0x8(%rsp),%r12
  mov    0x18(%rsp),%rbx
  mov    %r15,%rbp
  neg    %r12
L367:
  mov    %rbx,0x10(%rsp)
  mov    %r13,%rsi
  mov    %rbx,%rdi
  call   *%r14
  test   %eax,%eax
  jle    L234
  cmp    0x10(%rsp),%r15
  jae    L17
  jmp    L244
  nopw   0x0(%rax,%rax,1)
L302:
  mov    (%r15),%rax
  mov    0x0(%rbp),%rdx
  mov    %rdx,(%r15)
  mov    %rax,0x0(%rbp)
L237:
  add    %r12,%rbp
L365:
  add    %r12,%r15
  cmp    %rbx,%r15
  jb     L180
L17:
  mov    %r13,%rsi
  mov    %r15,%rdi
  call   *%r14
  test   %eax,%eax
  js     L45
  jne    L365
  mov    (%rsp),%edx
  test   %edx,%edx
  je     L302
  mov    (%rsp),%ecx
  mov    0x8(%rsp),%rdx
  mov    %rbp,%rsi
  mov    %r15,%rdi
  call   <swapfunc@plt>
  jmp    L237
L45:
  mov    (%rsp),%eax
  test   %eax,%eax
  jne    L225
  mov    (%rbx),%rax
  mov    (%r15),%rdx
  mov    %rdx,(%rbx)
  mov    %rax,(%r15)
L245:
  mov    0x8(%rsp),%rax
  add    %r12,%r15
  add    %rbx,%rax
  mov    %rax,0x10(%rsp)
L190:
  mov    %rax,%rbx
  cmp    %rax,%r15
  jae    L367
  mov    0x20(%rsp),%rdx
  mov    %rbp,%r12
  sub    0x18(%rsp),%rax
  sub    %r15,%r12
  sub    %rbp,%rdx
  sub    0x8(%rsp),%rdx
  mov    %rax,%rbp
  cmp    %r12,%rdx
  cmova  %r12,%rdx
  mov    %rdx,%rbx
L188:
  mov    0x18(%rsp),%rdx
  sub    %r13,%rdx
  cmp    %rax,%rdx
  cmovg  %rax,%rdx
  test   %rdx,%rdx
  jne    L173
L24:
  test   %rbx,%rbx
  je     L48
  mov    0x20(%rsp),%rsi
  mov    (%rsp),%ecx
  mov    %rbx,%rdx
  mov    0x10(%rsp),%rdi
  sub    %rbx,%rsi
  call   <swapfunc@plt>
L48:
  cmp    %rbp,0x8(%rsp)
  jae    L469
  cmp    0x28(%rsp),%r13
  jbe    L478
  cmp    0x30(%rsp),%r13
  jbe    L478
L469:
  mov    0x8(%rsp),%rdi
  cmp    %r12,%rdi
  jae    L189
  mov    %r12,%rax
  xor    %edx,%edx
  mov    0x20(%rsp),%rcx
  div    %rdi
  mov    %rcx,%r13
  sub    %r12,%r13
  mov    %rax,%rbx
  mov    %rcx,%rax
  sub    $0x1,%rax
  cmp    %r13,0x28(%rsp)
  jae    L388
  cmp    %r13,0x30(%rsp)
  jb     L189
L388:
  cmp    %rax,0x28(%rsp)
  jbe    L41
  cmp    %rax,0x30(%rsp)
  jbe    L41
L189:
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L225:
  mov    (%rsp),%ecx
  mov    0x8(%rsp),%rdx
  mov    %r15,%rsi
  mov    %rbx,%rdi
  call   <swapfunc@plt>
  jmp    L245
L234:
  jne    L92
  mov    (%rsp),%ecx
  test   %ecx,%ecx
  jne    L345
  mov    0x18(%rsp),%rcx
  mov    (%rbx),%rdx
  mov    (%rcx),%rax
  mov    %rdx,(%rcx)
  mov    %rax,(%rbx)
L178:
  mov    0x8(%rsp),%rcx
  add    %rcx,0x18(%rsp)
L92:
  mov    0x8(%rsp),%rax
  add    %rbx,%rax
  mov    %rax,0x10(%rsp)
  jmp    L190
L102:
  cmpq   $0x0,0x38(%rsp)
  je     L189
  mov    0x18(%rsp),%rax
  mov    0x38(%rsp),%rdx
  xor    %ebp,%ebp
  xor    %ebx,%ebx
  xor    %r12d,%r12d
  mov    %rax,0x10(%rsp)
  nopl   0x0(%rax)
L173:
  mov    0x10(%rsp),%rsi
  mov    (%rsp),%ecx
  mov    %r13,%rdi
  sub    %rdx,%rsi
  call   <swapfunc@plt>
  jmp    L24
L345:
  mov    (%rsp),%ecx
  mov    0x8(%rsp),%rdx
  mov    %rbx,%rsi
  mov    0x18(%rsp),%rdi
  call   <swapfunc@plt>
  jmp    L178
L20:
  mov    (%rsp),%ecx
  mov    0x8(%rsp),%rdx
  mov    %rbp,%rsi
  mov    %r13,%rdi
  call   <swapfunc@plt>
  jmp    L448
L54:
  xor    %eax,%eax
  cmpq   $0x8,0x8(%rsp)
  setne  %al
  mov    %eax,(%rsp)
  cmp    $0x6,%rbx
  ja     L422
L246:
  mov    0x8(%rsp),%rax
  imul   %rax,%rbx
  lea    0x0(%r13,%rax,1),%rcx
  neg    %rax
  mov    %rcx,0x10(%rsp)
  lea    0x0(%r13,%rbx,1),%r15
  mov    %rax,%rbx
  cmp    %rcx,%r15
  jbe    L189
  mov    (%rsp),%r12d
  mov    0x8(%rsp),%rbp
  mov    %r15,0x18(%rsp)
  mov    %r13,(%rsp)
L437:
  mov    0x10(%rsp),%rax
  cmp    %rax,(%rsp)
  jae    L287
  mov    %rax,%r15
  jmp    L128
L40:
  mov    0x0(%r13),%rax
  mov    0x0(%r13,%rbx,1),%rdx
  mov    %rdx,0x0(%r13)
  mov    %rax,0x0(%r13,%rbx,1)
  cmp    %r15,(%rsp)
  jae    L287
L128:
  mov    %r15,%r13
  sub    %rbp,%r15
  mov    %r13,%rsi
  mov    %r15,%rdi
  call   *%r14
  test   %eax,%eax
  jle    L287
  test   %r12d,%r12d
  je     L40
  mov    %r12d,%ecx
  mov    %rbp,%rdx
  mov    %r15,%rsi
  mov    %r13,%rdi
  call   <swapfunc@plt>
  cmp    %r15,(%rsp)
  jb     L128
L287:
  add    %rbp,0x10(%rsp)
  mov    0x10(%rsp),%rax
  cmp    %rax,0x18(%rsp)
  ja     L437
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L478:
  lea    -0x1(%r13,%rbp,1),%rax
  cmp    0x28(%rsp),%rax
  jae    L60
  cmp    0x30(%rsp),%rax
  jb     L469
L60:
  mov    0x8(%rsp),%rdi
  mov    %rbp,%rax
  xor    %edx,%edx
  mov    0x30(%rsp),%r9
  mov    0x28(%rsp),%r8
  mov    %r14,%rcx
  div    %rdi
  mov    %rdi,%rdx
  mov    %r13,%rdi
  mov    %rax,%rsi
  call   <_pqsort>
  jmp    L469
L143:
  mov    %rbx,%r9
  mov    %r14,%rcx
  mov    %r13,%rdi
  shr    $0x3,%r9
  imul   %rax,%r9
  lea    0x0(%r13,%r9,2),%rdx
  lea    0x0(%r13,%r9,1),%rsi
  mov    %r9,0x10(%rsp)
  call   <med3@plt>
  mov    0x10(%rsp),%r9
  mov    %rbp,%rdi
  mov    %rbp,%rsi
  mov    %r14,%rcx
  mov    %rax,%r12
  mov    %r9,%r10
  lea    0x0(%rbp,%r9,1),%rdx
  sub    %r9,%rdi
  neg    %r10
  mov    %r10,0x10(%rsp)
  call   <med3@plt>
  mov    0x10(%rsp),%r10
  mov    %r15,%rdx
  mov    %r14,%rcx
  mov    %rax,%rbp
  lea    (%r15,%r10,1),%rsi
  lea    (%rsi,%r10,1),%rdi
  call   <med3@plt>
  mov    %rax,%rdx
  jmp    L428
L180:
  mov    %rbx,%rax
L468:
  mov    0x20(%rsp),%rdx
  mov    %rbp,%r12
  sub    0x18(%rsp),%rax
  sub    %r15,%r12
  sub    %rbp,%rdx
  sub    0x8(%rsp),%rdx
  mov    %rax,%rbp
  cmp    %r12,%rdx
  mov    %rdx,%rbx
  cmova  %r12,%rbx
  jmp    L188
L244:
  mov    0x10(%rsp),%rax
  jmp    L468
```

assistant: ```c
void _pqsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *), void *lrange, void *rrange) {
  char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
  size_t d, r;
  int swaptype, cmp_result;
loop:
  swaptype = ((char *)a - (char *)0) % sizeof(long) || es % sizeof(long) ? 2 : es == sizeof(long) ? 0 : 1;
  ;
  if (n < 7) {
    for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
      for (pl = pm; pl > (char *)a && cmp(pl - es, pl) > 0; pl -= es)
        if (swaptype == 0) {
          long t = *(long *)(void *)(pl);
          *(long *)(void *)(pl) = *(long *)(void *)(pl - es);
          *(long *)(void *)(pl - es) = t;
        } else
          swapfunc(pl, pl - es, es, swaptype);
    return;
  }
  pm = (char *)a + (n / 2) * es;
  if (n > 7) {
    pl = (char *)a;
    pn = (char *)a + (n - 1) * es;
    if (n > 40) {
      d = (n / 8) * es;
      pl = med3(pl, pl + d, pl + 2 * d, cmp);
      pm = med3(pm - d, pm, pm + d, cmp);
      pn = med3(pn - 2 * d, pn - d, pn, cmp);
    }
    pm = med3(pl, pm, pn, cmp);
  }
  if (swaptype == 0) {
    long t = *(long *)(void *)(a);
    *(long *)(void *)(a) = *(long *)(void *)(pm);
    *(long *)(void *)(pm) = t;
  } else
    swapfunc(a, pm, es, swaptype);
  pa = pb = (char *)a + es;
  pc = pd = (char *)a + (n - 1) * es;
  for (;;) {
    while (pb <= pc && (cmp_result = cmp(pb, a)) <= 0) {
      if (cmp_result == 0) {
        if (swaptype == 0) {
          long t = *(long *)(void *)(pa);
          *(long *)(void *)(pa) = *(long *)(void *)(pb);
          *(long *)(void *)(pb) = t;
        } else
          swapfunc(pa, pb, es, swaptype);
        pa += es;
      }
      pb += es;
    }
    while (pb <= pc && (cmp_result = cmp(pc, a)) >= 0) {
      if (cmp_result == 0) {
        if (swaptype == 0) {
          long t = *(long *)(void *)(pc);
          *(long *)(void *)(pc) = *(long *)(void *)(pd);
          *(long *)(void *)(pd) = t;
        } else
          swapfunc(pc, pd, es, swaptype);
        pd -= es;
      }
      pc -= es;
    }
    if (pb > pc)
      break;
    if (swaptype == 0) {
      long t = *(long *)(void *)(pb);
      *(long *)(void *)(pb) = *(long *)(void *)(pc);
      *(long *)(void *)(pc) = t;
    } else
      swapfunc(pb, pc, es, swaptype);
    pb += es;
    pc -= es;
  }
  pn = (char *)a + n * es;
  r = (pa - (char *)a) < (pb - pa) ? pa - (char *)a : pb - pa;
  if ((r) > 0)
    swapfunc((a), (pb - r), (size_t)(r), swaptype);
  r = ((size_t)(pd - pc)) < (pn - pd - es) ? (size_t)(pd - pc) : pn - pd - es;
  if ((r) > 0)
    swapfunc((pb), (pn - r), (size_t)(r), swaptype);
  if ((r = pb - pa) > es) {
    void *_l = a, *_r = ((unsigned char *)a) + r - 1;
    if (!((lrange < _l && rrange < _l) || (lrange > _r && rrange > _r)))
      _pqsort(a, r / es, es, cmp, lrange, rrange);
  }
  if ((r = pd - pc) > es) {
    void *_l, *_r;
    a = pn - r;
    n = r / es;
    _l = a;
    _r = ((unsigned char *)a) + r - 1;
    if (!((lrange < _l && rrange < _l) || (lrange > _r && rrange > _r)))
      goto loop;
  }
}
```