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

```asm
<heapsort2_d>:
  endbr64
  mov    %edi,%r8d
  push   %r14
  mov    %rsi,%rcx
  mov    %rdx,%rdi
  mov    %r8d,%r11d
  push   %r13
  shr    $0x1f,%r11d
  push   %r12
  add    %r8d,%r11d
  push   %rbp
  sar    %r11d
  push   %rbx
  sub    $0x1,%r11d
  js     L72
  movslq %r11d,%rbx
  lea    0x1(%r11,%r11,1),%ebp
  lea    -0x1(%r8),%r10d
  shl    $0x3,%rbx
  lea    (%rsi,%rbx,1),%r12
  add    %rdx,%rbx
  nopl   0x0(%rax,%rax,1)
L7:
  movsd  (%r12),%xmm2
  movsd  (%rbx),%xmm3
  mov    %r12,%r14
  mov    %rbx,%rdx
  mov    %ebp,%r13d
  cmp    %ebp,%r8d
  jle    L20
  movslq %r11d,%rdx
  jmp    L5
  nopl   (%rax)
L184:
  add    %rdi,%rax
  movsd  %xmm0,(%r14)
  lea    0x1(%rsi,%rsi,1),%r13d
  movsd  (%rax),%xmm0
  movsd  %xmm0,(%rdx)
  cmp    %r13d,%r8d
  jle    L164
  movslq %esi,%rdx
L5:
  movslq %r13d,%rax
  mov    %r13d,%esi
  shl    $0x3,%rax
  lea    (%rcx,%rax,1),%r9
  movsd  (%r9),%xmm0
  cmp    %r10d,%r13d
  jge    L11
  lea    0x8(%rax),%r13
  lea    (%rcx,%r13,1),%r14
  movsd  (%r14),%xmm1
  comisd %xmm0,%xmm1
  jbe    L11
  add    $0x1,%esi
  movapd %xmm1,%xmm0
  mov    %r14,%r9
  mov    %r13,%rax
L11:
  shl    $0x3,%rdx
  lea    (%rcx,%rdx,1),%r14
  add    %rdi,%rdx
  comisd %xmm0,%xmm2
  jb     L184
L20:
  sub    $0x1,%r11d
  movsd  %xmm2,(%r14)
  sub    $0x8,%r12
  sub    $0x2,%ebp
  movsd  %xmm3,(%rdx)
  sub    $0x8,%rbx
  cmp    $0xffffffff,%r11d
  jne    L7
L72:
  test   %r8d,%r8d
  jle    L156
  lea    -0x1(%r8),%r10d
  sub    $0x2,%r8d
  movslq %r10d,%r10
  nopl   0x0(%rax,%rax,1)
L131:
  movsd  (%rcx),%xmm0
  movsd  (%rcx,%r10,8),%xmm2
  mov    %r10d,%r11d
  movsd  %xmm0,(%rcx,%r10,8)
  movsd  (%rdi),%xmm0
  movsd  (%rdi,%r10,8),%xmm3
  movsd  %xmm0,(%rdi,%r10,8)
  cmp    $0x1,%r10d
  jle    L120
  mov    $0x1,%esi
  xor    %eax,%eax
  jmp    L183
  cs nopw 0x0(%rax,%rax,1)
L21:
  add    %rdi,%rdx
  movsd  %xmm0,(%rsi)
  lea    0x1(%r9,%r9,1),%esi
  movsd  (%rdx),%xmm0
  movsd  %xmm0,(%rax)
  cmp    %r11d,%esi
  jge    L56
  movslq %r9d,%rax
L183:
  movslq %esi,%rdx
  mov    %esi,%r9d
  shl    $0x3,%rdx
  lea    (%rcx,%rdx,1),%rbx
  movsd  (%rbx),%xmm0
  cmp    %r8d,%esi
  jge    L46
  lea    0x8(%rdx),%rsi
  lea    (%rcx,%rsi,1),%rbp
  movsd  0x0(%rbp),%xmm1
  comisd %xmm0,%xmm1
  jbe    L46
  add    $0x1,%r9d
  movapd %xmm1,%xmm0
  mov    %rbp,%rbx
  mov    %rsi,%rdx
L46:
  shl    $0x3,%rax
  lea    (%rcx,%rax,1),%rsi
  add    %rdi,%rax
  comisd %xmm0,%xmm2
  jb     L21
L4:
  movsd  %xmm2,(%rsi)
  movsd  %xmm3,(%rax)
L50:
  sub    $0x1,%r10
  sub    $0x1,%r8d
  jmp    L131
  nopw   0x0(%rax,%rax,1)
L164:
  mov    %rax,%rdx
  mov    %r9,%r14
  jmp    L20
  nopl   0x0(%rax,%rax,1)
L56:
  mov    %rdx,%rax
  mov    %rbx,%rsi
  jmp    L4
L120:
  movsd  %xmm2,(%rcx)
  movsd  %xmm3,(%rdi)
  je     L50
L156:
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
```

assistant: ```c
void heapsort2_d(int n, double key[], double val[]) {
  int i, j, k;
  double key0;
  double val0;
  for (k = n / 2 - 1; k >= 0; k--) {
    i = k;
    key0 = key[i];
    val0 = val[i];
    j = 2 * i + 1;
    while (j <= n - 1) {
      if (j < n - 1 && key[j] < key[j + 1])
        j++;
      if (key0 >= key[j])
        break;
      key[i] = key[j];
      val[i] = val[j];
      i = j;
      j = 2 * i + 1;
    }
    key[i] = key0;
    val[i] = val0;
  }
  while (n > 0) {
    key0 = key[n - 1];
    key[n - 1] = key[0];
    val0 = val[n - 1];
    val[n - 1] = val[0];
    n--;
    i = 0;
    j = 2 * i + 1;
    while (j <= n - 1) {
      if (j < n - 1 && key[j] < key[j + 1])
        j++;
      if (key0 >= key[j])
        break;
      key[i] = key[j];
      val[i] = val[j];
      i = j;
      j = 2 * i + 1;
    }
    key[i] = key0;
    val[i] = val0;
  }
}
```