user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<BinSearchInsert>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x18(%rbp)
  mov    %esi,%ecx
  mov    %edx,%eax
  mov    %ecx,%edx
  mov    %dl,-0x1c(%rbp)
  mov    %ax,-0x20(%rbp)
  movzbl -0x1c(%rbp),%eax
  add    %rax,%rax
  lea    -0x2(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  test   %ax,%ax
  je     L103
  mov    $0xffffffff,%eax
  jmp    L37
L52:
  movzbl -0x1c(%rbp),%eax
  sub    $0x1,%eax
  mov    %al,-0x1c(%rbp)
L103:
  cmpb   $0x1,-0x1c(%rbp)
  jbe    L75
  movzbl -0x1c(%rbp),%eax
  add    %rax,%rax
  lea    -0x2(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  test   %ax,%ax
  je     L52
L75:
  movb   $0x0,-0x4(%rbp)
  movzbl -0x1c(%rbp),%eax
  sub    $0x1,%eax
  mov    %al,-0x3(%rbp)
  movzbl -0x4(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  cmp    %ax,-0x20(%rbp)
  jae    L187
  movzbl -0x1c(%rbp),%eax
  sub    $0x1,%eax
  mov    %al,-0x5(%rbp)
  jmp    L182
L128:
  movzbl -0x5(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl -0x5(%rbp),%edx
  add    $0x1,%rdx
  lea    (%rdx,%rdx,1),%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  movzwl (%rax),%eax
  mov    %ax,(%rdx)
  movzbl -0x5(%rbp),%eax
  sub    $0x1,%eax
  mov    %al,-0x5(%rbp)
L182:
  movzbl -0x5(%rbp),%eax
  cmp    -0x4(%rbp),%al
  ja     L128
  movzbl -0x5(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl -0x5(%rbp),%edx
  add    $0x1,%rdx
  lea    (%rdx,%rdx,1),%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  movzwl (%rax),%eax
  mov    %ax,(%rdx)
  movzbl -0x5(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rax,%rdx
  movzwl -0x20(%rbp),%eax
  mov    %ax,(%rdx)
  movzbl -0x4(%rbp),%eax
  jmp    L37
L187:
  movzbl -0x3(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  cmp    %ax,-0x20(%rbp)
  jbe    L11
  movzbl -0x3(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  test   %ax,%ax
  je     L119
  movzbl -0x3(%rbp),%eax
  add    $0x1,%eax
  mov    %al,-0x3(%rbp)
L119:
  movzbl -0x3(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rax,%rdx
  movzwl -0x20(%rbp),%eax
  mov    %ax,(%rdx)
  movzbl -0x3(%rbp),%eax
  jmp    L37
L49:
  movzbl -0x3(%rbp),%eax
  movzbl -0x4(%rbp),%edx
  sub    %edx,%eax
  mov    %eax,%edx
  shr    $0x1f,%edx
  add    %edx,%eax
  sar    %eax
  mov    %eax,%edx
  movzbl -0x4(%rbp),%eax
  add    %edx,%eax
  mov    %al,-0x1(%rbp)
  movzbl -0x1(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  cmp    %ax,-0x20(%rbp)
  jne    L50
  movzbl -0x1(%rbp),%eax
  jmp    L37
L50:
  movzbl -0x1(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzwl (%rax),%eax
  cmp    %ax,-0x20(%rbp)
  jae    L167
  movzbl -0x1(%rbp),%eax
  sub    $0x1,%eax
  mov    %al,-0x3(%rbp)
  movb   $0x0,-0x2(%rbp)
  jmp    L11
L167:
  movzbl -0x1(%rbp),%eax
  add    $0x1,%eax
  mov    %al,-0x4(%rbp)
  movb   $0x1,-0x2(%rbp)
L11:
  movzbl -0x4(%rbp),%eax
  cmp    -0x3(%rbp),%al
  jb     L49
  movzbl -0x1c(%rbp),%eax
  sub    $0x1,%eax
  mov    %al,-0x5(%rbp)
  jmp    L136
L46:
  movzbl -0x5(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl -0x5(%rbp),%edx
  add    $0x1,%rdx
  lea    (%rdx,%rdx,1),%rcx
  mov    -0x18(%rbp),%rdx
  add    %rcx,%rdx
  movzwl (%rax),%eax
  mov    %ax,(%rdx)
  movzbl -0x5(%rbp),%eax
  sub    $0x1,%eax
  mov    %al,-0x5(%rbp)
L136:
  movzbl -0x5(%rbp),%eax
  cmp    -0x3(%rbp),%al
  ja     L46
  cmpb   $0x0,-0x2(%rbp)
  je     L183
  movzbl -0x5(%rbp),%eax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rax,%rdx
  movzwl -0x20(%rbp),%eax
  mov    %ax,(%rdx)
  jmp    L122
L183:
  movzbl -0x5(%rbp),%eax
  add    $0x1,%rax
  lea    (%rax,%rax,1),%rdx
  mov    -0x18(%rbp),%rax
  add    %rax,%rdx
  movzwl -0x20(%rbp),%eax
  mov    %ax,(%rdx)
L122:
  movzbl -0x3(%rbp),%eax
L37:
  pop    %rbp
  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;
}
```