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

```asm
<BinSearchInsert>:
  endbr64
  movzbl %sil,%eax
  cmpw   $0x0,-0x2(%rdi,%rax,2)
  jne    L230
  push   %r12
  push   %rbp
  mov    %edx,%ebp
  mov    %esi,%edx
  push   %rbx
  mov    %ebp,%r10d
  mov    %rdi,%rbx
  lea    -0x1(%rsi),%edi
  cmp    $0x1,%sil
  jbe    L33
  movzbl %dil,%edi
  lea    -0x2(%rbx,%rdi,2),%rax
  nopl   0x0(%rax,%rax,1)
L164:
  mov    %edx,%edi
  sub    $0x1,%edx
  cmp    $0x1,%dl
  je     L187
  sub    $0x2,%rax
  cmpw   $0x0,0x2(%rax)
  je     L164
  sub    $0x2,%edi
  cmp    %bp,(%rbx)
  jbe    L150
L55:
  sub    $0x2,%edx
  movzbl %dil,%edi
  movzbl %dl,%edx
  mov    %rdx,%rax
  lea    0x2(%rdx,%rdx,1),%rdx
  neg    %rax
  add    %rax,%rax
  lea    (%rax,%rdi,2),%rsi
  lea    0x2(%rax,%rdi,2),%rdi
  add    %rbx,%rsi
  add    %rbx,%rdi
  call   <memmove@plt>
  movzwl (%rbx),%r9d
L83:
  mov    %r9w,0x2(%rbx)
  xor    %eax,%eax
  mov    %bp,(%rbx)
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  nopl   0x0(%rax)
L187:
  movzwl (%rbx),%r9d
  cmp    %bp,%r9w
  ja     L83
  mov    %rbx,%rax
  xor    %edi,%edi
  cmp    %r9w,%bp
  jbe    L174
L161:
  test   %r9w,%r9w
  je     L172
  movzbl %dl,%eax
  mov    %edx,%edi
  lea    (%rbx,%rax,2),%rax
L172:
  mov    %bp,(%rax)
  mov    %edi,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  nopw   0x0(%rax,%rax,1)
L150:
  movzbl %dil,%r12d
  lea    (%rbx,%r12,2),%r11
  movzwl (%r11),%r9d
  mov    %r11,%rax
  cmp    %r9w,%bp
  ja     L161
L204:
  mov    %edi,%eax
  xor    %r8d,%r8d
  jmp    L114
  nopl   0x0(%rax)
L213:
  lea    -0x1(%rcx),%eax
  xor    %ecx,%ecx
  cmp    %al,%r8b
  jae    L178
L114:
  movzbl %r8b,%ecx
  movzbl %al,%esi
  sub    %ecx,%esi
  mov    %esi,%ecx
  shr    $0x1f,%ecx
  add    %esi,%ecx
  sar    %ecx
  add    %r8d,%ecx
  movzbl %cl,%esi
  cmp    %r10w,(%rbx,%rsi,2)
  je     L26
  ja     L213
  lea    0x1(%rcx),%r8d
  mov    $0x1,%ecx
  cmp    %al,%r8b
  jb     L114
L178:
  cmp    %dil,%al
  jae    L145
  sub    $0x2,%edx
  lea    0x2(%rbx,%r12,2),%rsi
  mov    %edx,%r8d
  movzbl %dl,%edx
  sub    %eax,%r8d
  movzbl %r8b,%r8d
  lea    (%r8,%r8,1),%rdi
  sub    %rdi,%r11
  mov    %rdx,%rdi
  sub    %r12,%rdi
  jmp    L37
  nopw   0x0(%rax,%rax,1)
L41:
  movzwl (%rsi,%rdi,2),%r9d
L37:
  mov    %r9w,(%rsi)
  sub    $0x2,%rsi
  cmp    %rsi,%r11
  jne    L41
  sub    %r8,%rdx
  mov    %rdx,%r12
L145:
  test   %cl,%cl
  je     L119
  mov    %bp,(%rbx,%r12,2)
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  cs nopw 0x0(%rax,%rax,1)
L26:
  pop    %rbx
  mov    %ecx,%eax
  pop    %rbp
  pop    %r12
  ret
  nopw   0x0(%rax,%rax,1)
L119:
  mov    %bp,0x2(%rbx,%r12,2)
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L33:
  movzwl (%rbx),%r9d
  cmp    %bp,%r9w
  jbe    L123
  test   %dil,%dil
  je     L83
  xor    %edx,%edx
  mov    $0xffffffff,%edi
  jmp    L55
L123:
  movzbl %dil,%r12d
  lea    (%rbx,%r12,2),%r11
  movzwl (%r11),%r9d
  mov    %r11,%rax
  cmp    %bp,%r9w
  jb     L161
  test   %dil,%dil
  jne    L204
  xor    %eax,%eax
  xor    %r12d,%r12d
  jmp    L145
  nopl   0x0(%rax,%rax,1)
L174:
  xor    %r12d,%r12d
  xor    %eax,%eax
  jmp    L145
L230:
  mov    $0xffffffff,%eax
  ret
```

assistant: ```c
char BinSearchInsert(unsigned short *src, unsigned char len, unsigned short key) {
  unsigned char i, low, high, mid, flag;
  if (src[len - 1] != 0)
    return -1;
  while ((len > 1) && (src[len - 1] == 0))
    len--;
  low = 0;
  high = len - 1;
  if (key < src[low]) {
    for (i = len - 1; i > low; i--) {
      src[i + 1] = src[i];
    }
    src[i + 1] = src[i];
    src[i] = key;
    return low;
  }
  if (key > src[high]) {
    if (src[high] != 0) {
      high++;
    }
    src[high] = key;
    return high;
  }
  while (low < high) {
    mid = low + ((high - low) / 2);
    if (key == src[mid])
      return mid;
    if (key < src[mid]) {
      high = mid - 1;
      flag = 0;
    } else {
      low = mid + 1;
      flag = 1;
    }
  }
  for (i = len - 1; i > high; i--) {
    src[i + 1] = src[i];
  }
  if (flag)
    src[i] = key;
  else
    src[i + 1] = key;
  return high;
}
```