user: Translate the below assembly code into C programming language:

```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    L23
  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)
L165:
  movzbl (%rax),%edx
  sub    $0x1,%rax
  addl   $0x1,(%rsp,%rdx,4)
  cmp    %rax,%rcx
  jne    L165
  mov    %r12d,%r8d
  mov    $0x1,%edx
  mov    $0x1,%esi
  jmp    L54
  nopw   0x0(%rax,%rax,1)
L2:
  mov    %eax,%r8d
  mov    %esi,%ebp
L127:
  cmp    $0x100,%ecx
  je     L51
L70:
  add    $0x1,%rdx
  mov    %ecx,%esi
L54:
  lea    0x1(%rsi),%ecx
  cmp    $0x27,%rdx
  je     L70
  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    L127
  test   %eax,%eax
  jne    L2
  test   %rbx,%rbx
  je     L83
L1:
  mov    %sil,(%rbx)
  mov    %esi,%edi
  lea    0x1(%r13,%r10,1),%rcx
  mov    $0x1,%edx
  jmp    L91
  nopw   0x0(%rax,%rax,1)
L159:
  cmp    $0x27,%al
  je     L103
  movslq %edx,%rsi
  add    $0x1,%r9
  lea    0x1(%rdx),%r13d
  mov    %al,(%rbx,%rsi,1)
  cmp    %r9,%rcx
  je     L143
L100:
  mov    %r13d,%edx
L91:
  movzbl (%r9),%eax
  sub    %edi,%eax
  cmp    $0x1,%al
  ja     L159
L103:
  lea    0x1(%rdx),%esi
  movslq %edx,%r8
  lea    0x2(%rdx),%r13d
  add    $0x1,%eax
  movslq %esi,%rdx
  add    $0x1,%r9
  movb   $0x1,(%rbx,%r8,1)
  mov    %al,(%rbx,%rdx,1)
  cmp    %rcx,%r9
  jne    L100
  mov    %esi,%edx
L143:
  movslq %r13d,%rax
  xor    %edi,%edi
  cmp    %r12d,%edx
  movb   $0x0,(%rbx,%rax,1)
  sete   %dil
  call   <assert@plt>
L22:
  mov    0x408(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L77
  add    $0x410,%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
  nopw   0x0(%rax,%rax,1)
L23:
  mov    $0x1,%r13d
  test   %rdx,%rdx
  je     L22
  mov    $0x78,%eax
  mov    %ax,(%rdx)
  jmp    L22
L83:
  lea    0x1(%r12),%r13d
  jmp    L22
L51:
  add    %r8d,%r12d
  mov    %ebp,%esi
  test   %rbx,%rbx
  jne    L1
  jmp    L83
L77:
  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;
}
```