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

```asm
<DMedSelect>:
  endbr64
  push   %rbp
  push   %rbx
  mov    %edi,%r11d
  mov    %esi,%ebx
  mov    %rdx,%r8
  cmp    $0x2,%esi
  jle    L62
  mov    $0x1,%ebp
  mov    $0x2,%eax
  jmp    L94
L36:
  mov    %r9d,%ebp
L121:
  lea    0x1(%rbp),%eax
  cmp    %ebx,%eax
  jge    L4
L94:
  lea    (%rbx,%rbp,1),%edx
  sar    %edx
  movslq %edx,%rdx
  lea    (%r8,%rdx,8),%rcx
  movsd  (%rcx),%xmm0
  movslq %ebp,%rdx
  lea    0x8(,%rdx,8),%rdx
  lea    (%r8,%rdx,1),%r10
  movsd  (%r10),%xmm1
  movsd  %xmm1,(%rcx)
  movsd  %xmm0,(%r10)
  lea    -0x8(%r8,%rdx,1),%rdx
  movsd  (%rdx),%xmm0
  movslq %ebx,%rcx
  lea    (%r8,%rcx,8),%rcx
  movsd  (%rcx),%xmm1
  comisd %xmm1,%xmm0
  jbe    L67
  movsd  %xmm1,(%rdx)
  movsd  %xmm0,(%rcx)
L67:
  movsd  (%r10),%xmm0
  movsd  (%rcx),%xmm1
  comisd %xmm1,%xmm0
  jbe    L1
  movsd  %xmm1,(%r10)
  movsd  %xmm0,(%rcx)
L1:
  movsd  (%rdx),%xmm0
  movsd  (%r10),%xmm1
  comisd %xmm1,%xmm0
  jbe    L35
  movsd  %xmm1,(%rdx)
  movsd  %xmm0,(%r10)
L35:
  movsd  (%r10),%xmm1
  add    $0x1,%eax
  movslq %eax,%rsi
  mov    %ebx,%edx
  jmp    L21
L62:
  mov    $0x1,%ebp
  mov    $0x2,%eax
L4:
  cmp    %ebx,%eax
  je     L31
L55:
  movslq %r11d,%r11
  movsd  (%r8,%r11,8),%xmm0
  pop    %rbx
  pop    %rbp
  ret
L31:
  movslq %ebx,%rbx
  lea    (%r8,%rbx,8),%rax
  movsd  (%rax),%xmm1
  movslq %ebp,%rbp
  lea    (%r8,%rbp,8),%rdx
  movsd  (%rdx),%xmm0
  comisd %xmm1,%xmm0
  jbe    L55
  movsd  %xmm1,(%rdx)
  movsd  %xmm0,(%rax)
  jmp    L55
L74:
  add    $0x1,%rsi
L21:
  mov    %esi,%r9d
  movsd  (%r8,%rsi,8),%xmm2
  comisd %xmm2,%xmm1
  ja     L74
  movslq %edx,%rax
  lea    -0x8(%r8,%rax,8),%rax
L86:
  mov    %edx,%edi
  sub    $0x1,%edx
  mov    %rax,%rcx
  sub    $0x8,%rax
  movsd  0x8(%rax),%xmm0
  comisd %xmm1,%xmm0
  ja     L86
  cmp    %esi,%edx
  jl     L14
  movsd  %xmm0,(%r8,%rsi,8)
  movsd  %xmm2,(%rcx)
  jmp    L74
L14:
  movsd  %xmm0,(%r10)
  movsd  %xmm1,(%rcx)
  cmp    %r11d,%edx
  jl     L36
  lea    -0x2(%rdi),%ebx
  cmove  %r9d,%ebp
  jmp    L121
```

assistant: ```c
double DMedSelect(int k, int n, double arr[]) {
  double a, temp;
  int i, ir, j, mid, l;
  l = 1;
  ir = n;
  for (;;) {
    if (ir <= l + 1) {
      if (ir == l + 1 && arr[ir] < arr[l]) {
        temp = (arr[l]);
        (arr[l]) = (arr[ir]);
        (arr[ir]) = temp;
      }
      return arr[k];
    } else {
      mid = (l + ir) >> 1;
      temp = (arr[mid]);
      (arr[mid]) = (arr[l + 1]);
      (arr[l + 1]) = temp;
      if (arr[l] > arr[ir]) {
        temp = (arr[l]);
        (arr[l]) = (arr[ir]);
        (arr[ir]) = temp;
      }
      if (arr[l + 1] > arr[ir]) {
        temp = (arr[l + 1]);
        (arr[l + 1]) = (arr[ir]);
        (arr[ir]) = temp;
      }
      if (arr[l] > arr[l + 1]) {
        temp = (arr[l]);
        (arr[l]) = (arr[l + 1]);
        (arr[l + 1]) = temp;
      }
      i = l + 1;
      j = ir;
      a = arr[l + 1];
      for (;;) {
        do
          i++;
        while (arr[i] < a);
        do
          j--;
        while (arr[j] > a);
        if (j < i)
          break;
        temp = (arr[i]);
        (arr[i]) = (arr[j]);
        (arr[j]) = temp;
      }
      arr[l + 1] = arr[j];
      arr[j] = a;
      if (j >= k)
        ir = j - 1;
      if (j <= k)
        l = i;
    }
  }
}
```