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

```asm
<append>:
  endbr64
  push   %r15
  lea    D9(%rip),%rdi
  push   %r14
  lea    D17(%rip),%r14
  push   %r13
  lea    D27(%rip),%r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x148,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x138(%rsp)
  xor    %eax,%eax
  lea    0x30(%rsp),%rbp
  lea    0x10(%rsp),%r12
  call   <puts0@plt>
  pxor   %xmm0,%xmm0
  mov    $0x100,%esi
  xor    %eax,%eax
  mov    %rbp,%rdi
  movaps %xmm0,0x30(%rsp)
  call   <getsn@plt>
  movdqa 0x30(%rsp),%xmm1
  mov    %r13,%rdi
  xor    %eax,%eax
  movb   $0x0,0x20(%rsp)
  movaps %xmm1,0x10(%rsp)
  call   <puts0@plt>
  mov    %r12,%rdi
  xor    %eax,%eax
  call   <puts0@plt>
  mov    %r14,%rdi
  xor    %eax,%eax
  call   <puts0@plt>
  xor    %eax,%eax
  mov    $0x3,%esi
  mov    %r12,%rdi
  call   <open_@plt>
  cmp    $0x1,%ax
  jne    L77
  lea    D57(%rip),%rdi
  xor    %eax,%eax
  lea    D47(%rip),%r15
  call   <puts0@plt>
  movl   $0x1,0xc(%rsp)
L56:
  mov    %r15,%rdi
  xor    %eax,%eax
  call   <puts0@plt>
  xor    %eax,%eax
  mov    $0x20,%ecx
  mov    %rbp,%rdi
  rep stos %rax,%es:(%rdi)
  mov    $0x100,%esi
  mov    %rbp,%rdi
  call   <getsn@plt>
  mov    %r13,%rdi
  xor    %eax,%eax
  call   <puts0@plt>
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <puts0@plt>
  mov    %r14,%rdi
  xor    %eax,%eax
  call   <puts0@plt>
  movzbl 0x30(%rsp),%esi
  cmp    $0x5d,%sil
  je     L16
  mov    0xc(%rsp),%eax
  test   %eax,%eax
  je     L42
L78:
  movl   $0x0,0xc(%rsp)
  mov    %rbp,%r12
  lea    0x130(%rsp),%rbx
L23:
  test   %sil,%sil
  je     L56
  xor    %edi,%edi
  xor    %eax,%eax
  add    $0x1,%r12
  call   <writec@plt>
  movzbl -0x1(%r12),%edi
  xor    %eax,%eax
  call   <putch@plt>
  cmp    %r12,%rbx
  je     L56
  movzbl (%r12),%esi
  jmp    L23
L42:
  mov    $0xa,%esi
  xor    %edi,%edi
  xor    %eax,%eax
  call   <writec@plt>
  movzbl 0x30(%rsp),%esi
  jmp    L78
L16:
  xor    %edi,%edi
  xor    %eax,%eax
  call   <close_@plt>
L21:
  mov    0x138(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L37
  add    $0x148,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L77:
  lea    D15(%rip),%rdi
  xor    %eax,%eax
  call   <puts0@plt>
  jmp    L21
L37:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: label: D9
data_type: string
name: disassemble_data
arguments: label: D17
data_type: string
name: disassemble_data
arguments: label: D27
data_type: string
name: disassemble_data
arguments: label: D57
data_type: string
name: disassemble_data
arguments: label: D47
data_type: string
name: disassemble_data
arguments: label: D15
data_type: string

tool: D9: file ? 

tool: D17: '


tool: D27: 
'

tool: D57: open OK


tool: D47: data to file (] - end of text) ? 

tool: D15: open not ok


assistant: ```c
void append(void) {
  unsigned short int i;
  unsigned short int j;
  unsigned short int equal;
  unsigned char device;
  unsigned char filename[16 + 2];
  unsigned char str[256];
  int first_line;
  puts0("file ? ");
  for (i = 0; i < 16; i++)
    str[i] = 0;
  getsn(str, 256);
  for (i = 0; i < 16; i++)
    filename[i] = str[i];
  filename[16] = 0;
  puts0("\r\n'");
  puts0(filename);
  puts0("'\r\n");
  i = open_(filename, 3);
  if (i == 1) {
    puts0("open OK\r\n");
  } else {
    puts0("open not ok\r\n");
    return;
  }
  first_line = 1;
  while (1) {
    puts0("data to file (] - end of text) ? ");
    for (i = 0; i < 256; i++)
      str[i] = 0;
    getsn(str, 256);
    puts0("\r\n'");
    puts0(str);
    puts0("'\r\n");
    if (str[0] == ']')
      break;
    if (first_line == 0)
      writec(0, '\n');
    else
      first_line = 0;
    for (i = 0; i < 256; i++)
      if (str[i]) {
        writec(0, str[i]);
        putch(str[i]);
      } else
        break;
  }
  close_(0);
}
```