user: What is the c source code of the assembly code below?

```asm
<ksmall_dbl>:
  endbr64
  push   %r13
  mov    %rdi,%r13
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  mov    %rdx,%rbp
  push   %rbx
  mov    %rcx,%rbx
  sub    $0x8,%rsp
  test   %rcx,%rcx
  setne  %al
  cmp    %rdx,%rsi
  seta   %dl
  and    %edx,%eax
  test   %rdi,%rdi
  setne  %dil
  movzbl %dil,%edi
  and    %eax,%edi
  call   <assert@plt>
  cmp    $0x2,%r12
  ja     L11
  movsd  0x0(%r13),%xmm0
  je     L3
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L11:
  cmp    %rbx,%r13
  je     L7
  lea    0x0(,%r12,8),%rdx
  mov    %r13,%rsi
  mov    %rbx,%rdi
  call   <memcpy@plt>
L7:
  lea    -0x1(%r12),%r10
  xor    %r11d,%r11d
  nopw   0x0(%rax,%rax,1)
L43:
  lea    (%r11,%r10,1),%rax
  lea    (%rbx,%r10,8),%rdx
  shr    %rax
  movsd  (%rdx),%xmm0
  movsd  (%rbx,%rax,8),%xmm2
  lea    (%rbx,%r11,8),%rax
  movsd  (%rax),%xmm1
  comisd %xmm0,%xmm1
  jbe    L118
  movsd  %xmm0,(%rax)
  movapd %xmm1,%xmm0
  movsd  %xmm1,(%rdx)
  movsd  (%rax),%xmm1
L118:
  comisd %xmm2,%xmm1
  ja     L139
  movapd %xmm0,%xmm1
  minsd  %xmm2,%xmm1
L139:
  mov    %r10,%rcx
  mov    %r11,%r9
  cs nopw 0x0(%rax,%rax,1)
L4:
  lea    0x1(%r9),%r8
  movsd  (%rbx,%r8,8),%xmm2
  comisd %xmm2,%xmm1
  ja     L66
  lea    -0x1(%rcx),%rdx
  lea    (%rbx,%rdx,8),%rax
  jmp    L102
  nopw   0x0(%rax,%rax,1)
L49:
  sub    $0x1,%rdx
L102:
  mov    %rax,%rsi
  movsd  (%rax),%xmm0
  sub    $0x8,%rax
  mov    %rcx,%rdi
  mov    %rdx,%rcx
  comisd %xmm1,%xmm0
  ja     L49
  cmp    %rdx,%r8
  jae    L131
  movsd  %xmm0,(%rbx,%r8,8)
  movsd  %xmm2,(%rsi)
L66:
  mov    %r8,%r9
  jmp    L4
  nop
L131:
  cmp    %r8,%rbp
  jae    L17
  cmp    %r11,%r9
  jbe    L21
  mov    %r9,%r10
  jmp    L43
L17:
  cmp    %r10,%rdi
  jae    L21
  mov    %rdi,%r11
  jmp    L43
L21:
  movsd  (%rbx,%rbp,8),%xmm0
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L3:
  movsd  0x8(%r13),%xmm1
  test   %rbp,%rbp
  je     L65
  add    $0x8,%rsp
  maxsd  %xmm1,%xmm0
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L65:
  minsd  %xmm0,%xmm1
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  movapd %xmm1,%xmm0
  ret
```

assistant: ```c
double ksmall_dbl(double *data, size_t n, size_t k, double *buf) {
  size_t a, b, l, r;
  double p, x;
  assert(data && buf && (n > 0) && (k < n));
  if (n <= 2) {
    if (n <= 1)
      return data[0];
    if (k > 0)
      return (data[0] > data[1]) ? data[0] : data[1];
    else
      return (data[0] > data[1]) ? data[1] : data[0];
  }
  if (buf != data)
    memcpy(buf, data, n * sizeof(double));
  a = 0;
  b = n - 1;
  while (a < b) {
    l = a;
    r = b;
    p = buf[(l + r) / 2];
    if (buf[l] > buf[r]) {
      x = buf[l];
      buf[l] = buf[r];
      buf[r] = x;
    }
    if (p < buf[l])
      p = buf[l];
    else if (p > buf[r])
      p = buf[r];
    while (1) {
      while (buf[++l] < p)
        ;
      while (buf[--r] > p)
        ;
      if (l >= r)
        break;
      x = buf[l];
      buf[l] = buf[r];
      buf[r] = x;
    }
    if (l > k)
      b = l - 1;
    else
      a = r + 1;
  }
  return buf[k];
}
```