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

```asm
<encode_file>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x10000(%rsp),%r11
L30:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L30
  sub    $0x48,%rsp
  mov    %rdx,0x18(%rsp)
  mov    %esi,%ebp
  mov    %rdi,%rbx
  mov    %esi,%r14d
  mov    %r8w,0x16(%rsp)
  mov    %rcx,%r12
  mov    %r9,%r15
  sar    $0x8,%ebp
  mov    %fs:0x28,%rax
  mov    %rax,0x10038(%rsp)
  xor    %eax,%eax
  movl   $0x0,0x2c(%rsp)
  test   %r9,%r9
  je     L288
  mov    $0x3,%edx
  lea    D17(%rip),%rdi
  mov    $0x1,%esi
  call   <fwrite@plt>
  movzbl (%r15),%eax
  mov    %r15,%rdx
  xor    %ecx,%ecx
  xor    %edi,%edi
  test   %al,%al
  je     L183
L233:
  add    $0x1,%rdx
  xor    %eax,%ecx
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L233
  movzbl %cl,%edi
L183:
  mov    %r12,%rsi
  mov    %r15,%r13
  call   <fputc@plt>
  movzbl (%r15),%eax
  movzbl 0x1(%r15),%edx
  xor    %eax,%ebp
  test   %dl,%dl
  jne    L163
L50:
  xor    %r14d,%eax
L11:
  movzbl %al,%ecx
  movzbl %bpl,%edx
  lea    D30(%rip),%rsi
  xor    %eax,%eax
  mov    %r12,%rdi
  lea    0x30(%rsp),%rbp
  xor    %r14d,%r14d
  call   <fprintf@plt>
  mov    $0x10000,%edx
  xor    %esi,%esi
  mov    %rbp,%rdi
  call   <memset@plt>
  lea    0x2c(%rsp),%rax
  mov    %rax,0x8(%rsp)
  nopw   0x0(%rax,%rax,1)
L77:
  cmpq   $0x0,(%rbx,%r14,8)
  je     L112
  movzwl 0x16(%rsp),%eax
  cmp    $0x10000,%r14
  cmovne %r14d,%eax
  test   %r15,%r15
  je     L5
  movzbl 0x1(%r13),%edx
  lea    0x1(%r13),%r10
  test   %dl,%dl
  jne    L54
  movzbl (%r15),%edx
  mov    %r15,%r10
L54:
  movzbl 0x1(%r10),%esi
  xor    %eax,%edx
  lea    0x1(%r10),%r13
  test   %sil,%sil
  jne    L264
  movzbl (%r15),%esi
  mov    %r15,%r13
L264:
  movsbl %ah,%ecx
  movsbl %dl,%edx
  mov    %r12,%rdi
  mov    %ecx,%eax
  xor    %esi,%eax
  lea    D30(%rip),%rsi
  movsbl %al,%ecx
  xor    %eax,%eax
  call   <fprintf@plt>
  mov    (%rbx,%r14,8),%rcx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  mov    0x8(%rsp),%rdx
  movl   $0x0,0x2c(%rsp)
  call   <write_bits@plt>
  test   %rax,%rax
  jne    L40
  movsbl 0x1(%r13),%eax
  add    $0x1,%r13
  test   %al,%al
  jne    L43
  movsbl (%r15),%eax
  mov    %r15,%r13
L43:
  movzbl 0x2c(%rsp),%edi
  mov    %r12,%rsi
  xor    %eax,%edi
  call   <fputc@plt>
  mov    0x2c(%rsp),%eax
  test   %eax,%eax
  lea    0x7(%rax),%ecx
  cmovns %eax,%ecx
  sar    $0x3,%ecx
  mov    %ecx,%esi
  cmp    $0xfffffff9,%eax
  jl     L128
  xor    %edx,%edx
  xor    %eax,%eax
  nop
L18:
  movzbl 0x1(%r13),%edi
  test   %dil,%dil
  je     L247
  add    $0x1,%edx
  xor    %dil,0x30(%rsp,%rax,1)
  add    $0x1,%r13
  movzbl %dl,%eax
  cmp    %ecx,%eax
  jle    L18
L128:
  lea    0x1(%rsi),%edx
  mov    %r12,%rcx
  mov    $0x1,%esi
  mov    %rbp,%rdi
  mov    %edx,0x10(%rsp)
  call   <fwrite@plt>
  mov    0x10(%rsp),%edx
  cmp    %edx,%eax
  jne    L40
L112:
  add    $0x1,%r14
  cmp    $0x10001,%r14
  jne    L77
  movl   $0x0,0x2c(%rsp)
  jmp    L298
  nop
L250:
  mov    0x18(%rsp),%rdi
  call   <getc@plt>
  cmp    $0xffffffff,%eax
  je     L148
  xor    %edx,%edx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  mov    %r13b,%dl
  mov    %al,%dh
  movzwl %dx,%edx
  mov    (%rbx,%rdx,8),%rcx
  mov    0x8(%rsp),%rdx
  call   <write_bits@plt>
  test   %rax,%rax
  jne    L40
L298:
  mov    0x18(%rsp),%rdi
  call   <getc@plt>
  mov    %eax,%r13d
  cmp    $0xffffffff,%eax
  jne    L250
L148:
  mov    0x80000(%rbx),%rcx
  mov    0x8(%rsp),%rdx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  call   <write_bits@plt>
  test   %rax,%rax
  jne    L40
  mov    0x2c(%rsp),%edx
  xor    %eax,%eax
  test   %edx,%edx
  jle    L285
  sar    $0x3,%edx
  mov    %r12,%rcx
  mov    $0x1,%esi
  mov    %rbp,%rdi
  lea    0x1(%rdx),%ebx
  mov    %ebx,%edx
  call   <fwrite@plt>
  cmp    %ebx,%eax
  setne  %al
  movzbl %al,%eax
  jmp    L285
  nopl   0x0(%rax,%rax,1)
L247:
  movzbl 0x30(%rsp,%rax,1),%edi
  add    $0x1,%edx
  xor    (%r15),%dil
  mov    %r15,%r13
  mov    %dil,0x30(%rsp,%rax,1)
  movzbl %dl,%eax
  cmp    %ecx,%eax
  jle    L18
  jmp    L128
  nopl   0x0(%rax,%rax,1)
L5:
  movsbl %ah,%ecx
  movsbl %al,%edx
  lea    D30(%rip),%rsi
  mov    %r12,%rdi
  movsbl %cl,%ecx
  xor    %eax,%eax
  call   <fprintf@plt>
  mov    (%rbx,%r14,8),%rcx
  mov    %rbp,%rsi
  mov    %r12,%rdi
  mov    0x8(%rsp),%rdx
  movl   $0x0,0x2c(%rsp)
  call   <write_bits@plt>
  test   %rax,%rax
  jne    L40
  movzbl 0x2c(%rsp),%edi
  mov    %r12,%rsi
  call   <fputc@plt>
  mov    0x2c(%rsp),%eax
  test   %eax,%eax
  lea    0x7(%rax),%esi
  cmovns %eax,%esi
  sar    $0x3,%esi
  jmp    L128
  nopl   0x0(%rax)
L40:
  mov    $0x1,%eax
L285:
  mov    0x10038(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L100
  add    $0x10048,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L163:
  lea    0x1(%r15),%r13
  mov    %edx,%eax
  jmp    L50
L288:
  mov    $0x3,%edx
  mov    $0x1,%esi
  lea    D29(%rip),%rdi
  xor    %r13d,%r13d
  call   <fwrite@plt>
  mov    %r14d,%eax
  jmp    L11
L100:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D17
type_guessed: string
name: unpack_data
arguments: tag: D30
type_guessed: string
name: unpack_data
arguments: tag: D29
type_guessed: string

tool: D17: hz1

tool: D30: %c%c

tool: D29: hz0

assistant: ```c
int encode_file(char **table, int n, FILE *f, FILE *f2, unsigned short tw, char *key) {
  char bitbuf[65536];
  int i, bits = 0;
  unsigned char cl, ch;
  int cx[2];
  union {
    char c[2];
    unsigned short word;
  } u;
  char *enc = key;
  fprintf(f2, "%s", (key ? "hz1" : "hz0"));
  cl = (unsigned char)(n & 0x00ff);
  ch = (unsigned char)(n >> 8);
  if (key) {
    unsigned char cs;
    for (cs = 0; *enc; enc++)
      cs ^= *enc;
    fprintf(f2, "%c", cs);
    enc = key;
    ch ^= *enc;
    if ((*(++enc)) == '\0')
      enc = key;
    cl ^= *enc;
  }
  fprintf(f2, "%c%c", ch, cl);
  for (i = 0; i < 65536; i++)
    bitbuf[i] = '\0';
  for (i = 0; i < 65536 + 1; i++)
    if (table[i]) {
      int nmemb;
      u.word = (unsigned short)i;
      if (i == 65536)
        u.word = tw;
      if (key) {
        if (*(++enc) == '\0')
          enc = key;
        u.c[0] ^= *enc;
        if (*(++enc) == '\0')
          enc = key;
        u.c[1] ^= *enc;
      }
      fprintf(f2, "%c%c", u.c[0], u.c[1]);
      bits = 0;
      if (write_bits(f2, bitbuf, &bits, table[i]) != 0)
        return 1;
      if (key) {
        if (*(++enc) == '\0')
          enc = key;
        fprintf(f2, "%c", ((unsigned char)bits) ^ *enc);
        for (cl = 0; cl <= bits / 8; cl++) {
          if (*(++enc) == '\0')
            enc = key;
          bitbuf[cl] ^= *enc;
        }
      } else
        fprintf(f2, "%c", (unsigned char)bits);
      nmemb = bits / 8 + 1;
      if (fwrite(bitbuf, sizeof(char), bits / 8 + 1, f2) != nmemb)
        return 1;
    }
  bits = 0;
  while ((cx[0] = getc(f)) != -1 && (cx[1] = getc(f)) != -1) {
    u.c[0] = cx[0];
    u.c[1] = cx[1];
    if (write_bits(f2, bitbuf, &bits, table[u.word]) != 0)
      return 1;
  }
  if (write_bits(f2, bitbuf, &bits, table[65536]) != 0)
    return 1;
  if (bits > 0) {
    int nmemb = bits / 8 + 1;
    if (fwrite(bitbuf, sizeof(char), nmemb, f2) != nmemb)
      return 1;
  }
  return 0;
}
```