user: 请显示与下面列出的汇编代码相匹配的C语言实现:

```asm
<MedSelect>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %edi,%ebp
  mov    %esi,%r12d
  mov    %rdx,%r11
  cmp    $0x2,%esi
  jle    L127
  mov    $0x1,%r13d
  mov    $0x2,%eax
  jmp    L29
L43:
  mov    %r14d,%r13d
L30:
  lea    0x1(%r13),%eax
  cmp    %r12d,%eax
  jge    L58
L29:
  lea    (%r12,%r13,1),%edx
  sar    %edx
  movslq %edx,%rdx
  lea    (%r11,%rdx,4),%rcx
  mov    (%rcx),%esi
  movslq %r13d,%rdx
  lea    0x4(,%rdx,4),%rdx
  lea    (%r11,%rdx,1),%rbx
  mov    (%rbx),%edi
  mov    %edi,(%rcx)
  mov    %esi,(%rbx)
  lea    -0x4(%r11,%rdx,1),%rdx
  mov    (%rdx),%esi
  movslq %r12d,%rcx
  lea    (%r11,%rcx,4),%rcx
  mov    (%rcx),%edi
  cmp    %edi,%esi
  jle    L56
  mov    %edi,(%rdx)
  mov    %esi,(%rcx)
L56:
  mov    (%rbx),%esi
  mov    (%rcx),%edi
  cmp    %edi,%esi
  jle    L7
  mov    %edi,(%rbx)
  mov    %esi,(%rcx)
L7:
  mov    (%rdx),%ecx
  mov    (%rbx),%esi
  cmp    %esi,%ecx
  jle    L54
  mov    %esi,(%rdx)
  mov    %ecx,(%rbx)
L54:
  mov    (%rbx),%esi
  add    $0x1,%eax
  movslq %eax,%r8
  mov    %r12d,%edx
  jmp    L14
L127:
  mov    $0x1,%r13d
  mov    $0x2,%eax
L58:
  cmp    %r12d,%eax
  je     L31
L147:
  movslq %ebp,%rbp
  mov    (%r11,%rbp,4),%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
L31:
  movslq %r12d,%r12
  lea    (%r11,%r12,4),%rax
  mov    (%rax),%esi
  movslq %r13d,%r13
  lea    (%r11,%r13,4),%rcx
  mov    (%rcx),%edx
  cmp    %edx,%esi
  jge    L147
  mov    %esi,(%rcx)
  mov    %edx,(%rax)
  jmp    L147
L85:
  add    $0x1,%r8
L14:
  mov    %r8d,%r14d
  mov    (%r11,%r8,4),%r10d
  cmp    %esi,%r10d
  jl     L85
  movslq %edx,%rax
  lea    -0x4(%r11,%rax,4),%rax
L38:
  mov    %edx,%r9d
  sub    $0x1,%edx
  mov    %rax,%rdi
  sub    $0x4,%rax
  mov    0x4(%rax),%ecx
  cmp    %esi,%ecx
  jg     L38
  cmp    %r8d,%edx
  jl     L20
  mov    %ecx,(%r11,%r8,4)
  mov    %r10d,(%rdi)
  jmp    L85
L20:
  mov    %ecx,(%rbx)
  mov    %esi,(%rdi)
  cmp    %ebp,%edx
  jl     L43
  lea    -0x2(%r9),%r12d
  cmove  %r14d,%r13d
  jmp    L30
```

assistant: ```c
int MedSelect(int k, int n, int arr[]) {
  int 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;
    }
  }
}
```