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

```asm
<sqlite_encode_binary>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x410,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x408(%rsp)
  xor    %eax,%eax
  test   %esi,%esi
  jle    L109
  mov    %rsp,%r14
  mov    %rdi,%r13
  mov    %esi,%r12d
  mov    $0x400,%edx
  xor    %esi,%esi
  mov    %r14,%rdi
  call   <memset@plt>
  lea    -0x1(%r12),%r10d
  movslq %r12d,%rdx
  mov    %r13,%r9
  movslq %r10d,%rax
  lea    -0x2(%r13,%rdx,1),%rcx
  mov    %r10d,%r10d
  add    %r13,%rax
  sub    %r10,%rcx
  nopl   (%rax)
L50:
  movzbl (%rax),%edx
  sub    $0x1,%rax
  addl   $0x1,(%rsp,%rdx,4)
  cmp    %rax,%rcx
  jne    L50
  mov    %r12d,%r8d
  mov    $0x1,%edx
  mov    $0x1,%esi
  jmp    L91
  nopw   0x0(%rax,%rax,1)
L147:
  mov    %eax,%r8d
  mov    %esi,%ebp
L40:
  cmp    $0x100,%ecx
  je     L30
L103:
  add    $0x1,%rdx
  mov    %ecx,%esi
L91:
  lea    0x1(%rsi),%ecx
  cmp    $0x27,%rdx
  je     L103
  movzbl %cl,%edi
  mov    (%r14,%rdx,4),%eax
  add    (%rsp,%rdi,4),%eax
  lea    0x27(%rsi),%edi
  movzbl %dil,%edi
  add    (%rsp,%rdi,4),%eax
  cmp    %r8d,%eax
  jge    L40
  test   %eax,%eax
  jne    L147
  test   %rbx,%rbx
  je     L155
L146:
  mov    %sil,(%rbx)
  mov    %esi,%edi
  lea    0x1(%r13,%r10,1),%rsi
  mov    $0x1,%r13d
  jmp    L181
  nopl   0x0(%rax,%rax,1)
L97:
  mov    %r13d,%edx
  cmp    $0x27,%al
  je     L144
L105:
  movslq %edx,%rcx
  add    $0x1,%r9
  lea    0x1(%rdx),%r13d
  mov    %al,(%rbx,%rcx,1)
  cmp    %r9,%rsi
  je     L166
L181:
  movzbl (%r9),%eax
  sub    %edi,%eax
  cmp    $0x1,%al
  ja     L97
L144:
  lea    0x1(%r13),%edx
  movslq %r13d,%r13
  add    $0x1,%eax
  movb   $0x1,(%rbx,%r13,1)
  jmp    L105
  nopl   (%rax)
L166:
  movslq %r13d,%rax
  xor    %edi,%edi
  cmp    %r12d,%edx
  movb   $0x0,(%rbx,%rax,1)
  sete   %dil
  call   <assert@plt>
L71:
  mov    0x408(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L22
  add    $0x410,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  nopl   0x0(%rax,%rax,1)
L109:
  mov    $0x1,%r13d
  test   %rdx,%rdx
  je     L71
  mov    $0x78,%eax
  mov    %ax,(%rdx)
  jmp    L71
L155:
  lea    0x1(%r12),%r13d
  jmp    L71
L30:
  add    %r8d,%r12d
  mov    %ebp,%esi
  test   %rbx,%rbx
  jne    L146
  jmp    L155
L22:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int sqlite_encode_binary(const unsigned char *in, int n, unsigned char *out) {
  int i, j, e, m;
  unsigned char x;
  int cnt[256];
  if (n <= 0) {
    if (out) {
      out[0] = 'x';
      out[1] = 0;
    }
    return 1;
  }
  memset(cnt, 0, sizeof(cnt));
  for (i = n - 1; i >= 0; i--) {
    cnt[in[i]]++;
  }
  m = n;
  for (i = 1; i < 256; i++) {
    int sum;
    if (i == '\'')
      continue;
    sum = cnt[i] + cnt[(i + 1) & 0xff] + cnt[(i + '\'') & 0xff];
    if (sum < m) {
      m = sum;
      e = i;
      if (m == 0)
        break;
    }
  }
  if (out == 0) {
    return n + m + 1;
  }
  out[0] = e;
  j = 1;
  for (i = 0; i < n; i++) {
    x = in[i] - e;
    if (x == 0 || x == 1 || x == '\'') {
      out[j++] = 1;
      x++;
    }
    out[j++] = x;
  }
  out[j] = 0;
  assert(j == n + m + 1);
  return j;
}
```