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

```asm
<qsort>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %rdx,%r15
  push   %r14
  push   %r13
  mov    %rcx,%r13
  push   %r12
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  lea    0x17(%rdx),%rax
  mov    %rax,%rcx
  and    $0xff0,%eax
  mov    %rax,-0x68(%rbp)
  and    $0xfffffffffffff000,%rcx
  sub    $0x8,%rax
  mov    %rcx,-0x60(%rbp)
  mov    %rax,-0x70(%rbp)
  cmp    $0x3,%rsi
  jbe    L105
L207:
  xor    %eax,%eax
  call   <rand@plt>
  mov    %rsp,%rdx
  sub    -0x60(%rbp),%rdx
  cmp    %rdx,%rsp
  je     L228
L53:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rdx,%rsp
  jne    L53
L228:
  mov    -0x68(%rbp),%rcx
  sub    %rcx,%rsp
  test   %rcx,%rcx
  je     L239
  mov    -0x70(%rbp),%rcx
  orq    $0x0,(%rsp,%rcx,1)
L239:
  mov    -0x50(%rbp),%rdi
  mov    -0x48(%rbp),%r12
  lea    0xf(%rsp),%r14
  and    $0xfffffffffffffff0,%r14
  lea    -0x1(%rdi),%rdx
  imul   %r15,%rdx
  add    %r12,%rdx
  mov    %rdx,-0x58(%rbp)
  mov    %rdx,%rbx
  xor    %edx,%edx
  div    %rdi
  mov    %r14,%rdi
  imul   %r15,%rdx
  lea    (%r12,%rdx,1),%rsi
  mov    %r15,%rdx
  call   <memcpy@plt>
L65:
  cmp    %rbx,%r12
  jbe    L96
  jmp    L142
  xchg   %ax,%ax
L11:
  add    %r15,%r12
L96:
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   *%r13
  test   %eax,%eax
  js     L11
  mov    %rbx,%rsi
  mov    %r14,%rdi
  call   *%r13
  test   %eax,%eax
  jns    L26
  nopl   (%rax)
L41:
  sub    %r15,%rbx
  mov    %r14,%rdi
  mov    %rbx,%rsi
  call   *%r13
  test   %eax,%eax
  js     L41
L26:
  cmp    %rbx,%r12
  jbe    L82
L142:
  cmp    %rbx,-0x48(%rbp)
  jb     L153
L231:
  cmp    -0x58(%rbp),%r12
  jae    L199
  mov    %r12,%rax
  xor    %edx,%edx
  sub    -0x48(%rbp),%rax
  div    %r15
  sub    %rax,-0x50(%rbp)
  mov    -0x50(%rbp),%rcx
  cmp    $0x3,%rcx
  jbe    L101
  mov    %r12,-0x48(%rbp)
  jmp    L207
L82:
  mov    %rbx,%rsi
  mov    %r12,%rdi
  mov    %r15,%rdx
  add    %r15,%r12
  call   <swap@plt>
  sub    %r15,%rbx
  jmp    L65
L105:
  mov    %rdi,%r12
L101:
  cmpq   $0x2,-0x50(%rbp)
  lea    (%r12,%r15,1),%r14
  je     L76
  cmpq   $0x3,-0x50(%rbp)
  je     L229
L199:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L185
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L153:
  mov    -0x48(%rbp),%rdi
  mov    %rbx,%rax
  xor    %edx,%edx
  mov    %r13,%rcx
  sub    %rdi,%rax
  div    %r15
  mov    %r15,%rdx
  lea    0x1(%rax),%rsi
  call   <qsort>
  jmp    L231
L229:
  lea    (%r12,%r15,1),%r14
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   *%r13
  test   %eax,%eax
  js     L33
L130:
  lea    (%r12,%r15,2),%rbx
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   *%r13
  test   %eax,%eax
  jns    L199
  mov    %r15,%rdx
  mov    %rbx,%rsi
  mov    %r14,%rdi
  call   <swap@plt>
L76:
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   *%r13
  test   %eax,%eax
  jns    L199
  mov    %r15,%rdx
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <swap@plt>
  jmp    L199
L33:
  mov    %r15,%rdx
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <swap@plt>
  jmp    L130
L185:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) {
  if (nmemb < 4) {
    if (nmemb == 2) {
      if (compar(base + size, base) < 0) {
        swap(base, base + size, size);
      }
    } else if (nmemb == 3) {
      if (compar(base + size, base) < 0) {
        swap(base, base + size, size);
      }
      if (compar(base + (size << 1), base + size) < 0) {
        swap(base + size, base + (size << 1), size);
        if (compar(base + size, base) < 0) {
          swap(base, base + size, size);
        }
      }
    }
    return;
  } else {
    void *pos = (rand() % nmemb) * size + base;
    void *key = alloca(size);
    void *i = base, *j = base + (size * (nmemb - 1));
    memcpy(key, pos, size);
    while (i <= j) {
      while (compar(i, key) < 0) {
        i += size;
      }
      while (compar(key, j) < 0) {
        j -= size;
      }
      if (i <= j) {
        swap(i, j, size);
        i += size;
        j -= size;
      }
    }
    if (j > base) {
      qsort(base, (j - base) / size + 1, size, compar);
    }
    if (i < base + (nmemb - 1) * size) {
      qsort(i, nmemb - (i - base) / size, size, compar);
    }
  }
}
```