user: What would the C source look like for the assembly code provided here?

```asm
<heapsort>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,0x40(%rsp)
  mov    %rsi,0x28(%rsp)
  mov    %rcx,0x18(%rsp)
  mov    $0x0,%eax
  cmp    $0x1,%rsi
  jbe    L133
  mov    %rdx,%r15
  test   %rdx,%rdx
  je     L110
  mov    %rdx,%rdi
  call   <malloc@plt>
  mov    %rax,0x48(%rsp)
  test   %rax,%rax
  je     L220
  mov    0x40(%rsp),%rax
  sub    %r15,%rax
  mov    %rax,(%rsp)
  mov    0x28(%rsp),%r13
  mov    %r13,%rax
  shr    %rax
  mov    %rax,0x8(%rsp)
  mov    0x18(%rsp),%r14
  jmp    L225
L110:
  mov    D2(%rip),%rax
  mov    (%rax),%edx
  mov    D17(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L133
L194:
  mov    0x10(%rsp),%rbp
  imul   %r15,%rbp
  add    (%rsp),%rbp
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   *%r14
  test   %eax,%eax
  jle    L241
  lea    (%rbx,%r15,1),%rcx
L119:
  movzbl 0x0(%rbp),%eax
  add    $0x1,%rbp
  movzbl (%rbx),%edx
  mov    %dl,-0x1(%rbp)
  add    $0x1,%rbx
  mov    %al,-0x1(%rbx)
  cmp    %rbx,%rcx
  jne    L119
  lea    (%r12,%r12,1),%rbp
  cmp    %rbp,%r13
  jb     L241
  mov    %r12,0x10(%rsp)
L92:
  mov    %r15,%rbx
  imul   %rbp,%rbx
  add    (%rsp),%rbx
  mov    %rbp,%r12
  cmp    %rbp,%r13
  jbe    L194
  lea    (%rbx,%r15,1),%rax
  mov    %rax,0x20(%rsp)
  mov    %rax,%rsi
  mov    %rbx,%rdi
  call   *%r14
  test   %eax,%eax
  jns    L194
  lea    0x1(%rbp),%r12
  mov    0x20(%rsp),%rbx
  jmp    L194
L241:
  subq   $0x1,0x8(%rsp)
  je     L68
L225:
  mov    0x8(%rsp),%rax
  lea    (%rax,%rax,1),%rbp
  mov    %rax,0x10(%rsp)
  cmp    %r13,%rbp
  jbe    L92
  jmp    L241
L68:
  mov    0x28(%rsp),%rax
  imul   %r15,%rax
  add    (%rsp),%rax
  mov    %rax,0x20(%rsp)
  mov    0x48(%rsp),%r14
  mov    %r15,0x30(%rsp)
  jmp    L18
L314:
  imul   %r13,%r15
  add    (%rsp),%r15
  mov    0x8(%rsp),%rax
L5:
  movzbl 0x0(%rbp,%rax,1),%edx
  mov    %dl,(%r15,%rax,1)
  mov    %rax,%rdx
  add    $0x1,%rax
  cmp    %rdx,%rbx
  jne    L5
  lea    (%rsi,%rsi,1),%r12
  cmp    %r12,%r14
  jb     L26
  mov    %rsi,%r15
L158:
  mov    %r13,%rbp
  imul   %r12,%rbp
  add    (%rsp),%rbp
  mov    %r12,%rsi
  cmp    %r12,%r14
  jbe    L314
  lea    0x0(%rbp,%r13,1),%rax
  mov    %rax,0x10(%rsp)
  mov    %rax,%rsi
  mov    %rbp,%rdi
  mov    0x18(%rsp),%rcx
  call   *%rcx
  mov    %r12,%rsi
  test   %eax,%eax
  jns    L314
  lea    0x1(%r12),%rsi
  mov    0x10(%rsp),%rbp
  jmp    L314
L26:
  mov    0x38(%rsp),%r14
  mov    %rsi,%r15
  shr    %r15
  mov    %rsi,%rbp
  imul   %r13,%rbp
  mov    (%rsp),%rax
  add    %rax,%rbp
  mov    %r13,%r12
  imul   %r15,%r12
  add    %rax,%r12
  cmp    $0x1,%rsi
  je     L51
L171:
  mov    %r12,%rsi
  mov    %r14,%rdi
  mov    0x18(%rsp),%rax
  call   *%rax
  test   %eax,%eax
  js     L51
  mov    0x8(%rsp),%rax
L16:
  movzbl (%r12,%rax,1),%edx
  mov    %dl,0x0(%rbp,%rax,1)
  mov    %rax,%rdx
  add    $0x1,%rax
  cmp    %rdx,%rbx
  jne    L16
  mov    %r15,%rax
  shr    %rax
  mov    %r13,%rbp
  imul   %r15,%rbp
  mov    (%rsp),%rdi
  add    %rdi,%rbp
  mov    %r13,%r12
  imul   %rax,%r12
  add    %rdi,%r12
  cmp    $0x1,%r15
  je     L51
  mov    %rax,%r15
  jmp    L171
L251:
  mov    0x40(%rsp),%rbp
L51:
  mov    0x8(%rsp),%rax
L141:
  movzbl (%r14,%rax,1),%edx
  mov    %dl,0x0(%rbp,%rax,1)
  mov    %rax,%rdx
  add    $0x1,%rax
  cmp    %rdx,%rbx
  jne    L141
  sub    %r13,0x20(%rsp)
  cmpq   $0x1,0x28(%rsp)
  je     L113
L18:
  mov    0x20(%rsp),%rdx
  mov    0x8(%rsp),%rax
  mov    0x30(%rsp),%rsi
L196:
  movzbl (%rdx,%rax,1),%ecx
  mov    %cl,(%r14,%rax,1)
  add    $0x1,%rax
  cmp    %rsi,%rax
  jne    L196
  mov    0x8(%rsp),%r13
  mov    0x40(%rsp),%rcx
  mov    0x30(%rsp),%rsi
L159:
  movzbl (%rcx,%r13,1),%eax
  mov    %al,(%rdx,%r13,1)
  mov    %r13,%rbx
  add    $0x1,%r13
  cmp    %r13,%rsi
  jne    L159
  subq   $0x1,0x28(%rsp)
  mov    0x28(%rsp),%rax
  cmp    $0x1,%rax
  jbe    L251
  mov    $0x2,%r12d
  mov    $0x1,%r15d
  mov    %r14,0x38(%rsp)
  mov    %rax,%r14
  jmp    L158
L113:
  mov    0x48(%rsp),%rdi
  call   <free@plt>
  mov    $0x0,%eax
L133:
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L220:
  mov    $0xffffffff,%eax
  jmp    L133
```

assistant: ```c
int heapsort(void *vbase, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) {
  size_t cnt, i, j, l;
  char tmp, *tmp1, *tmp2;
  char *base, *k, *p, *t;
  if (nmemb <= 1)
    return (0);
  if (!size) {
    errno = EINVAL;
    return (-1);
  }
  if ((k = malloc(size)) == NULL)
    return (-1);
  base = (char *)vbase - size;
  for (l = nmemb / 2 + 1; --l;) {
    for (i = l; (j = i * 2) <= nmemb; i = j) {
      p = base + j * size;
      if (j < nmemb && compar(p, p + size) < 0) {
        p += size;
        ++j;
      }
      t = base + i * size;
      if (compar(p, t) <= 0)
        break;
      {
        cnt = size;
        do {
          tmp = *t;
          *t++ = *p;
          *p++ = tmp;
        } while (--cnt);
      };
    }
  };
  while (nmemb > 1) {
    {
      cnt = size;
      tmp1 = k;
      tmp2 = base + nmemb * size;
      do {
        *tmp1++ = *tmp2++;
      } while (--cnt);
    };
    {
      cnt = size;
      tmp1 = base + nmemb * size;
      tmp2 = base + size;
      do {
        *tmp1++ = *tmp2++;
      } while (--cnt);
    };
    --nmemb;
    {
      for (i = 1; (j = i * 2) <= nmemb; i = j) {
        p = base + j * size;
        if (j < nmemb && compar(p, p + size) < 0) {
          p += size;
          ++j;
        }
        t = base + i * size;
        {
          cnt = size;
          tmp1 = t;
          tmp2 = p;
          do {
            *tmp1++ = *tmp2++;
          } while (--cnt);
        };
      }
      for (;;) {
        j = i;
        i = j / 2;
        p = base + j * size;
        t = base + i * size;
        if (j == 1 || compar(k, t) < 0) {
          {
            cnt = size;
            tmp1 = p;
            tmp2 = k;
            do {
              *tmp1++ = *tmp2++;
            } while (--cnt);
          };
          break;
        }
        {
          cnt = size;
          tmp1 = p;
          tmp2 = t;
          do {
            *tmp1++ = *tmp2++;
          } while (--cnt);
        };
      }
    };
  }
  free(k);
  return (0);
}
```